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(
|
||||
{
|
||||
required String data,
|
||||
required String type,
|
||||
required double dimension,
|
||||
// required String data,
|
||||
// required String type,
|
||||
// required int version,
|
||||
// required int maskPattern,
|
||||
required int errorCorrectLevel,
|
||||
required int version,
|
||||
required int maskPattern,
|
||||
required double dimension,
|
||||
required String identifier,
|
||||
required String pass,
|
||||
required int direction
|
||||
}
|
||||
) {
|
||||
log('QR Code Data: $data');
|
||||
try {
|
||||
// Verifica se os dados estão de acordo com as regras de negócio
|
||||
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
|
||||
log("pass: $pass");
|
||||
const Color backgroundColor = Colors.white;
|
||||
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);
|
||||
} catch (e) {
|
||||
// Tratamento de erros
|
||||
return Text("Erro ao gerar QR Code: ${e.toString()}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,6 +163,7 @@ class _QrCodePassKeyTemplateComponentWidgetState
|
|||
width: double.infinity,
|
||||
child: TextFormField(
|
||||
controller: _model.keyTextFieldTextController,
|
||||
|
||||
focusNode: _model.keyTextFieldFocusNode,
|
||||
onChanged: (_) => EasyDebounce.debounce(
|
||||
'_model.keyTextFieldTextController',
|
||||
|
@ -264,7 +265,7 @@ class _QrCodePassKeyTemplateComponentWidgetState
|
|||
required isFocused,
|
||||
maxLength}) =>
|
||||
null,
|
||||
keyboardType: TextInputType.visiblePassword,
|
||||
keyboardType: TextInputType.number,
|
||||
cursorColor: FlutterFlowTheme.of(context).primary,
|
||||
validator: _model.keyTextFieldTextControllerValidator
|
||||
.asValidator(context),
|
||||
|
|
|
@ -128,8 +128,8 @@ void dispose() {
|
|||
if (_model.isAccess == true)
|
||||
Text(
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
ptText: 'QR Code de Acesso',
|
||||
enText: 'Access QR Code',
|
||||
ptText: 'Use esse QR Code para acesso',
|
||||
enText: 'Use this QR Code for access',
|
||||
),
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily:
|
||||
|
@ -146,19 +146,19 @@ void dispose() {
|
|||
if (_model.isAccess == true)
|
||||
Align(
|
||||
alignment: const AlignmentDirectional(0.0, 0.0),
|
||||
// this.errorCorrectLevel = 3,
|
||||
// this.version = 10,
|
||||
// this.maskPattern = -1,
|
||||
child: buildQrCode(
|
||||
data: 'example.com',
|
||||
type: 'URl',
|
||||
dimension: dimension,
|
||||
errorCorrectLevel: QrErrorCorrectLevel.M,
|
||||
maskPattern: -1,
|
||||
version: QrVersions.auto,
|
||||
identifier: FFAppState().userDevUUID,
|
||||
pass: '1234',
|
||||
direction: 5,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
safeSetState(() {
|
||||
|
||||
});
|
||||
},
|
||||
child: buildQrCode(
|
||||
dimension: dimension,
|
||||
errorCorrectLevel: QrErrorCorrectLevel.M,
|
||||
identifier: FFAppState().userDevUUID,
|
||||
pass: _model.key!,
|
||||
direction: 5,
|
||||
),
|
||||
),
|
||||
),
|
||||
if(_model.isAccess == false)
|
||||
|
@ -206,8 +206,9 @@ void dispose() {
|
|||
await _showQrCodeBottomSheet(context);
|
||||
_toggleQrCodeAccess();
|
||||
},
|
||||
text: FFLocalizations.of(context).getText(
|
||||
'mxdrsbmy' /* Liberar QR Code */,
|
||||
text: FFLocalizations.of(context).getVariableText(
|
||||
ptText: 'Gerar QR Code',
|
||||
enText: 'Generate QR Code',
|
||||
),
|
||||
options: FFButtonOptions(
|
||||
height: 40.0,
|
||||
|
@ -247,7 +248,7 @@ void dispose() {
|
|||
width: 300.0,
|
||||
decoration: const BoxDecoration(),
|
||||
child: Visibility(
|
||||
visible: _model.isAccess == false,
|
||||
visible: _model.isAccess == true,
|
||||
child: Text(
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
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),
|
||||
child: Text(
|
||||
FFLocalizations.of(context).getVariableText(
|
||||
enText: 'Changing QR code in',
|
||||
ptText: 'Trocando QR code em',
|
||||
ptText: 'Expirando QR code em',
|
||||
enText: 'Expiring QR code in',
|
||||
// 'wkjkxd2e' /* Trocando QR code em */,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
|
|
Loading…
Reference in New Issue