From a2c76286e6bd996347a31f3f998fd497d2154ce6 Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 23 Aug 2024 11:05:28 -0300 Subject: [PATCH] =?UTF-8?q?Feat:=20Configura=C3=A7=C3=A3o=20de=20Rotas=20e?= =?UTF-8?q?=20Ajuste=20na=20pagina=20de=20Reception?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/actions/actions.dart | 77 +++++---- lib/app_state.dart | 7 + .../sign_in_template_component_model.dart | 4 + .../sign_in_template_component_widget.dart | 2 + lib/flutter_flow/nav/nav.dart | 6 +- lib/pages/home_page/home_page_widget.dart | 2 - .../reception_page/reception_page_widget.dart | 153 +++++++++--------- 7 files changed, 136 insertions(+), 115 deletions(-) diff --git a/lib/actions/actions.dart b/lib/actions/actions.dart index 1d454af9..bff8a1f3 100644 --- a/lib/actions/actions.dart +++ b/lib/actions/actions.dart @@ -1,3 +1,5 @@ +import 'dart:math'; + import 'package:flutter/material.dart'; // import 'package:hub/components/organisms/bottom_arrow_linked_locals/bottom_arrow_linked_locals_component_widget.dart'; import 'package:hub/backend/api_requests/api_calls.dart'; @@ -96,7 +98,8 @@ Future manageStatusColorAction( } Future singInLoginAction( - BuildContext context, { + BuildContext context, + FlutterFlowModel model, { String? emailAdress, String? password, }) async { @@ -158,7 +161,11 @@ Future singInLoginAction( AppState().isLogged = true; - await toggleHomePage(context); + bool _haveLocal = await checkLocals(context: context, model: model); + print(await checkLocals(context: context, model: model)); + AppState().haveLocal = _haveLocal; + + await toggleApp(context, AppState().haveLocal); } else { if (PhpGroup.loginCall.msg((loginCall?.jsonBody ?? '')) == null) { DialogUtil.errorDefault(context); @@ -302,16 +309,27 @@ Future toggleSignUpPage(BuildContext context) async { ); } -Future toggleHomePage(BuildContext context) async { - context.goNamed( - 'homePage', - extra: { - kTransitionInfoKey: const TransitionInfo( - hasTransition: true, - transitionType: PageTransitionType.fade, - ), - }, - ); +Future toggleApp(BuildContext context, bool haveLocal) async { + if (haveLocal == true) + context.goNamed( + 'homePage', + extra: { + kTransitionInfoKey: const TransitionInfo( + hasTransition: true, + transitionType: PageTransitionType.fade, + ), + }, + ); + else + context.goNamed( + 'receptionPage', + extra: { + kTransitionInfoKey: const TransitionInfo( + hasTransition: true, + transitionType: PageTransitionType.fade, + ) + }, + ); } Future visitCancelAction(BuildContext context, @@ -370,8 +388,7 @@ Future snackbar(BuildContext context, {required bool opt}) async { Future checkLocals({ String? cliUUID, required BuildContext context, - required HomePageModel model, - required void Function(void Function()) safeSetState, + required FlutterFlowModel model, }) async { // A chamada para a API permanece a mesma, assumindo que é necessária sempre. final response = await PhpGroup.getLocalsCall.call( @@ -386,32 +403,26 @@ Future checkLocals({ // Uso eficiente de coleções para verificar a condição desejada. final String uuid = cliUUID ?? AppState().cliUUID; - final bool itemFound = response.jsonBody['locais'].any( - (local) => local['CLI_ID'] == uuid && local['CLU_STATUS'] == "A", - ); - - // Log e retorno condicional baseado no resultado da busca. + final bool itemFound = + response.jsonBody['locais'].any((local) => local['CLI_ID'] == uuid); if (itemFound) { - return true; - } else { - // A chamada para showModalBottomSheet permanece, mas a atualização da UI é otimizada. + if (response.jsonBody['locais'] + .any((local) => local['CLU_STATUS'] == "A")) { + return true; + } await showModalBottomSheet( isScrollControlled: true, backgroundColor: Colors.transparent, enableDrag: false, + isDismissible: false, context: context, - builder: (context) => GestureDetector( - onTap: () => model.unfocusNode.canRequestFocus - ? FocusScope.of(context).requestFocus(model.unfocusNode) - : FocusScope.of(context).unfocus(), - child: Padding( - padding: MediaQuery.viewInsetsOf(context), - child: const BottomArrowLinkedLocalsComponentWidget(), - ), + builder: (context) => Padding( + padding: MediaQuery.viewInsetsOf(context), + child: const BottomArrowLinkedLocalsComponentWidget(), ), - ); - safeSetState( - () {}); // Chamada otimizada fora do then para evitar encadeamentos desnecessários. + ); // Chamada oti + return false; + } else { return false; } } diff --git a/lib/app_state.dart b/lib/app_state.dart index 7d2a5df8..71aa445c 100644 --- a/lib/app_state.dart +++ b/lib/app_state.dart @@ -380,6 +380,13 @@ class AppState extends ChangeNotifier { secureStorage.setBool('ff_isLogged', value); } + bool _haveLocal = false; + bool get haveLocal => _haveLocal; + set haveLocal(bool value) { + _haveLocal = value; + secureStorage.setBool('ff_local', value); + } + void deleteIsLogged() { secureStorage.delete(key: 'ff_isLogged'); } diff --git a/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart b/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart index e1010ec7..165de263 100644 --- a/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart +++ b/lib/components/templates_components/sign_in_template_component/sign_in_template_component_model.dart @@ -1,3 +1,5 @@ +import 'package:hub/pages/home_page/home_page_model.dart'; + import '/flutter_flow/flutter_flow_util.dart'; import 'sign_in_template_component_widget.dart' show SignInTemplateComponentWidget; @@ -13,6 +15,8 @@ class SignInTemplateComponentModel FocusNode? emailAddressFocusNode; TextEditingController? emailAddressTextController; String? Function(BuildContext, String?)? emailAddressTextControllerValidator; + + SignInTemplateComponentModel(); String? _emailAddressTextControllerValidator( BuildContext context, String? val) { if (val == null || val.isEmpty) { diff --git a/lib/components/templates_components/sign_in_template_component/sign_in_template_component_widget.dart b/lib/components/templates_components/sign_in_template_component/sign_in_template_component_widget.dart index 37658f1b..419b80f9 100644 --- a/lib/components/templates_components/sign_in_template_component/sign_in_template_component_widget.dart +++ b/lib/components/templates_components/sign_in_template_component/sign_in_template_component_widget.dart @@ -548,6 +548,7 @@ class _SignInTemplateComponentWidgetState await action_blocks .singInLoginAction( context, + _model, emailAdress: _model .emailAddressTextController .text, @@ -707,6 +708,7 @@ class _SignInTemplateComponentWidgetState await action_blocks .singInLoginAction( context, + _model, emailAdress: _model .emailAddressTextController .text, diff --git a/lib/flutter_flow/nav/nav.dart b/lib/flutter_flow/nav/nav.dart index ba1ab412..a54d3f73 100644 --- a/lib/flutter_flow/nav/nav.dart +++ b/lib/flutter_flow/nav/nav.dart @@ -71,7 +71,9 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) => GoRouter( name: '_initialize', path: '/', builder: (context, _) => AppState().isLogged - ? const HomePageWidget() + ? AppState().haveLocal + ? const HomePageWidget() + : const ReceptionPageWidget() : const WelcomePageWidget(), ), FFRoute( @@ -133,7 +135,7 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) => GoRouter( FFRoute( name: 'acessHistoryPage', path: '/acessHistoryPage', - builder: (context, params) => AcessHistoryPageWidget(opt: { + builder: (context, params) => AcessHistoryPageWidget(opt: const { 'personType': '.*', 'accessType': '.*', 'search': '.*', diff --git a/lib/pages/home_page/home_page_widget.dart b/lib/pages/home_page/home_page_widget.dart index 9a78b86c..849ae66b 100644 --- a/lib/pages/home_page/home_page_widget.dart +++ b/lib/pages/home_page/home_page_widget.dart @@ -29,12 +29,10 @@ class _HomePageWidgetState extends State { bool localStatus = false; final scaffoldKey = GlobalKey(); - Future checkLocalStatus() async { localStatus = await checkLocals( context: context, model: _model, - safeSetState: safeSetState, ); } diff --git a/lib/pages/reception_page/reception_page_widget.dart b/lib/pages/reception_page/reception_page_widget.dart index ee020787..4f7e31ed 100644 --- a/lib/pages/reception_page/reception_page_widget.dart +++ b/lib/pages/reception_page/reception_page_widget.dart @@ -72,87 +72,34 @@ class _ReceptionPageWidgetState extends State { ), ), ), - Row( + Column( + mainAxisAlignment: MainAxisAlignment.center, + mainAxisSize: MainAxisSize.max, children: [ - Expanded( - child: Padding( - padding: const EdgeInsets.fromLTRB(30, 0, 10, 0), - child: Tooltip( - message: FFLocalizations.of(context).getVariableText( - ptText: - 'Seu identificador é utilizado para efetuar\no vinculo do seu APP com o condominio.', - enText: 'My Identifier'), - textStyle: FlutterFlowTheme.of(context) - .labelSmall - .override( - fontFamily: 'Nunito Sans', - color: FlutterFlowTheme.of(context) - .secondaryText, - fontSize: 10.0, - letterSpacing: 0.0, - fontWeight: FontWeight.w500, - useGoogleFonts: GoogleFonts.asMap() - .containsKey('Plus Jakarta Sans'), - ), - child: FFButtonWidget( - onPressed: () => model.getIdenfifier(context), - text: FFLocalizations.of(context).getVariableText( - ptText: 'Meu Identificador', - enText: 'My Identifier'), - options: FFButtonOptions( - width: double.infinity, - height: 44.0, - padding: const EdgeInsetsDirectional.fromSTEB( - 0.0, 0.0, 0.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: 'Nunito Sans', - color: FlutterFlowTheme.of(context) - .primaryBackground, - fontSize: 14.0, - letterSpacing: 0.0, - fontWeight: FontWeight.w500, - useGoogleFonts: GoogleFonts.asMap() - .containsKey('Plus Jakarta Sans'), - ), - elevation: 3.0, - borderSide: const BorderSide( - color: Colors.transparent, - width: 1.0, - ), - borderRadius: BorderRadius.circular(12.0), + Padding( + padding: const EdgeInsets.fromLTRB(60, 0, 60, 10), + child: Tooltip( + message: FFLocalizations.of(context).getVariableText( + ptText: + 'Seu identificador é utilizado para efetuar\no vinculo do seu APP com o condominio.', + enText: 'My Identifier'), + textStyle: FlutterFlowTheme.of(context) + .labelSmall + .override( + fontFamily: 'Nunito Sans', + color: + FlutterFlowTheme.of(context).secondaryText, + fontSize: 10.0, + letterSpacing: 0.0, + fontWeight: FontWeight.w500, + useGoogleFonts: GoogleFonts.asMap() + .containsKey('Plus Jakarta Sans'), ), - showLoadingIndicator: false, - ), - ), - ), - ), - Expanded( - child: Padding( - padding: const EdgeInsets.fromLTRB(10, 0, 30, 0), child: FFButtonWidget( - onPressed: () async { - AppState().deleteAll(); - setState(() {}); - - context.goNamed( - 'welcomePage', - extra: { - kTransitionInfoKey: const TransitionInfo( - hasTransition: true, - transitionType: PageTransitionType.scale, - alignment: Alignment.bottomCenter, - ), - }, - ); - }, + onPressed: () => model.getIdenfifier(context), text: FFLocalizations.of(context).getVariableText( - ptText: 'Sair da Conta', enText: 'Logout'), + ptText: 'Meu Identificador', + enText: 'My Identifier'), options: FFButtonOptions( width: double.infinity, height: 44.0, @@ -160,7 +107,7 @@ class _ReceptionPageWidgetState extends State { 0.0, 0.0, 0.0, 0.0), iconPadding: const EdgeInsetsDirectional.fromSTEB( 0.0, 0.0, 0.0, 0.0), - color: FlutterFlowTheme.of(context).customColor1, + color: FlutterFlowTheme.of(context).primary, textStyle: FlutterFlowTheme.of(context) .titleSmall .override( @@ -184,6 +131,56 @@ class _ReceptionPageWidgetState extends State { ), ), ), + Padding( + padding: const EdgeInsets.fromLTRB(60, 0, 60, 0), + child: FFButtonWidget( + onPressed: () async { + AppState().deleteAll(); + setState(() {}); + + context.goNamed( + 'welcomePage', + extra: { + kTransitionInfoKey: const TransitionInfo( + hasTransition: true, + transitionType: PageTransitionType.scale, + alignment: Alignment.bottomCenter, + ), + }, + ); + }, + text: FFLocalizations.of(context).getVariableText( + ptText: 'Sair da Conta', enText: 'Logout'), + options: FFButtonOptions( + width: double.infinity, + height: 44.0, + padding: const EdgeInsetsDirectional.fromSTEB( + 0.0, 0.0, 0.0, 0.0), + iconPadding: const EdgeInsetsDirectional.fromSTEB( + 0.0, 0.0, 0.0, 0.0), + color: FlutterFlowTheme.of(context).customColor1, + textStyle: FlutterFlowTheme.of(context) + .titleSmall + .override( + fontFamily: 'Nunito Sans', + color: FlutterFlowTheme.of(context) + .primaryBackground, + fontSize: 14.0, + letterSpacing: 0.0, + fontWeight: FontWeight.w500, + useGoogleFonts: GoogleFonts.asMap() + .containsKey('Plus Jakarta Sans'), + ), + elevation: 3.0, + borderSide: const BorderSide( + color: Colors.transparent, + width: 1.0, + ), + borderRadius: BorderRadius.circular(12.0), + ), + showLoadingIndicator: false, + ), + ), ], ), ],