import 'package:barcode_widget/barcode_widget.dart'; import 'package:f_r_e_hub/actions/actions.dart'; import 'package:f_r_e_hub/flutter_flow/custom_functions.dart'; import 'package:percent_indicator/circular_percent_indicator.dart'; import '/components/templates_components/qr_code_pass_key_template_component/qr_code_pass_key_template_component_widget.dart'; import '/flutter_flow/flutter_flow_animations.dart'; import '/flutter_flow/flutter_flow_icon_button.dart'; import '/flutter_flow/flutter_flow_theme.dart'; import '/flutter_flow/flutter_flow_util.dart'; import '/flutter_flow/flutter_flow_widgets.dart'; import 'dart:async'; import '/flutter_flow/custom_functions.dart' as functions; // import 'package:barcode_widget/barcode_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter_animate/flutter_animate.dart'; import 'package:google_fonts/google_fonts.dart'; // import 'package:percent_indicator/percent_indicator.dart'; import 'qr_code_page_model.dart'; export 'qr_code_page_model.dart'; import 'package:qr_flutter/qr_flutter.dart'; class QrCodePageWidget extends StatefulWidget { const QrCodePageWidget({super.key}); @override State createState() => _QrCodePageWidgetState(); } class _QrCodePageWidgetState extends State with TickerProviderStateMixin { late QrCodePageModel _model; final scaffoldKey = GlobalKey(); final animationsMap = {}; @override void initState() { super.initState(); _model = createModel(context, () => QrCodePageModel()); // On page load action. SchedulerBinding.instance.addPostFrameCallback((_) async { if (animationsMap['barcodeOnActionTriggerAnimation'] != null) { animationsMap['barcodeOnActionTriggerAnimation']!.controller.fling(); } }); animationsMap.addAll({ 'barcodeOnActionTriggerAnimation': AnimationInfo( trigger: AnimationTrigger.onActionTrigger, applyInitialState: true, effectsBuilder: () => [ VisibilityEffect(duration: 1.ms), BlurEffect( curve: Curves.linear, delay: 0.0.ms, duration: 600.0.ms, begin: const Offset(0.0, 0.0), end: const Offset(10.0, 10.0), ), ], ), }); setupAnimations( animationsMap.values.where((anim) => anim.trigger == AnimationTrigger.onActionTrigger || !anim.applyInitialState), this, ); // // Adicionando um ouvinte de status à animação para reiniciá-la após a conclusão // animationsMap['barcodeOnActionTriggerAnimation']?.controller.addStatusListener((status) { // if (status == AnimationStatus.completed) { // animationsMap['barcodeOnActionTriggerAnimation']!.controller.reset(); // animationsMap['barcodeOnActionTriggerAnimation']!.controller.forward(); // } // }); } @override void dispose() { // Removendo o ouvinte antes de chamar super.dispose para evitar vazamentos de memória if (animationsMap['barcodeOnActionTriggerAnimation'] != null) { animationsMap['barcodeOnActionTriggerAnimation']!.controller.removeStatusListener((status) {}); } super.dispose(); } @override Widget build(BuildContext context) { return GestureDetector( onTap: () => _model.unfocusNode.canRequestFocus ? FocusScope.of(context).requestFocus(_model.unfocusNode) : FocusScope.of(context).unfocus(), child: Scaffold( key: scaffoldKey, backgroundColor: FlutterFlowTheme.of(context).primaryBackground, appBar: buildAppBar(context), body: buildBody(context), ), ); } Widget buildBody(BuildContext context) { double screenWidth = MediaQuery.of(context).size.width; double screenHeight = MediaQuery.of(context).size.height; double smallerDimension = screenWidth < screenHeight ? screenWidth : screenHeight; double dimension = smallerDimension * 0.75; double totalTimeInSeconds = 100.0; return SafeArea( top: true, child: Column( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ if (_model.isAccess == true) Text( FFLocalizations.of(context).getVariableText( ptText: 'QR Code de Acesso', enText: 'Access QR Code', ), style: FlutterFlowTheme.of(context).bodyMedium.override( fontFamily: FlutterFlowTheme.of(context).bodyMediumFamily, fontSize: 20.0, letterSpacing: 0.0, fontWeight: FontWeight.bold, useGoogleFonts: GoogleFonts.asMap().containsKey( FlutterFlowTheme.of(context).bodyMediumFamily), ), ), Stack( children: [ 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.H, maskPattern: -1, version: QrVersions.auto, identifier: FFAppState().userDevUUID, pass: '1234', direction: 5, ), ), if(_model.isAccess == false) Align( alignment: const AlignmentDirectional(0, 0), child: BarcodeWidget( data: 'Barcode', barcode: Barcode.qrCode(), width: 300.0, height: 200.0, color: FlutterFlowTheme.of(context).primaryText, backgroundColor: Colors.transparent, errorBuilder: (context, error) => const SizedBox( width: 300.0, height: 200.0, ), drawText: false, ).animateOnActionTrigger( animationsMap['barcodeOnActionTriggerAnimation']!, ), ), if (_model.isAccess == false) Align( alignment: const AlignmentDirectional(0.0, 0.0), child: InkWell( splashColor: Colors.transparent, focusColor: Colors.transparent, hoverColor: Colors.transparent, highlightColor: Colors.transparent, onLongPress: () async { await _model.qrCodeEncoder( context, key: _model.key, ); setState(() {}); }, child: Container( width: 200.0, height: 200.0, decoration: const BoxDecoration(), child: Align( alignment: const AlignmentDirectional(0.0, 0.0), child: FFButtonWidget( onPressed: () async { await _showQrCodeBottomSheet(context); _toggleQrCodeAccess(); }, text: FFLocalizations.of(context).getText( 'mxdrsbmy' /* Liberar QR Code */, ), options: FFButtonOptions( height: 40.0, padding: const EdgeInsetsDirectional.fromSTEB( 24.0, 0.0, 24.0, 0.0), iconPadding: const EdgeInsetsDirectional.fromSTEB( 0.0, 0.0, 0.0, 0.0), color: FlutterFlowTheme.of(context).primary, textStyle: FlutterFlowTheme.of(context) .titleSmall .override( fontFamily: FlutterFlowTheme.of(context) .titleSmallFamily, color: Colors.white, letterSpacing: 0.0, useGoogleFonts: GoogleFonts.asMap() .containsKey( FlutterFlowTheme.of(context) .titleSmallFamily), ), elevation: 3.0, borderSide: const BorderSide( color: Colors.transparent, width: 1.0, ), borderRadius: BorderRadius.circular(8.0), ), ), ), ), ), ), ], ), if (_model.isAccess == true) Container( width: 300.0, decoration: const BoxDecoration(), child: Visibility( visible: _model.isAccess == false, child: Text( FFLocalizations.of(context).getVariableText( ptText: 'Certifique-se de que o QRCode está visivel para o leitor', enText: 'Make sure the QRCode is visible to the reader', // '6z6kvmhl' /* Certifique-se de que o QRCode ... */, ), style: FlutterFlowTheme.of(context).bodyMedium.override( fontFamily: FlutterFlowTheme.of(context).bodyMediumFamily, letterSpacing: 0.0, useGoogleFonts: GoogleFonts.asMap().containsKey( FlutterFlowTheme.of(context).bodyMediumFamily), ), ), ), ), if (_model.isAccess == true) Container( width: 250.0, height: 80.0, decoration: BoxDecoration( borderRadius: BorderRadius.circular(100.0), border: Border.all( color: FlutterFlowTheme.of(context).primary, ), ), child: Row( mainAxisSize: MainAxisSize.max, children: [ Expanded( child: Padding( padding: const EdgeInsetsDirectional.fromSTEB( 10.0, 0.0, 0.0, 0.0), child: Text( FFLocalizations.of(context).getVariableText( enText: 'Changing QR code in', ptText: 'Trocando QR code em', // 'wkjkxd2e' /* Trocando QR code em */, ), textAlign: TextAlign.center, style: FlutterFlowTheme.of(context) .bodyMedium .override( fontFamily: FlutterFlowTheme.of(context) .bodyMediumFamily, letterSpacing: 0.0, fontWeight: FontWeight.w600, useGoogleFonts: GoogleFonts.asMap() .containsKey(FlutterFlowTheme.of(context) .bodyMediumFamily), ), ), ), ), Align( alignment: const AlignmentDirectional(0.0, 0.0), child: Padding( padding: const EdgeInsetsDirectional.fromSTEB( 0.0, 0.0, 20.0, 0.0), child: StreamBuilder( stream: functions.getProgressValue(), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { return CircularProgressIndicator(); } else if (snapshot.hasError) { return Text('Error: ${snapshot.error}'); } else if (!snapshot.hasData) { return Text('No data'); } else { final progress = snapshot.data!; return CircularPercentIndicator( percent: progress, radius: 30.0, lineWidth: 7.0, animation: true, animateFromLastPercent: true, onAnimationEnd: () { _resetAnimationAndToggleAccess(); }, progressColor: FlutterFlowTheme.of(context).primary, backgroundColor: FlutterFlowTheme.of(context).primaryText, center: Text( '${(progress * totalTimeInSeconds / 5).toStringAsFixed(1)}s', style: FlutterFlowTheme.of(context).headlineSmall.override( fontFamily: FlutterFlowTheme.of(context).headlineSmallFamily, fontSize: 14.0, letterSpacing: 0.0, useGoogleFonts: GoogleFonts.asMap().containsKey( FlutterFlowTheme.of(context).headlineSmallFamily), ), ), startAngle: 20.0, ); } }, ), ), ), ], ), ), ], ), ); } void _toggleQrCodeAccess() { if (animationsMap['barcodeOnActionTriggerAnimation'] != null) { animationsMap['barcodeOnActionTriggerAnimation']!.controller.stop(); animationsMap['barcodeOnActionTriggerAnimation']!.controller.reverse(); } _model.isAccess = !_model.isAccess; setState(() {}); } Future _showQrCodeBottomSheet(BuildContext context) async { await showModalBottomSheet( isScrollControlled: true, backgroundColor: Colors.transparent, useSafeArea: true, context: context, builder: (context) { return GestureDetector( onTap: () => _model .unfocusNode.canRequestFocus ? FocusScope.of(context) .requestFocus(_model.unfocusNode) : FocusScope.of(context).unfocus(), child: Padding( padding: MediaQuery.viewInsetsOf(context), child: QrCodePassKeyTemplateComponentWidget( toggleActionStatus: (key) async { _model.key = key; setState(() {}); }, ), ), ); }, ).then((value) => safeSetState(() {})); unawaited( () async { await _model.qrCodeEncoder( context, key: _model.key, ); setState(() {}); }(), ); } void _resetAnimationAndToggleAccess() { setState(() { // Reinicia a animação animationsMap['barcodeOnActionTriggerAnimation']!.controller.reset(); animationsMap['barcodeOnActionTriggerAnimation']!.controller.forward(); // Alterna o estado de acesso _model.isAccess = !_model.isAccess; }); } AppBar buildAppBar(BuildContext context) { return AppBar( backgroundColor: FlutterFlowTheme.of(context).primaryBackground, automaticallyImplyLeading: false, leading: FlutterFlowIconButton( borderColor: Colors.transparent, borderRadius: 30.0, borderWidth: 1.0, buttonSize: 60.0, icon: Icon( Icons.keyboard_arrow_left, color: FlutterFlowTheme.of(context).primaryText, size: 30.0, ), onPressed: () async { context.pop(); }, ), title: Text( FFLocalizations.of(context).getText( 'ku7jqe53' /* QR Code de Acesso */, ), style: FlutterFlowTheme.of(context).headlineMedium.override( fontFamily: FlutterFlowTheme.of(context).headlineMediumFamily, color: FlutterFlowTheme.of(context).primaryText, fontSize: 16.0, letterSpacing: 0.0, useGoogleFonts: GoogleFonts.asMap().containsKey( FlutterFlowTheme.of(context).headlineMediumFamily), ), ), actions: const [], centerTitle: true, elevation: 0.0, ); } }