From 5d6f4209d632070d025e290e8215530142ca84aa Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 9 Aug 2024 11:25:25 -0300 Subject: [PATCH 1/4] Ajuste de responsividade, do modal e tratamento de erro --- .../message_opt_modal/opt_modal_widget.dart | 285 +++++++------ .../card_item_template_component_widget.dart | 107 +++-- lib/flutter_flow/internationalization.dart | 4 +- lib/main.dart | 3 +- .../acess_history_page_widget.dart | 374 ++++++------------ 5 files changed, 320 insertions(+), 453 deletions(-) diff --git a/lib/components/molecular_components/message_opt_modal/opt_modal_widget.dart b/lib/components/molecular_components/message_opt_modal/opt_modal_widget.dart index 6b2df897..7dfaf73c 100644 --- a/lib/components/molecular_components/message_opt_modal/opt_modal_widget.dart +++ b/lib/components/molecular_components/message_opt_modal/opt_modal_widget.dart @@ -1,3 +1,4 @@ +import 'dart:ffi'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -7,7 +8,6 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/internationalization.dart'; - class OptModalWidget extends StatefulWidget { final String defaultPersonType; final String defaultAccessType; @@ -65,7 +65,7 @@ class _OptModalWidgetState extends State { Map filterResult = { 'personType': '', 'accessType': '', - 'search': _model.textController?.text == '' + 'search': _model.textController?.text == '' ? '.*' : _model.textController!.text.toLowerCase(), }; @@ -89,7 +89,8 @@ class _OptModalWidgetState extends State { Navigator.pop(context, filterResult); } - Widget _buildCheckboxListTile(String key, List> options) { + Widget _buildCheckboxListTile( + String key, List> options, double fontsize) { return Column( children: [ Row( @@ -97,14 +98,13 @@ class _OptModalWidgetState extends State { mainAxisAlignment: MainAxisAlignment.start, children: [ Padding( - padding: - const EdgeInsetsDirectional.fromSTEB(0.0, 10.0, 0.0, 0.0), + padding: const EdgeInsetsDirectional.fromSTEB(0.0, 3.0, 0.0, 0.0), child: Text( FFLocalizations.of(context).getText('l7tw8b92'), - textAlign: TextAlign - .left, // Adiciona esta linha para alinhar o texto à esquerda + textAlign: TextAlign.left, style: FlutterFlowTheme.of(context).bodyMedium.override( fontFamily: FlutterFlowTheme.of(context).bodyMediumFamily, + fontSize: fontsize, letterSpacing: 0.0, useGoogleFonts: GoogleFonts.asMap().containsKey( FlutterFlowTheme.of(context).bodyMediumFamily), @@ -115,6 +115,7 @@ class _OptModalWidgetState extends State { ], ), ListView.builder( + physics: const NeverScrollableScrollPhysics(), shrinkWrap: true, itemCount: options.length, itemBuilder: (context, index) { @@ -125,6 +126,7 @@ class _OptModalWidgetState extends State { style: FlutterFlowTheme.of(context).bodyMedium.override( fontFamily: FlutterFlowTheme.of(context).bodyMediumFamily, letterSpacing: 0.0, + fontSize: fontsize, useGoogleFonts: GoogleFonts.asMap().containsKey( FlutterFlowTheme.of(context).bodyMediumFamily), color: FlutterFlowTheme.of(context).primaryText, @@ -148,9 +150,10 @@ class _OptModalWidgetState extends State { checkboxShape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(100), ), + enableFeedback: true, side: BorderSide( - width: 10, + width: 5, color: FlutterFlowTheme.of(context).secondaryText, ), controlAffinity: @@ -178,157 +181,153 @@ class _OptModalWidgetState extends State { @override Widget build(BuildContext context) { - return SafeArea( - child: Align( - alignment: const AlignmentDirectional(1.0, -1.0), + double screenWidth = MediaQuery.of(context).size.width; + double screenHeight = MediaQuery.of(context).size.height; + + return Center( + child: Container( + width: screenWidth * 0.75, + height: screenHeight * 0.70, + decoration: BoxDecoration( + color: FlutterFlowTheme.of(context).primaryBackground, + borderRadius: BorderRadius.circular(24.0), + ), child: Padding( - padding: const EdgeInsetsDirectional.fromSTEB(0.0, 50.0, 50.0, 0.0), - child: Container( - width: 300.0, - height: 450.0, - decoration: BoxDecoration( - color: FlutterFlowTheme.of(context).primaryBackground, - borderRadius: BorderRadius.circular(24.0), - ), - child: Padding( - padding: const EdgeInsets.all(4.0), - child: Column( + padding: const EdgeInsets.all(4.0), + child: Column( + children: [ + Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.start, children: [ - Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsetsDirectional.fromSTEB( - 10.0, 10.0, 0.0, 10.0), - child: Text( - FFLocalizations.of(context) - .getText('yfj9pd6k'), // Filtros - style: FlutterFlowTheme.of(context) - .headlineMedium - .override( + Padding( + padding: const EdgeInsetsDirectional.fromSTEB( + 10.0, 10.0, 0.0, 10.0), + child: Text( + FFLocalizations.of(context) + .getText('yfj9pd6k'), // Filtros + style: + FlutterFlowTheme.of(context).headlineMedium.override( fontFamily: FlutterFlowTheme.of(context) .headlineMediumFamily, color: FlutterFlowTheme.of(context).primaryText, - fontSize: 16.0, + fontSize: 18.0, letterSpacing: 0.0, + fontWeight: FontWeight.bold, useGoogleFonts: GoogleFonts.asMap().containsKey( FlutterFlowTheme.of(context) .headlineMediumFamily), ), - ), - ), - ], - ), - Padding( - padding: const EdgeInsetsDirectional.fromSTEB( - 8.0, 0.0, 8.0, 0.0), - child: TextFormField( - controller: _model.textController, - focusNode: _model.textFieldFocusNode, - autofocus: false, - obscureText: false, - decoration: InputDecoration( - isDense: true, - labelText: FFLocalizations.of(context).getText( - '0enrtljz' /* Pesquise aqui..... */, - ), - labelStyle: FlutterFlowTheme.of(context) - .labelMedium - .override( - fontFamily: FlutterFlowTheme.of(context) - .labelMediumFamily, - color: FlutterFlowTheme.of(context).primaryText, - letterSpacing: 0.0, - useGoogleFonts: GoogleFonts.asMap().containsKey( - FlutterFlowTheme.of(context) - .labelMediumFamily), - ), - hintStyle: FlutterFlowTheme.of(context) - .labelMedium - .override( - fontFamily: FlutterFlowTheme.of(context) - .labelMediumFamily, - color: FlutterFlowTheme.of(context).primaryText, - letterSpacing: 0.0, - useGoogleFonts: GoogleFonts.asMap().containsKey( - FlutterFlowTheme.of(context) - .labelMediumFamily), - ), - enabledBorder: OutlineInputBorder( - borderSide: BorderSide( - color: FlutterFlowTheme.of(context).alternate, - width: 1, - ), - borderRadius: BorderRadius.circular(8.0), - ), - focusedBorder: OutlineInputBorder( - borderSide: BorderSide( - color: FlutterFlowTheme.of(context).primary, - width: 1, - ), - borderRadius: BorderRadius.circular(8.0), - ), - errorBorder: OutlineInputBorder( - borderSide: BorderSide( - color: FlutterFlowTheme.of(context).error, - width: 1, - ), - borderRadius: BorderRadius.circular(8.0), - ), - focusedErrorBorder: OutlineInputBorder( - borderSide: BorderSide( - color: FlutterFlowTheme.of(context).error, - width: 1, - ), - borderRadius: BorderRadius.circular(8.0), - ), - filled: true, - fillColor: FlutterFlowTheme.of(context).alternate, - suffixIcon: const Icon( - Icons.search_outlined, - ), - ), - style: FlutterFlowTheme.of(context).bodyMedium.override( - fontFamily: - FlutterFlowTheme.of(context).bodyMediumFamily, - letterSpacing: 0.0, - useGoogleFonts: GoogleFonts.asMap().containsKey( - FlutterFlowTheme.of(context).bodyMediumFamily), - ), - validator: - _model.textControllerValidator.asValidator(context), - ), - ), - SingleChildScrollView( - child: Container( - padding: const EdgeInsets.all(20), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - _buildCheckboxListTile( - 'personType', personTypeOptions), - _buildCheckboxListTile( - 'accessType', accessTypeOptions), - ], - ), - ), - ), - ElevatedButton( - onPressed: _applyFilter, - child: - Text(FFLocalizations.of(context).getText('88kshkph')), - style: ElevatedButton.styleFrom( - foregroundColor: FlutterFlowTheme.of(context).info, - backgroundColor: FlutterFlowTheme.of(context).primary, ), ), ], ), - ), + Padding( + padding: + const EdgeInsetsDirectional.fromSTEB(8.0, 0.0, 8.0, 0.0), + child: TextFormField( + controller: _model.textController, + focusNode: _model.textFieldFocusNode, + autofocus: false, + obscureText: false, + decoration: InputDecoration( + isDense: true, + labelText: FFLocalizations.of(context).getText( + '0enrtljz' /* Pesquise aqui... */, + ), + labelStyle: FlutterFlowTheme.of(context) + .labelMedium + .override( + fontFamily: + FlutterFlowTheme.of(context).labelMediumFamily, + color: FlutterFlowTheme.of(context).primaryText, + letterSpacing: 0.0, + useGoogleFonts: GoogleFonts.asMap().containsKey( + FlutterFlowTheme.of(context).labelMediumFamily), + ), + hintStyle: FlutterFlowTheme.of(context) + .labelMedium + .override( + fontFamily: + FlutterFlowTheme.of(context).labelMediumFamily, + color: FlutterFlowTheme.of(context).primaryText, + letterSpacing: 0.0, + useGoogleFonts: GoogleFonts.asMap().containsKey( + FlutterFlowTheme.of(context).labelMediumFamily), + ), + enabledBorder: OutlineInputBorder( + borderSide: BorderSide( + color: FlutterFlowTheme.of(context).alternate, + width: 1, + ), + borderRadius: BorderRadius.circular(8.0), + ), + focusedBorder: OutlineInputBorder( + borderSide: BorderSide( + color: FlutterFlowTheme.of(context).primary, + width: 1, + ), + borderRadius: BorderRadius.circular(8.0), + ), + errorBorder: OutlineInputBorder( + borderSide: BorderSide( + color: FlutterFlowTheme.of(context).error, + width: 1, + ), + borderRadius: BorderRadius.circular(8.0), + ), + focusedErrorBorder: OutlineInputBorder( + borderSide: BorderSide( + color: FlutterFlowTheme.of(context).error, + width: 1, + ), + borderRadius: BorderRadius.circular(8.0), + ), + filled: true, + fillColor: FlutterFlowTheme.of(context).alternate, + suffixIcon: const Icon( + Icons.search_outlined, + ), + ), + style: FlutterFlowTheme.of(context).bodyMedium.override( + fontFamily: + FlutterFlowTheme.of(context).bodyMediumFamily, + letterSpacing: 0.0, + useGoogleFonts: GoogleFonts.asMap().containsKey( + FlutterFlowTheme.of(context).bodyMediumFamily), + ), + validator: + _model.textControllerValidator.asValidator(context), + ), + ), + Expanded( + child: SingleChildScrollView( + child: Container( + padding: const EdgeInsets.all(10), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + _buildCheckboxListTile('personType', personTypeOptions, + screenHeight * 0.025), + _buildCheckboxListTile('accessType', accessTypeOptions, + screenHeight * 0.025), + ], + ), + ), + ), + ), + ElevatedButton( + onPressed: _applyFilter, + style: ElevatedButton.styleFrom( + foregroundColor: FlutterFlowTheme.of(context).info, + backgroundColor: FlutterFlowTheme.of(context).primary, + ), + child: Text(FFLocalizations.of(context).getText('88kshkph')), + ), + ], ), ), ), ); } -} \ No newline at end of file +} diff --git a/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart b/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart index a1e4cfc6..9550f897 100644 --- a/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart +++ b/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart @@ -1,6 +1,8 @@ import 'dart:collection'; import 'dart:developer'; +import 'package:auto_size_text/auto_size_text.dart'; + import '/flutter_flow/flutter_flow_theme.dart'; import '/flutter_flow/flutter_flow_util.dart'; import 'package:cached_network_image/cached_network_image.dart'; @@ -12,8 +14,6 @@ export 'card_item_template_component_model.dart'; /// - - class CardItemTemplateComponentWidget extends StatefulWidget { const CardItemTemplateComponentWidget({ super.key, @@ -25,7 +25,7 @@ class CardItemTemplateComponentWidget extends StatefulWidget { final Map? labelsHashMap; final List?> statusHashMap; - final Map imageHashMap; + final Map imageHashMap; final Future Function()? onTapCardItemAction; @override @@ -40,7 +40,9 @@ class _CardItemTemplateComponentWidgetState LinkedHashMap.from(widget.labelsHashMap ?? {}); List> get statusLinkedHashMap => - widget.statusHashMap.map((map) => LinkedHashMap.from(map ?? {})).toList(); + widget.statusHashMap + .map((map) => LinkedHashMap.from(map ?? {})) + .toList(); @override void setState(VoidCallback callback) { @@ -71,12 +73,18 @@ class _CardItemTemplateComponentWidgetState } } + String truncate(int cutoff, String mytext) { + return (mytext.length <= cutoff) + ? mytext + : '${mytext.substring(0, cutoff)}...'; + } + @override Widget build(BuildContext context) { + double screenWidth = MediaQuery.of(context).size.width; + double screenHeight = MediaQuery.of(context).size.height; context.watch(); - - return InkWell( splashColor: Colors.transparent, focusColor: Colors.transparent, @@ -123,7 +131,8 @@ class _CardItemTemplateComponentWidgetState labelsLinkedHashMap.keys.elementAt(index); String value = labelsLinkedHashMap[key]!; return Padding( - padding: const EdgeInsets.only(bottom: 5.0), + padding: + const EdgeInsets.fromLTRB(0, 5, 0, 3), child: Padding( padding: const EdgeInsets.fromLTRB(20, 0, 0, 0), @@ -140,7 +149,7 @@ class _CardItemTemplateComponentWidgetState fontFamily: FlutterFlowTheme.of(context) .bodyMediumFamily, - fontSize: 12.5, + fontSize: screenWidth * 0.025, letterSpacing: 0.0, fontWeight: FontWeight.bold, useGoogleFonts: GoogleFonts @@ -151,21 +160,23 @@ class _CardItemTemplateComponentWidgetState .bodyMediumFamily), color: FlutterFlowTheme.of(context) - .primaryText, + .customColor6, ), ), const SizedBox( width: 5.0), // Espaçamento entre o label e o valor Text( - value, + truncate(20, value), + overflow: TextOverflow.ellipsis, + maxLines: 1, style: FlutterFlowTheme.of(context) .bodyMedium .override( fontFamily: FlutterFlowTheme.of(context) .bodyMediumFamily, - fontSize: 12.5, + fontSize: screenWidth * 0.030, letterSpacing: 0.0, fontWeight: FontWeight.bold, useGoogleFonts: GoogleFonts @@ -183,40 +194,52 @@ class _CardItemTemplateComponentWidgetState }, ), ), - Row( - mainAxisAlignment: MainAxisAlignment.center, - mainAxisSize: MainAxisSize.max, - children: statusLinkedHashMap.expand((linkedHashMap) { - return linkedHashMap.entries.map((MapEntry item) { - return Container( - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Padding( - padding: const EdgeInsets.symmetric(horizontal: 1.0, vertical: 3.0), - child: Container( - width: 100.0, - height: 27.0, - decoration: BoxDecoration( - color: item.value, // Usa a cor do item atual - borderRadius: BorderRadius.circular(5.0), - ), - child: Align( - alignment: Alignment.center, - child: Text( - item.key, // Usa a chave do item atual como texto - style: TextStyle( - color: FlutterFlowTheme.of(context).info, // Ajuste conforme necessário + Padding( + padding: const EdgeInsets.fromLTRB(20, 0, 0, 0), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + children: + statusLinkedHashMap.expand((linkedHashMap) { + return linkedHashMap.entries + .map((MapEntry item) { + return Container( + child: Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Padding( + padding: const EdgeInsets.symmetric( + horizontal: 1.0, vertical: 3.0), + child: Container( + width: screenWidth * 0.20, + height: 27.0, + decoration: BoxDecoration( + color: item + .value, // Usa a cor do item atual + borderRadius: + BorderRadius.circular(5.0), + ), + child: Align( + alignment: Alignment.center, + child: Text( + item.key, // Usa a chave do item atual como texto + style: TextStyle( + fontSize: screenWidth * 0.03, + color: FlutterFlowTheme.of( + context) + .info, // Ajuste conforme necessário + ), ), ), ), ), - ), - ], - ), - ); - }).toList(); - }).toList(), + ], + ), + ); + }).toList(); + }).toList(), + ), ), ]), ), @@ -245,4 +268,4 @@ class _CardItemTemplateComponentWidgetState ), ); } -} \ No newline at end of file +} diff --git a/lib/flutter_flow/internationalization.dart b/lib/flutter_flow/internationalization.dart index ca57ae4a..ba266723 100644 --- a/lib/flutter_flow/internationalization.dart +++ b/lib/flutter_flow/internationalization.dart @@ -518,8 +518,8 @@ final kTranslationsMap = >>[ // optModal { '0enrtljz': { - 'pt': 'Pesquise aqui.....', - 'en': 'Search here.....', + 'pt': 'Pesquise aqui...', + 'en': 'Search here...', }, 'l7tw8b92': { 'pt': 'Tipo de Pessoa', diff --git a/lib/main.dart b/lib/main.dart index 2590c721..642f9e0b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,3 @@ - import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_crashlytics/firebase_crashlytics.dart'; import 'package:hub/app_state.dart'; @@ -141,4 +140,4 @@ class _MyAppState extends State { routerConfig: _router, ); } -} \ No newline at end of file +} diff --git a/lib/pages/acess_history_page/acess_history_page_widget.dart b/lib/pages/acess_history_page/acess_history_page_widget.dart index 58976eb6..ddd65809 100644 --- a/lib/pages/acess_history_page/acess_history_page_widget.dart +++ b/lib/pages/acess_history_page/acess_history_page_widget.dart @@ -19,9 +19,6 @@ import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/pages/acess_history_page/acess_history_page_model.dart'; import 'package:rxdart/rxdart.dart'; - - - @immutable class AcessHistoryPageWidget extends StatefulWidget { late Map opt = { @@ -43,8 +40,8 @@ class AccessHistoryItemWidget extends StatelessWidget { @override Widget build(BuildContext context) { - return Padding( - padding: const EdgeInsets.all(8.0), + return const Padding( + padding: EdgeInsets.all(8.0), child: Column(), ); } @@ -66,6 +63,7 @@ class _AcessHistoryPageWidgetState extends State { @override void initState() { super.initState(); + _model = createModel(context, () => AcessHistoryPageModel()); log("initState called in _AcessHistoryPageWidgetState"); } @@ -138,28 +136,44 @@ class _AcessHistoryPageWidgetState extends State { return Row( mainAxisAlignment: MainAxisAlignment.end, children: [ - IconButton( - icon: const Icon(Icons.filter_list), - padding: EdgeInsets.fromLTRB(0, 0, 10, 0), - onPressed: () async { - final Map? selectedFilter = - await showModalBottomSheet>( - isScrollControlled: true, - backgroundColor: Colors.transparent, - context: context, - builder: (context) => OptModalWidget( - defaultAccessType: - selectedTypeSubject.value['accessType'] ?? '.*', - defaultPersonType: - selectedTypeSubject.value['personType'] ?? '.*', - ), - ); + Padding( + padding: const EdgeInsets.fromLTRB(0, 0, 10, 0), + child: IconButton( + icon: const Icon(Icons.filter_list), + onPressed: () async { + final Map? selectedFilter = + await showModalBottomSheet>( + isScrollControlled: true, + backgroundColor: Colors.transparent, + context: context, + builder: (context) { + return GestureDetector( + onTap: () { + Navigator.of(context).pop(); + }, + child: Container( + color: Colors.transparent, + child: GestureDetector( + onTap: () {}, + child: OptModalWidget( + defaultAccessType: + selectedTypeSubject.value['accessType'] ?? + '.*', + defaultPersonType: + selectedTypeSubject.value['personType'] ?? + '.*', + ), + ), + ), + ); + }); - if (selectedFilter != null) { - log('Selected Filter: $selectedFilter'); - _updateAccessHistoryAction(selectedFilter); - } - }, + if (selectedFilter != null) { + log('Selected Filter: $selectedFilter'); + _updateAccessHistoryAction(selectedFilter); + } + }, + ), ), ], ); @@ -227,20 +241,22 @@ class _AcessHistoryPageWidgetState extends State { } Widget _accessHistoryListOrganismWidget(BuildContext context) { - return SingleChildScrollView( - child: Column( - children: [ - StreamBuilder>( - stream: selectedTypeSubject.stream, - builder: (context, snapshot) { - if (!snapshot.hasData) { - return Center(child: CircularProgressIndicator()); - } - final selected = snapshot.data!; - return _cardListViewOrganismWidget(selected); - }, - ), - ], + return Center( + child: SingleChildScrollView( + child: Column( + children: [ + StreamBuilder>( + stream: selectedTypeSubject.stream, + builder: (context, snapshot) { + if (!snapshot.hasData) { + return Center(child: CircularProgressIndicator()); + } + final selected = snapshot.data!; + return _cardListViewOrganismWidget(selected); + }, + ), + ], + ), ), ); } @@ -253,8 +269,7 @@ class _AcessHistoryPageWidgetState extends State { log('Response: ${response.jsonBody}'); final List accessHistory = response.jsonBody['acessos'] ?? []; log('Access History Before Filtering: $accessHistory'); - log( - 'Filtering for: Person Type - ${select['personType']}, Access Type - ${select['accessType']}, Search - ${select['search']}'); + log('Filtering for: Person Type - ${select['personType']}, Access Type - ${select['accessType']}, Search - ${select['search']}'); return accessHistory.where((item) { final personTypeMatches = select['personType'] == '.*' || @@ -272,8 +287,7 @@ class _AcessHistoryPageWidgetState extends State { } Widget _cardListViewOrganismWidget(Map selected) { - log( - 'Selected types in Card: ${selected['personType']}, ${selected['accessType']}'); + log('Selected types in Card: ${selected['personType']}, ${selected['accessType']}'); log('_buildAccessHistoryList called'); return FutureBuilder>( future: fetchCardListViewService(selected), @@ -290,8 +304,18 @@ class _AcessHistoryPageWidgetState extends State { ), ), ); + } else if (snapshot.hasData && snapshot.data!.isEmpty) { + return Center( + child: Text(FFLocalizations.of(context).getVariableText( + ptText: "Nenhum histórico encontrado!", + enText: "No history found!")), + ); } else if (snapshot.hasError) { - return Text('Error: ${snapshot.error}'); + return Center( + child: Text(FFLocalizations.of(context).getVariableText( + ptText: "Falha ao efetuar operação!", + enText: "Failed to perform operation!")), + ); } else { final accessHistory = snapshot.data!; log('Access History: $accessHistory'); @@ -301,8 +325,7 @@ class _AcessHistoryPageWidgetState extends State { itemCount: accessHistory.length, itemBuilder: (context, index) { final accessHistoryItem = accessHistory[index]; - log( - 'Access History Item: ${accessHistoryItem['PES_TIPO']}'); + log('Access History Item: ${accessHistoryItem['PES_TIPO']}'); return _accessHistoryCardMoleculeWidget( context, accessHistoryItem); }, @@ -314,7 +337,7 @@ class _AcessHistoryPageWidgetState extends State { Widget _accessHistoryCardMoleculeWidget( BuildContext context, dynamic accessHistoryItem) { - log('Access History Item: $accessHistoryItem'); + log('Access History Item: $accessHistoryItem'); return CardItemTemplateComponentWidget( imageHashMap: Map.from({ 'key': accessHistoryItem['PES_ID'] ?? '', @@ -327,230 +350,53 @@ class _AcessHistoryPageWidgetState extends State { }), statusHashMap: [ accessHistoryItem['PES_TIPO'] == 'O' - ? Map.from({ - FFLocalizations.of(context).getVariableText( - ptText: 'Morador', - enText: 'Resident', - ): FlutterFlowTheme.of(context).alternate2, - }) - : accessHistoryItem['PES_TIPO'] == 'E' - ? Map.from({ - FFLocalizations.of(context).getVariableText( - ptText: 'Visitante', - enText: 'Visitor', - ): FlutterFlowTheme.of(context).alternate2, - }) - : Map.from({ - FFLocalizations.of(context).getVariableText( - ptText: 'Desconhecido', - enText: 'Unknown', - ): FlutterFlowTheme.of(context).alternate2, - }), + ? Map.from({ + FFLocalizations.of(context).getVariableText( + ptText: 'Morador', + enText: 'Resident', + ): FlutterFlowTheme.of(context).alternate2, + }) + : accessHistoryItem['PES_TIPO'] == 'E' + ? Map.from({ + FFLocalizations.of(context).getVariableText( + ptText: 'Visitante', + enText: 'Visitor', + ): FlutterFlowTheme.of(context).alternate2, + }) + : Map.from({ + FFLocalizations.of(context).getVariableText( + ptText: 'Desconhecido', + enText: 'Unknown', + ): FlutterFlowTheme.of(context).alternate2, + }), accessHistoryItem['ACE_TIPO'] == '0' - ? Map.from({ - FFLocalizations.of(context).getVariableText( - ptText: 'Entrada', - enText: 'Entrance', - ): FlutterFlowTheme.of(context).success, - }) - : accessHistoryItem['ACE_TIPO'] == '1' - ? Map.from({ - FFLocalizations.of(context).getVariableText( - ptText: 'Saída', - enText: 'Exit', - ): FlutterFlowTheme.of(context).error, - }) - : Map.from({ - FFLocalizations.of(context).getVariableText( - ptText: 'Desconhecido', - enText: 'Unknown', - ): FlutterFlowTheme.of(context).warning, - }) + ? Map.from({ + FFLocalizations.of(context).getVariableText( + ptText: 'Entrada', + enText: 'Entrance', + ): FlutterFlowTheme.of(context).success, + }) + : accessHistoryItem['ACE_TIPO'] == '1' + ? Map.from({ + FFLocalizations.of(context).getVariableText( + ptText: 'Saída', + enText: 'Exit', + ): FlutterFlowTheme.of(context).error, + }) + : Map.from({ + FFLocalizations.of(context).getVariableText( + ptText: 'Desconhecido', + enText: 'Unknown', + ): FlutterFlowTheme.of(context).warning, + }) ], onTapCardItemAction: () async {}); } } -Widget _cardHeaderAtomWidget(BuildContext context, String urlImagem, - String tipoPessoa, Color corFundoTipo, accessHistoryItem) { - return Row( - mainAxisSize: MainAxisSize.max, - children: [ - Padding( - padding: const EdgeInsets.all(10.0), - child: ClipRRect( - borderRadius: BorderRadius.circular(100.0), - child: Image.network( - urlImagem, - width: 60.0, - height: 60.0, - fit: BoxFit.cover, - ), - ), - ), - Column( - mainAxisSize: MainAxisSize.max, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - getJsonField( - accessHistoryItem, - r'''$.PES_NOME''', - ).toString(), - style: FlutterFlowTheme.of(context).bodyMedium.override( - fontFamily: FlutterFlowTheme.of(context).bodyMediumFamily, - letterSpacing: 0.0, - useGoogleFonts: GoogleFonts.asMap().containsKey( - FlutterFlowTheme.of(context).bodyMediumFamily), - ), - ), - Container( - width: 100.0, - height: 25.0, - decoration: BoxDecoration( - color: (() { - // Extrai o valor de PES_TIPO, converte para String, remove espaços em branco e aspas - final pesTipo = - jsonToStr(getJsonField( - accessHistoryItem, - r'''$.PES_TIPO''', - )) - .trim() - .replaceAll('"', ''); // Remove aspas - - // Debug: Imprime o valor de PES_TIPO ajustado - log('PES_TIPO FOR COLORING: $pesTipo'); - - // Retorna a cor baseada na condição ajustada - return pesTipo == 'E' - ? FlutterFlowTheme.of(context).warning - : FlutterFlowTheme.of(context).primary; - })(), - borderRadius: BorderRadius.circular(24.0), - ), - child: Align( - alignment: const AlignmentDirectional(0.0, 0.0), - child: Text( - getJsonField( - accessHistoryItem, - r'''$.PES_TIPO''', - ).toString() == - 'E' - ? FFLocalizations.of(context).getText( - 'zok7lu4w', - ) - : FFLocalizations.of(context).getText( - 'oonqk812', - ), - style: FlutterFlowTheme.of(context).bodyMedium.override( - fontFamily: FlutterFlowTheme.of(context).bodyMediumFamily, - color: FlutterFlowTheme.of(context).info, - letterSpacing: 0.0, - useGoogleFonts: GoogleFonts.asMap().containsKey( - FlutterFlowTheme.of(context).bodyMediumFamily), - ), - ), - ), - ), - ], - ), - ] - .divide(const SizedBox(width: 20.0)) - .addToStart(const SizedBox(width: 5.0)) - .addToEnd(const SizedBox(width: 5.0)), - ); -} - -Widget _cardDetailsMoleculeWidget( - BuildContext context, dynamic accessHistoryItem) { - return Row( - mainAxisSize: MainAxisSize.max, - children: [ - Expanded( - child: Column( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Text( - FFLocalizations.of(context).getText( - '2odgr6hg', - ), - style: FlutterFlowTheme.of(context).bodyMedium.override( - fontFamily: - FlutterFlowTheme.of(context).bodyMediumFamily, - fontSize: 12.5, - letterSpacing: 0.0, - fontWeight: FontWeight.bold, - useGoogleFonts: GoogleFonts.asMap().containsKey( - FlutterFlowTheme.of(context).bodyMediumFamily), - ), - ), - Text( - getJsonField( - accessHistoryItem, - r'''$.ACE_DATAHORA''', - ).toString(), - style: FlutterFlowTheme.of(context).bodyMedium.override( - fontFamily: - FlutterFlowTheme.of(context).bodyMediumFamily, - fontSize: 12.5, - letterSpacing: 0.0, - useGoogleFonts: GoogleFonts.asMap().containsKey( - FlutterFlowTheme.of(context).bodyMediumFamily), - ), - ), - ].addToStart(const SizedBox(width: 10.0)), - ), - Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Text( - FFLocalizations.of(context).getText( - 'zrde3fke', - ), - style: FlutterFlowTheme.of(context).bodyMedium.override( - fontFamily: - FlutterFlowTheme.of(context).bodyMediumFamily, - fontSize: 12.5, - letterSpacing: 0.0, - fontWeight: FontWeight.bold, - useGoogleFonts: GoogleFonts.asMap().containsKey( - FlutterFlowTheme.of(context).bodyMediumFamily), - ), - ), - Text( - getJsonField( - accessHistoryItem, - r'''$.ACI_DESCRICAO''', - ).toString(), - style: FlutterFlowTheme.of(context).bodyMedium.override( - fontFamily: - FlutterFlowTheme.of(context).bodyMediumFamily, - fontSize: 12.5, - letterSpacing: 0.0, - useGoogleFonts: GoogleFonts.asMap().containsKey( - FlutterFlowTheme.of(context).bodyMediumFamily), - ), - ), - ].addToStart(const SizedBox(width: 10.0)), - ), - ].divide(const SizedBox(height: 3.0)), - ), - ), - ] - .addToStart(const SizedBox(width: 5.0)) - .addToEnd(const SizedBox(width: 5.0)), - ); -} - String imageUrlAtomWidget(String document, String type) { return valueOrDefault( "https://freaccess.com.br/freaccess/getImage.php?&cliID=${FFAppState().cliUUID}&atividade=getFoto&Documento=$document&tipo=$type", "https://storage.googleapis.com/flutterflow-io-6f20.appspot.com/projects/flutter-freaccess-hub-0xgz9q/assets/7ftdetkzc3s0/360_F_64676383_LdbmhiNM6Ypzb3FM4PPuFP9rHe7ri8Ju.jpg", ); -} \ No newline at end of file +} From b678ed514294e0d643d248a057d290af270e3212 Mon Sep 17 00:00:00 2001 From: Ivan Antunes Date: Mon, 12 Aug 2024 13:02:27 -0300 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20Pagina=C3=A7=C3=A3o=20do=20Historico?= =?UTF-8?q?=20de=20Acesso?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/backend/api_requests/api_calls.dart | 62 ++-- .../acess_history_page_model.dart | 6 +- .../acess_history_page_widget.dart | 290 +++++++++--------- 3 files changed, 173 insertions(+), 185 deletions(-) diff --git a/lib/backend/api_requests/api_calls.dart b/lib/backend/api_requests/api_calls.dart index 2a8838ec..1649576f 100644 --- a/lib/backend/api_requests/api_calls.dart +++ b/lib/backend/api_requests/api_calls.dart @@ -1715,7 +1715,7 @@ class RespondeSolicitacaoCall { } class GetAccessCall { - Stream call({ + Future call({ String? devUUID = '', String? userUUID = '', String? cliID = '', @@ -1725,43 +1725,31 @@ class GetAccessCall { String? pesTipo = '', }) { final baseUrl = PhpGroup.getBaseUrl(); - final StreamController controller = StreamController(); - Future.microtask(() async { - try { - final response = await ApiManager.instance.makeApiCall( - callName: 'getAccess', - apiUrl: '$baseUrl/processRequest.php', - callType: ApiCallType.POST, - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - }, - params: { - 'devUUID': devUUID, - 'userUUID': userUUID, - 'cliID': cliID, - 'atividade': atividade, - 'pageSize': pageSize, - 'pageNumber': pageNumber, - 'pesTipo': pesTipo, - }, - bodyType: BodyType.X_WWW_FORM_URL_ENCODED, - returnBody: true, - encodeBodyUtf8: false, - decodeUtf8: false, - cache: false, - isStreamingApi: false, - alwaysAllowBody: false, - ); - controller.add(response); - await controller.close(); - } catch (e) { - controller.addError(e); - await controller.close(); - } - }); - - return controller.stream; + return ApiManager.instance.makeApiCall( + callName: 'getAccess', + apiUrl: '$baseUrl/processRequest.php', + callType: ApiCallType.POST, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + params: { + 'devUUID': devUUID, + 'userUUID': userUUID, + 'cliID': cliID, + 'atividade': atividade, + 'pageSize': pageSize, + 'pageNumber': pageNumber, + 'pesTipo': pesTipo, + }, + bodyType: BodyType.X_WWW_FORM_URL_ENCODED, + returnBody: true, + encodeBodyUtf8: false, + decodeUtf8: false, + cache: false, + isStreamingApi: false, + alwaysAllowBody: false, + ); } bool? error(dynamic response) => castToType(getJsonField( diff --git a/lib/pages/acess_history_page/acess_history_page_model.dart b/lib/pages/acess_history_page/acess_history_page_model.dart index 4d633ac2..ea6e2115 100644 --- a/lib/pages/acess_history_page/acess_history_page_model.dart +++ b/lib/pages/acess_history_page/acess_history_page_model.dart @@ -11,11 +11,11 @@ import 'package:hub/pages/liberation_history/liberation_history_model.dart'; class AcessHistoryPageModel extends FlutterFlowModel { final unfocusNode = FocusNode(); - final _accessHistoryManager = StreamRequestManager(); - Stream accessHistory({ + final _accessHistoryManager = FutureRequestManager(); + Future accessHistory({ String? uniqueQueryKey, bool? overrideCache, - required Stream Function() requestFn, + required Future Function() requestFn, }) => _accessHistoryManager.performRequest( uniqueQueryKey: uniqueQueryKey, diff --git a/lib/pages/acess_history_page/acess_history_page_widget.dart b/lib/pages/acess_history_page/acess_history_page_widget.dart index ddd65809..4fa801d7 100644 --- a/lib/pages/acess_history_page/acess_history_page_widget.dart +++ b/lib/pages/acess_history_page/acess_history_page_widget.dart @@ -1,5 +1,6 @@ import 'dart:developer'; +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -7,9 +8,7 @@ import 'package:hub/app_state.dart'; import 'package:hub/backend/api_requests/api_calls.dart'; import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/components/molecular_components/message_opt_modal/opt_modal_widget.dart'; -import 'package:hub/components/molecular_components/option_selection_modal/option_selection_modal_widget.dart'; import 'package:hub/components/templates_components/card_item_template_component/card_item_template_component_widget.dart'; -import 'package:hub/flutter_flow/custom_functions.dart'; import 'package:hub/flutter_flow/flutter_flow_icon_button.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; @@ -17,6 +16,8 @@ import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/pages/acess_history_page/acess_history_page_model.dart'; +import 'package:hub/shared/utils/dialog_util.dart'; +import 'package:hub/shared/utils/log_util.dart'; import 'package:rxdart/rxdart.dart'; @immutable @@ -53,19 +54,34 @@ class _AcessHistoryPageWidgetState extends State { bool _isSubjectClosed = false; final scaffoldKey = GlobalKey(); - _AcessHistoryPageWidgetState(Map opt) - : selectedTypeSubject = BehaviorSubject.seeded(opt) { - selectedTypeSubject.listen((value) { - log("selectedTypeSubject changed: $value"); - }); + late ScrollController _scrollController; + int _pageNumber = 1; + final int _pageSize = 10; + bool _hasData = false; + bool _loading = false; + + String _personType = '.*'; + String _accessType = '.*'; + String _search = '.*'; + + late Future _accessFuture; + List _accessWrap = []; + + _AcessHistoryPageWidgetState(Map opt) : selectedTypeSubject = BehaviorSubject.seeded(opt) { + selectedTypeSubject.listen((value) {}); } @override void initState() { super.initState(); - _model = createModel(context, () => AcessHistoryPageModel()); - log("initState called in _AcessHistoryPageWidgetState"); + _accessFuture = fetchAccessHistoryService(); + + _scrollController = ScrollController()..addListener(() { + if (_scrollController.position.atEdge && _scrollController.position.pixels != 0) { + _loadMoreAccess(); + } + }); } @override @@ -77,31 +93,31 @@ class _AcessHistoryPageWidgetState extends State { @override Widget build(BuildContext context) { + final theme = FlutterFlowTheme.of(context); + return Scaffold( key: scaffoldKey, backgroundColor: FlutterFlowTheme.of(context).primaryBackground, - appBar: _appBarOrganismWidget(context), - body: _accessHistoryListOrganismWidget(context)); + appBar: _appBar(context, theme), + body: _body(context)); } -// AppBar Widgets - PreferredSizeWidget _appBarOrganismWidget(BuildContext context) { - final theme = FlutterFlowTheme.of(context); + + PreferredSizeWidget _appBar(BuildContext context, FlutterFlowTheme theme) { return AppBar( backgroundColor: theme.primaryBackground, automaticallyImplyLeading: false, - leading: _appBarBackButtonAtomWidget(context, theme), - title: _appBarTitleMoleculeWidget(context, theme), + leading: _backButton(context, theme), + title: _title(context, theme), centerTitle: true, elevation: 0.0, actions: [ - _appBarFilterButtonAtomWidget(context), + _filterButton(context) ], ); } - Widget _appBarBackButtonAtomWidget( - BuildContext context, FlutterFlowTheme theme) { + Widget _backButton(BuildContext context, FlutterFlowTheme theme) { return FlutterFlowIconButton( borderColor: Colors.transparent, borderRadius: 30.0, @@ -116,8 +132,7 @@ class _AcessHistoryPageWidgetState extends State { ); } - Widget _appBarTitleMoleculeWidget( - BuildContext context, FlutterFlowTheme theme) { + Widget _title(BuildContext context, FlutterFlowTheme theme) { return Text( FFLocalizations.of(context).getText('ch8qymga'), style: theme.headlineMedium.override( @@ -126,13 +141,12 @@ class _AcessHistoryPageWidgetState extends State { fontSize: 16.0, letterSpacing: 0.0, useGoogleFonts: - GoogleFonts.asMap().containsKey(theme.headlineMediumFamily), + GoogleFonts.asMap().containsKey(theme.headlineMediumFamily), ), ); } - Widget _appBarFilterButtonAtomWidget(BuildContext context) { - log('selectedTypeSubject: ${selectedTypeSubject.value}'); + Widget _filterButton(BuildContext context) { return Row( mainAxisAlignment: MainAxisAlignment.end, children: [ @@ -141,27 +155,20 @@ class _AcessHistoryPageWidgetState extends State { child: IconButton( icon: const Icon(Icons.filter_list), onPressed: () async { - final Map? selectedFilter = - await showModalBottomSheet>( + final Map? selectedFilter = await showModalBottomSheet>( isScrollControlled: true, backgroundColor: Colors.transparent, context: context, builder: (context) { return GestureDetector( - onTap: () { - Navigator.of(context).pop(); - }, + onTap: () => Navigator.of(context).pop(), child: Container( color: Colors.transparent, child: GestureDetector( onTap: () {}, child: OptModalWidget( - defaultAccessType: - selectedTypeSubject.value['accessType'] ?? - '.*', - defaultPersonType: - selectedTypeSubject.value['personType'] ?? - '.*', + defaultAccessType: selectedTypeSubject.value['accessType'] ?? '.*', + defaultPersonType: selectedTypeSubject.value['personType'] ?? '.*', ), ), ), @@ -169,7 +176,6 @@ class _AcessHistoryPageWidgetState extends State { }); if (selectedFilter != null) { - log('Selected Filter: $selectedFilter'); _updateAccessHistoryAction(selectedFilter); } }, @@ -192,108 +198,112 @@ class _AcessHistoryPageWidgetState extends State { }); if (needsUpdate) { selectedTypeSubject.add(updatedType); - log("updateAccessHistory called with newType: $newType"); + fetchCardListViewService(updatedType); safeSetState(() {}); } } } - Stream fetchAccessHistoryService(String selectedType) { - log('Calling API with type: $selectedType'); - switch (selectedType) { - case 'E': - return _model.accessHistory( - requestFn: () => PhpGroup.getAccessCall.call( - devUUID: FFAppState().devUUID, - userUUID: FFAppState().userUUID, - cliID: FFAppState().cliUUID, - atividade: 'getAcessos', - pageSize: '100', - pageNumber: '1', - pesTipo: 'E', - ), - ); - case 'O': - return _model.accessHistory( - requestFn: () => PhpGroup.getAccessCall.call( - devUUID: FFAppState().devUUID, - userUUID: FFAppState().userUUID, - cliID: FFAppState().cliUUID, - atividade: 'getAcessos', - pageSize: '100', - pageNumber: '1', - pesTipo: 'O', - ), - ); - default: - return _model.accessHistory( - requestFn: () => PhpGroup.getAccessCall.call( - devUUID: FFAppState().devUUID, - userUUID: FFAppState().userUUID, - cliID: FFAppState().cliUUID, - atividade: 'getAcessos', - pageSize: '100', - pageNumber: '1', - pesTipo: 'T', - ), - ); + Future fetchAccessHistoryService() async { + try { + setState(() => _loading = true); + var response = await PhpGroup.getAccessCall.call( + devUUID: FFAppState().devUUID, + userUUID: FFAppState().userUUID, + cliID: FFAppState().cliUUID, + atividade: 'getAcessos', + pageSize: _pageSize.toString(), + pageNumber: _pageNumber.toString(), + pesTipo: _personType != 'E' && _personType != 'O' ? 'T' : _personType, + ); + + final List accessHistory = response.jsonBody['acessos'] ?? []; + + List filteredAccess = accessHistory.where((item) { + final personTypeMatches = _personType == '.*' || item["PES_TIPO"].toString() == _personType; + final accessTypeMatches = _accessType == '.*' || item["ACE_TIPO"].toString() == _accessType; + final searchMatches = _search == '.*' || item["PES_NOME"].toString().toLowerCase().contains(_search.toLowerCase()); + return personTypeMatches && accessTypeMatches && searchMatches; + }).toList(); + + if (filteredAccess != null && filteredAccess.isNotEmpty) { + setState(() { + _accessWrap.addAll(filteredAccess); + _hasData = true; + _loading = false; + }); + return response; + } + + setState(() { + _hasData = false; + _loading = false; + }); + return null; + } catch (e, s) { + DialogUtil.errorDefault(context); + LogUtil.requestAPIFailed('processRequest', "", "Busca Acesso", e, s); + setState(() { + _hasData = false; + _loading = false; + }); } } - Widget _accessHistoryListOrganismWidget(BuildContext context) { - return Center( - child: SingleChildScrollView( - child: Column( - children: [ - StreamBuilder>( - stream: selectedTypeSubject.stream, - builder: (context, snapshot) { - if (!snapshot.hasData) { - return Center(child: CircularProgressIndicator()); - } - final selected = snapshot.data!; - return _cardListViewOrganismWidget(selected); - }, + Widget _body(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded(child: _cardListViewOrganismWidget()), + if (_loading) Container( + padding: const EdgeInsets.only(top: 15, bottom: 15), + color: FlutterFlowTheme.of(context).primary, + child: Center( + child: CircularProgressIndicator( + valueColor: AlwaysStoppedAnimation( + FlutterFlowTheme.of(context).info, + ), ), - ], + ), ), - ), + if (_hasData == false) Container( + padding: const EdgeInsets.only(top: 15, bottom: 15), + color: FlutterFlowTheme.of(context).primary, + child: Center( + child: Text( + FFLocalizations.of(context).getVariableText( + ptText: "Não há mais dados.", + enText: "No more data." + ), + style: TextStyle(color: FlutterFlowTheme.of(context).info), + ) + ), + ), + ], ); } - Future> fetchCardListViewService( - Map select) async { - log('Fetching access history'); - final response = - await fetchAccessHistoryService(select['personType']!).first; - log('Response: ${response.jsonBody}'); - final List accessHistory = response.jsonBody['acessos'] ?? []; - log('Access History Before Filtering: $accessHistory'); - log('Filtering for: Person Type - ${select['personType']}, Access Type - ${select['accessType']}, Search - ${select['search']}'); - - return accessHistory.where((item) { - final personTypeMatches = select['personType'] == '.*' || - item["PES_TIPO"].toString() == select['personType']; - final accessTypeMatches = select['accessType'] == '.*' || - item["ACE_TIPO"].toString() == select['accessType']; - final searchMatches = select['search'] == '.*' || - item["PES_NOME"] - .toString() - .toLowerCase() - .contains(select['search']!.toLowerCase()); - log('NOMES: ${item["PES_NOME"].toString().toLowerCase()}'); - return personTypeMatches && accessTypeMatches && searchMatches; - }).toList(); + void _loadMoreAccess() { + if (_hasData == true) { + _pageNumber++; + _accessFuture = fetchAccessHistoryService(); + } } - Widget _cardListViewOrganismWidget(Map selected) { - log('Selected types in Card: ${selected['personType']}, ${selected['accessType']}'); - log('_buildAccessHistoryList called'); - return FutureBuilder>( - future: fetchCardListViewService(selected), + void fetchCardListViewService(Map select) { + _personType = select['personType']!; + _accessType = select['accessType']!; + _search = select['search']!; + _accessWrap = []; + _pageNumber = 1; + _accessFuture = fetchAccessHistoryService(); + } + + Widget _cardListViewOrganismWidget() { + return FutureBuilder( + future: _accessFuture, builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.waiting) { - log('Waiting for data'); + if (snapshot.connectionState == ConnectionState.waiting && _accessWrap.isEmpty) { return Center( child: SizedBox( width: 50.0, @@ -304,40 +314,30 @@ class _AcessHistoryPageWidgetState extends State { ), ), ); - } else if (snapshot.hasData && snapshot.data!.isEmpty) { - return Center( - child: Text(FFLocalizations.of(context).getVariableText( - ptText: "Nenhum histórico encontrado!", - enText: "No history found!")), - ); } else if (snapshot.hasError) { return Center( child: Text(FFLocalizations.of(context).getVariableText( ptText: "Falha ao efetuar operação!", enText: "Failed to perform operation!")), ); - } else { - final accessHistory = snapshot.data!; - log('Access History: $accessHistory'); - return ListView.builder( - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - itemCount: accessHistory.length, - itemBuilder: (context, index) { - final accessHistoryItem = accessHistory[index]; - log('Access History Item: ${accessHistoryItem['PES_TIPO']}'); - return _accessHistoryCardMoleculeWidget( - context, accessHistoryItem); - }, - ); } + + return ListView.builder( + shrinkWrap: true, + physics: const BouncingScrollPhysics(), + controller: _scrollController, + itemCount: _accessWrap.length, + itemBuilder: (context, index) { + final accessHistoryItem = _accessWrap[index]; + return _accessHistoryCardMoleculeWidget(context, accessHistoryItem); + }, + ); }, ); } - Widget _accessHistoryCardMoleculeWidget( - BuildContext context, dynamic accessHistoryItem) { - log('Access History Item: $accessHistoryItem'); + Widget _accessHistoryCardMoleculeWidget(BuildContext context, dynamic accessHistoryItem) { + return CardItemTemplateComponentWidget( imageHashMap: Map.from({ 'key': accessHistoryItem['PES_ID'] ?? '', From 4d45de2890ebfd52a2ecb9ac28c79ac6869d3490 Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 12 Aug 2024 16:46:35 -0300 Subject: [PATCH 3/4] =?UTF-8?q?Adicionado=20tratamento=20de=20erro,=20corr?= =?UTF-8?q?igido=20modal,=20corrigido=20erro=20de=20espa=C3=A7amento=20do?= =?UTF-8?q?=20card=20e=20adicionado=20Snackbar.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../message_opt_modal/opt_modal_widget.dart | 90 +------------ .../card_item_template_component_widget.dart | 2 +- .../acess_history_page_widget.dart | 126 +++++++++++------- 3 files changed, 85 insertions(+), 133 deletions(-) diff --git a/lib/components/molecular_components/message_opt_modal/opt_modal_widget.dart b/lib/components/molecular_components/message_opt_modal/opt_modal_widget.dart index 7dfaf73c..bd40eb5a 100644 --- a/lib/components/molecular_components/message_opt_modal/opt_modal_widget.dart +++ b/lib/components/molecular_components/message_opt_modal/opt_modal_widget.dart @@ -30,10 +30,6 @@ class _OptModalWidgetState extends State { {'title': 'zok7lu4w', 'value': 'E'}, {'title': 'oonqk812', 'value': 'O'}, ]; - final List> accessTypeOptions = [ - {'title': '580z80ct', 'value': '0'}, - {'title': '1nbwqtzs', 'value': '1'}, - ]; @override void setState(VoidCallback callback) { @@ -187,7 +183,7 @@ class _OptModalWidgetState extends State { return Center( child: Container( width: screenWidth * 0.75, - height: screenHeight * 0.70, + height: screenHeight * 0.35, decoration: BoxDecoration( color: FlutterFlowTheme.of(context).primaryBackground, borderRadius: BorderRadius.circular(24.0), @@ -222,84 +218,6 @@ class _OptModalWidgetState extends State { ), ], ), - Padding( - padding: - const EdgeInsetsDirectional.fromSTEB(8.0, 0.0, 8.0, 0.0), - child: TextFormField( - controller: _model.textController, - focusNode: _model.textFieldFocusNode, - autofocus: false, - obscureText: false, - decoration: InputDecoration( - isDense: true, - labelText: FFLocalizations.of(context).getText( - '0enrtljz' /* Pesquise aqui... */, - ), - labelStyle: FlutterFlowTheme.of(context) - .labelMedium - .override( - fontFamily: - FlutterFlowTheme.of(context).labelMediumFamily, - color: FlutterFlowTheme.of(context).primaryText, - letterSpacing: 0.0, - useGoogleFonts: GoogleFonts.asMap().containsKey( - FlutterFlowTheme.of(context).labelMediumFamily), - ), - hintStyle: FlutterFlowTheme.of(context) - .labelMedium - .override( - fontFamily: - FlutterFlowTheme.of(context).labelMediumFamily, - color: FlutterFlowTheme.of(context).primaryText, - letterSpacing: 0.0, - useGoogleFonts: GoogleFonts.asMap().containsKey( - FlutterFlowTheme.of(context).labelMediumFamily), - ), - enabledBorder: OutlineInputBorder( - borderSide: BorderSide( - color: FlutterFlowTheme.of(context).alternate, - width: 1, - ), - borderRadius: BorderRadius.circular(8.0), - ), - focusedBorder: OutlineInputBorder( - borderSide: BorderSide( - color: FlutterFlowTheme.of(context).primary, - width: 1, - ), - borderRadius: BorderRadius.circular(8.0), - ), - errorBorder: OutlineInputBorder( - borderSide: BorderSide( - color: FlutterFlowTheme.of(context).error, - width: 1, - ), - borderRadius: BorderRadius.circular(8.0), - ), - focusedErrorBorder: OutlineInputBorder( - borderSide: BorderSide( - color: FlutterFlowTheme.of(context).error, - width: 1, - ), - borderRadius: BorderRadius.circular(8.0), - ), - filled: true, - fillColor: FlutterFlowTheme.of(context).alternate, - suffixIcon: const Icon( - Icons.search_outlined, - ), - ), - style: FlutterFlowTheme.of(context).bodyMedium.override( - fontFamily: - FlutterFlowTheme.of(context).bodyMediumFamily, - letterSpacing: 0.0, - useGoogleFonts: GoogleFonts.asMap().containsKey( - FlutterFlowTheme.of(context).bodyMediumFamily), - ), - validator: - _model.textControllerValidator.asValidator(context), - ), - ), Expanded( child: SingleChildScrollView( child: Container( @@ -307,10 +225,8 @@ class _OptModalWidgetState extends State { child: Column( mainAxisSize: MainAxisSize.min, children: [ - _buildCheckboxListTile('personType', personTypeOptions, - screenHeight * 0.025), - _buildCheckboxListTile('accessType', accessTypeOptions, - screenHeight * 0.025), + _buildCheckboxListTile( + 'personType', personTypeOptions, 14), ], ), ), diff --git a/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart b/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart index 9550f897..a315e2cc 100644 --- a/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart +++ b/lib/components/templates_components/card_item_template_component/card_item_template_component_widget.dart @@ -132,7 +132,7 @@ class _CardItemTemplateComponentWidgetState String value = labelsLinkedHashMap[key]!; return Padding( padding: - const EdgeInsets.fromLTRB(0, 5, 0, 3), + const EdgeInsets.fromLTRB(0, 2, 0, 5), child: Padding( padding: const EdgeInsets.fromLTRB(20, 0, 0, 0), diff --git a/lib/pages/acess_history_page/acess_history_page_widget.dart b/lib/pages/acess_history_page/acess_history_page_widget.dart index 4fa801d7..358b70c0 100644 --- a/lib/pages/acess_history_page/acess_history_page_widget.dart +++ b/lib/pages/acess_history_page/acess_history_page_widget.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:developer'; import 'package:flutter/cupertino.dart'; @@ -67,7 +68,8 @@ class _AcessHistoryPageWidgetState extends State { late Future _accessFuture; List _accessWrap = []; - _AcessHistoryPageWidgetState(Map opt) : selectedTypeSubject = BehaviorSubject.seeded(opt) { + _AcessHistoryPageWidgetState(Map opt) + : selectedTypeSubject = BehaviorSubject.seeded(opt) { selectedTypeSubject.listen((value) {}); } @@ -77,11 +79,20 @@ class _AcessHistoryPageWidgetState extends State { _model = createModel(context, () => AcessHistoryPageModel()); _accessFuture = fetchAccessHistoryService(); - _scrollController = ScrollController()..addListener(() { - if (_scrollController.position.atEdge && _scrollController.position.pixels != 0) { - _loadMoreAccess(); - } - }); + _scrollController = ScrollController() + ..addListener(() { + if (_scrollController.position.atEdge && + _scrollController.position.pixels != 0) { + _loadMoreAccess(); + WidgetsBinding.instance.addPostFrameCallback((_) { + Timer(const Duration(seconds: 3), () { + if (!_hasData && _pageNumber > 1) { + _showNoMoreDataSnackbar(context); + } + }); + }); + } + }); } @override @@ -102,7 +113,6 @@ class _AcessHistoryPageWidgetState extends State { body: _body(context)); } - PreferredSizeWidget _appBar(BuildContext context, FlutterFlowTheme theme) { return AppBar( backgroundColor: theme.primaryBackground, @@ -111,9 +121,7 @@ class _AcessHistoryPageWidgetState extends State { title: _title(context, theme), centerTitle: true, elevation: 0.0, - actions: [ - _filterButton(context) - ], + actions: [_filterButton(context)], ); } @@ -141,7 +149,7 @@ class _AcessHistoryPageWidgetState extends State { fontSize: 16.0, letterSpacing: 0.0, useGoogleFonts: - GoogleFonts.asMap().containsKey(theme.headlineMediumFamily), + GoogleFonts.asMap().containsKey(theme.headlineMediumFamily), ), ); } @@ -155,7 +163,8 @@ class _AcessHistoryPageWidgetState extends State { child: IconButton( icon: const Icon(Icons.filter_list), onPressed: () async { - final Map? selectedFilter = await showModalBottomSheet>( + final Map? selectedFilter = + await showModalBottomSheet>( isScrollControlled: true, backgroundColor: Colors.transparent, context: context, @@ -167,8 +176,12 @@ class _AcessHistoryPageWidgetState extends State { child: GestureDetector( onTap: () {}, child: OptModalWidget( - defaultAccessType: selectedTypeSubject.value['accessType'] ?? '.*', - defaultPersonType: selectedTypeSubject.value['personType'] ?? '.*', + defaultAccessType: + selectedTypeSubject.value['accessType'] ?? + '.*', + defaultPersonType: + selectedTypeSubject.value['personType'] ?? + '.*', ), ), ), @@ -220,9 +233,15 @@ class _AcessHistoryPageWidgetState extends State { final List accessHistory = response.jsonBody['acessos'] ?? []; List filteredAccess = accessHistory.where((item) { - final personTypeMatches = _personType == '.*' || item["PES_TIPO"].toString() == _personType; - final accessTypeMatches = _accessType == '.*' || item["ACE_TIPO"].toString() == _accessType; - final searchMatches = _search == '.*' || item["PES_NOME"].toString().toLowerCase().contains(_search.toLowerCase()); + final personTypeMatches = + _personType == '.*' || item["PES_TIPO"].toString() == _personType; + final accessTypeMatches = + _accessType == '.*' || item["ACE_TIPO"].toString() == _accessType; + final searchMatches = _search == '.*' || + item["PES_NOME"] + .toString() + .toLowerCase() + .contains(_search.toLowerCase()); return personTypeMatches && accessTypeMatches && searchMatches; }).toList(); @@ -250,35 +269,51 @@ class _AcessHistoryPageWidgetState extends State { } } + void _showNoMoreDataSnackbar(BuildContext context) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + FFLocalizations.of(context).getVariableText( + ptText: "Não há mais dados.", enText: "No more data."), + ), + duration: const Duration(seconds: 3), + backgroundColor: FlutterFlowTheme.of(context).primary, + ), + ); + } + Widget _body(BuildContext context) { return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded(child: _cardListViewOrganismWidget()), - if (_loading) Container( - padding: const EdgeInsets.only(top: 15, bottom: 15), - color: FlutterFlowTheme.of(context).primary, - child: Center( - child: CircularProgressIndicator( - valueColor: AlwaysStoppedAnimation( - FlutterFlowTheme.of(context).info, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + if (_hasData == false && _pageNumber <= 1 && _loading == false) + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + mainAxisSize: MainAxisSize.max, + children: [ + Center( + child: Text( + FFLocalizations.of(context).getVariableText( + ptText: "Nenhum histórico encontrado!", + enText: "No history found!"), + )), + ], + ), + ) + else if (_hasData || _pageNumber >= 1) + Expanded(child: _cardListViewOrganismWidget()), + if (_hasData == true && _loading) + Container( + padding: const EdgeInsets.only(top: 15, bottom: 15), + child: Center( + child: CircularProgressIndicator( + valueColor: AlwaysStoppedAnimation( + FlutterFlowTheme.of(context).primary, + ), ), ), - ), - ), - if (_hasData == false) Container( - padding: const EdgeInsets.only(top: 15, bottom: 15), - color: FlutterFlowTheme.of(context).primary, - child: Center( - child: Text( - FFLocalizations.of(context).getVariableText( - ptText: "Não há mais dados.", - enText: "No more data." - ), - style: TextStyle(color: FlutterFlowTheme.of(context).info), - ) - ), - ), + ) ], ); } @@ -303,7 +338,8 @@ class _AcessHistoryPageWidgetState extends State { return FutureBuilder( future: _accessFuture, builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.waiting && _accessWrap.isEmpty) { + if (snapshot.connectionState == ConnectionState.waiting && + _accessWrap.isEmpty) { return Center( child: SizedBox( width: 50.0, @@ -336,8 +372,8 @@ class _AcessHistoryPageWidgetState extends State { ); } - Widget _accessHistoryCardMoleculeWidget(BuildContext context, dynamic accessHistoryItem) { - + Widget _accessHistoryCardMoleculeWidget( + BuildContext context, dynamic accessHistoryItem) { return CardItemTemplateComponentWidget( imageHashMap: Map.from({ 'key': accessHistoryItem['PES_ID'] ?? '', From 61e23044d978572ce1789ab012cff5cdeb98561a Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 12 Aug 2024 17:32:07 -0300 Subject: [PATCH 4/4] =?UTF-8?q?Remo=C3=A7=C3=A3o=20de=20lixo=20de=20c?= =?UTF-8?q?=C3=B3digo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../acess_history_page_widget.dart | 25 ++----------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/lib/pages/acess_history_page/acess_history_page_widget.dart b/lib/pages/acess_history_page/acess_history_page_widget.dart index 358b70c0..7150cba4 100644 --- a/lib/pages/acess_history_page/acess_history_page_widget.dart +++ b/lib/pages/acess_history_page/acess_history_page_widget.dart @@ -62,8 +62,6 @@ class _AcessHistoryPageWidgetState extends State { bool _loading = false; String _personType = '.*'; - String _accessType = '.*'; - String _search = '.*'; late Future _accessFuture; List _accessWrap = []; @@ -84,13 +82,6 @@ class _AcessHistoryPageWidgetState extends State { if (_scrollController.position.atEdge && _scrollController.position.pixels != 0) { _loadMoreAccess(); - WidgetsBinding.instance.addPostFrameCallback((_) { - Timer(const Duration(seconds: 3), () { - if (!_hasData && _pageNumber > 1) { - _showNoMoreDataSnackbar(context); - } - }); - }); } }); } @@ -176,9 +167,6 @@ class _AcessHistoryPageWidgetState extends State { child: GestureDetector( onTap: () {}, child: OptModalWidget( - defaultAccessType: - selectedTypeSubject.value['accessType'] ?? - '.*', defaultPersonType: selectedTypeSubject.value['personType'] ?? '.*', @@ -235,14 +223,7 @@ class _AcessHistoryPageWidgetState extends State { List filteredAccess = accessHistory.where((item) { final personTypeMatches = _personType == '.*' || item["PES_TIPO"].toString() == _personType; - final accessTypeMatches = - _accessType == '.*' || item["ACE_TIPO"].toString() == _accessType; - final searchMatches = _search == '.*' || - item["PES_NOME"] - .toString() - .toLowerCase() - .contains(_search.toLowerCase()); - return personTypeMatches && accessTypeMatches && searchMatches; + return personTypeMatches; }).toList(); if (filteredAccess != null && filteredAccess.isNotEmpty) { @@ -253,7 +234,7 @@ class _AcessHistoryPageWidgetState extends State { }); return response; } - + _showNoMoreDataSnackbar(context); setState(() { _hasData = false; _loading = false; @@ -327,8 +308,6 @@ class _AcessHistoryPageWidgetState extends State { void fetchCardListViewService(Map select) { _personType = select['personType']!; - _accessType = select['accessType']!; - _search = select['search']!; _accessWrap = []; _pageNumber = 1; _accessFuture = fetchAccessHistoryService();