Refactoring

This commit is contained in:
jantunesmesias 2024-07-15 16:48:44 -03:00
parent 99adb1d513
commit 918dcf08ac
1 changed files with 11 additions and 19 deletions

View File

@ -6,7 +6,7 @@ import 'package:f_r_e_hub/pages/home_page/home_page_widget.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:qr_flutter/qr_flutter.dart'; import 'package:qr_flutter/qr_flutter.dart';
import 'package:sqflite/utils/utils.dart'; import 'package:sqflite/utils/utils.dart';
import 'dart:developer' as developer; import 'dart:developer';
import '/actions/actions.dart' as action_blocks; import '/actions/actions.dart' as action_blocks;
import '/backend/api_requests/api_calls.dart'; import '/backend/api_requests/api_calls.dart';
@ -513,7 +513,7 @@ Uint8List assembleQRPacket(int direction, String identifier, String password) {
String paddedBadge = identifier.padLeft(30, '0'); String paddedBadge = identifier.padLeft(30, '0');
developer.log("Badge: $paddedBadge"); log("Badge: $paddedBadge");
for (var i = 0; i < paddedBadge.length; i += 2) { for (var i = 0; i < paddedBadge.length; i += 2) {
packet.add(int.parse(paddedBadge.substring(i, i + 2), radix: 16)); packet.add(int.parse(paddedBadge.substring(i, i + 2), radix: 16));
@ -554,8 +554,8 @@ Uint8List assembleQRPacket(int direction, String identifier, String password) {
var bytes = packet.map((byte) => byte.toRadixString(16).padLeft(2, '0')).join((' ')); var bytes = packet.map((byte) => byte.toRadixString(16).padLeft(2, '0')).join((' '));
developer.log("Pacote: $packet"); log("Pacote: $packet");
developer.log("Bytes: $bytes"); log("Bytes: $bytes");
return Uint8List.fromList(packet); return Uint8List.fromList(packet);
} }
@ -569,14 +569,15 @@ Uint8List hexStringToByteArray(String s) {
return data; return data;
} }
String byteToHexa(List<int> pDados) { String byteToHexa(Uint8List pDados) {
return pDados.map((byte) => byte.toRadixString(16).padLeft(2, '0').toUpperCase()).join(); return pDados.map((byte) => byte.toRadixString(16).padLeft(2, '0').toUpperCase()).join();
} }
String byteToString(Uint8List bytes) { Future<String> byteToString(Uint8List bytes) async {
return utf8.decode(bytes, allowMalformed: true); return String.fromCharCodes(bytes);
} }
Widget buildQrCode( Widget buildQrCode(
{ {
required String data, required String data,
@ -590,7 +591,7 @@ Widget buildQrCode(
required int direction required int direction
} }
) { ) {
log('QR Code Data: $data');
try { try {
// Verifica se os dados estão de acordo com as regras de negócio // Verifica se os dados estão de acordo com as regras de negócio
if (data.isEmpty) { if (data.isEmpty) {
@ -601,16 +602,7 @@ Widget buildQrCode(
// Geração do QR Code com a biblioteca qr_flutter // Geração do QR Code com a biblioteca qr_flutter
const Color backgroundColor = Colors.white; const Color backgroundColor = Colors.white;
const Color foregroundColor = Colors.black; const Color foregroundColor = Colors.black;
return QrImageView( return QrImageView.withQr(qr: QrCode.fromUint8List(data: assembleQRPacket(direction, identifier, pass), errorCorrectLevel: errorCorrectLevel), size: dimension, padding: const EdgeInsets.all(10), backgroundColor: backgroundColor, foregroundColor: foregroundColor);
data: byteToString(assembleQRPacket(direction, identifier, pass)),
version: version, //QrVersions.auto
size: dimension,
errorCorrectionLevel: errorCorrectLevel,
backgroundColor: backgroundColor,
foregroundColor: foregroundColor,
gapless: false, // Ajuste conforme necessário
// Adicione mais customizações aqui conforme os arquivos Java
);
} catch (e) { } catch (e) {
// Tratamento de erros // Tratamento de erros
return Text("Erro ao gerar QR Code: ${e.toString()}"); return Text("Erro ao gerar QR Code: ${e.toString()}");