feat: Refactor QR code generation and add error handling
This commit is contained in:
parent
44fd0d6ed7
commit
ae33972b26
|
@ -579,31 +579,23 @@ Future<String> byteToString(Uint8List bytes) async {
|
||||||
|
|
||||||
Widget buildQrCode(
|
Widget buildQrCode(
|
||||||
{
|
{
|
||||||
required String data,
|
// required String data,
|
||||||
required String type,
|
// required String type,
|
||||||
required double dimension,
|
// required int version,
|
||||||
|
// required int maskPattern,
|
||||||
required int errorCorrectLevel,
|
required int errorCorrectLevel,
|
||||||
required int version,
|
required double dimension,
|
||||||
required int maskPattern,
|
|
||||||
required String identifier,
|
required String identifier,
|
||||||
required String pass,
|
required String pass,
|
||||||
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
|
log("pass: $pass");
|
||||||
if (data.isEmpty) {
|
|
||||||
throw Exception("Dados do QR Code estão vazios.");
|
|
||||||
}
|
|
||||||
// Aqui você pode adicionar mais lógica de validação conforme necessário
|
|
||||||
|
|
||||||
// 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.withQr(qr: QrCode.fromUint8List(data: assembleQRPacket(direction, identifier, pass), errorCorrectLevel: errorCorrectLevel), size: dimension, padding: const EdgeInsets.all(10), backgroundColor: backgroundColor, foregroundColor: foregroundColor);
|
return QrImageView.withQr(qr: QrCode.fromUint8List(data: assembleQRPacket(direction, identifier, pass), errorCorrectLevel: errorCorrectLevel), size: dimension, padding: const EdgeInsets.all(10), backgroundColor: backgroundColor, foregroundColor: foregroundColor);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Tratamento de erros
|
|
||||||
return Text("Erro ao gerar QR Code: ${e.toString()}");
|
return Text("Erro ao gerar QR Code: ${e.toString()}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,6 +163,7 @@ class _QrCodePassKeyTemplateComponentWidgetState
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
controller: _model.keyTextFieldTextController,
|
controller: _model.keyTextFieldTextController,
|
||||||
|
|
||||||
focusNode: _model.keyTextFieldFocusNode,
|
focusNode: _model.keyTextFieldFocusNode,
|
||||||
onChanged: (_) => EasyDebounce.debounce(
|
onChanged: (_) => EasyDebounce.debounce(
|
||||||
'_model.keyTextFieldTextController',
|
'_model.keyTextFieldTextController',
|
||||||
|
@ -264,7 +265,7 @@ class _QrCodePassKeyTemplateComponentWidgetState
|
||||||
required isFocused,
|
required isFocused,
|
||||||
maxLength}) =>
|
maxLength}) =>
|
||||||
null,
|
null,
|
||||||
keyboardType: TextInputType.visiblePassword,
|
keyboardType: TextInputType.number,
|
||||||
cursorColor: FlutterFlowTheme.of(context).primary,
|
cursorColor: FlutterFlowTheme.of(context).primary,
|
||||||
validator: _model.keyTextFieldTextControllerValidator
|
validator: _model.keyTextFieldTextControllerValidator
|
||||||
.asValidator(context),
|
.asValidator(context),
|
||||||
|
|
|
@ -128,8 +128,8 @@ void dispose() {
|
||||||
if (_model.isAccess == true)
|
if (_model.isAccess == true)
|
||||||
Text(
|
Text(
|
||||||
FFLocalizations.of(context).getVariableText(
|
FFLocalizations.of(context).getVariableText(
|
||||||
ptText: 'QR Code de Acesso',
|
ptText: 'Use esse QR Code para acesso',
|
||||||
enText: 'Access QR Code',
|
enText: 'Use this QR Code for access',
|
||||||
),
|
),
|
||||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||||
fontFamily:
|
fontFamily:
|
||||||
|
@ -146,21 +146,21 @@ void dispose() {
|
||||||
if (_model.isAccess == true)
|
if (_model.isAccess == true)
|
||||||
Align(
|
Align(
|
||||||
alignment: const AlignmentDirectional(0.0, 0.0),
|
alignment: const AlignmentDirectional(0.0, 0.0),
|
||||||
// this.errorCorrectLevel = 3,
|
child: InkWell(
|
||||||
// this.version = 10,
|
onTap: () {
|
||||||
// this.maskPattern = -1,
|
safeSetState(() {
|
||||||
|
|
||||||
|
});
|
||||||
|
},
|
||||||
child: buildQrCode(
|
child: buildQrCode(
|
||||||
data: 'example.com',
|
|
||||||
type: 'URl',
|
|
||||||
dimension: dimension,
|
dimension: dimension,
|
||||||
errorCorrectLevel: QrErrorCorrectLevel.M,
|
errorCorrectLevel: QrErrorCorrectLevel.M,
|
||||||
maskPattern: -1,
|
|
||||||
version: QrVersions.auto,
|
|
||||||
identifier: FFAppState().userDevUUID,
|
identifier: FFAppState().userDevUUID,
|
||||||
pass: '1234',
|
pass: _model.key!,
|
||||||
direction: 5,
|
direction: 5,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
if(_model.isAccess == false)
|
if(_model.isAccess == false)
|
||||||
Align(
|
Align(
|
||||||
alignment: const AlignmentDirectional(0, 0),
|
alignment: const AlignmentDirectional(0, 0),
|
||||||
|
@ -206,8 +206,9 @@ void dispose() {
|
||||||
await _showQrCodeBottomSheet(context);
|
await _showQrCodeBottomSheet(context);
|
||||||
_toggleQrCodeAccess();
|
_toggleQrCodeAccess();
|
||||||
},
|
},
|
||||||
text: FFLocalizations.of(context).getText(
|
text: FFLocalizations.of(context).getVariableText(
|
||||||
'mxdrsbmy' /* Liberar QR Code */,
|
ptText: 'Gerar QR Code',
|
||||||
|
enText: 'Generate QR Code',
|
||||||
),
|
),
|
||||||
options: FFButtonOptions(
|
options: FFButtonOptions(
|
||||||
height: 40.0,
|
height: 40.0,
|
||||||
|
@ -247,7 +248,7 @@ void dispose() {
|
||||||
width: 300.0,
|
width: 300.0,
|
||||||
decoration: const BoxDecoration(),
|
decoration: const BoxDecoration(),
|
||||||
child: Visibility(
|
child: Visibility(
|
||||||
visible: _model.isAccess == false,
|
visible: _model.isAccess == true,
|
||||||
child: Text(
|
child: Text(
|
||||||
FFLocalizations.of(context).getVariableText(
|
FFLocalizations.of(context).getVariableText(
|
||||||
ptText: 'Certifique-se de que o QRCode está visivel para o leitor',
|
ptText: 'Certifique-se de que o QRCode está visivel para o leitor',
|
||||||
|
@ -283,8 +284,8 @@ void dispose() {
|
||||||
10.0, 0.0, 0.0, 0.0),
|
10.0, 0.0, 0.0, 0.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
FFLocalizations.of(context).getVariableText(
|
FFLocalizations.of(context).getVariableText(
|
||||||
enText: 'Changing QR code in',
|
ptText: 'Expirando QR code em',
|
||||||
ptText: 'Trocando QR code em',
|
enText: 'Expiring QR code in',
|
||||||
// 'wkjkxd2e' /* Trocando QR code em */,
|
// 'wkjkxd2e' /* Trocando QR code em */,
|
||||||
),
|
),
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
|
|
Loading…
Reference in New Issue