From 0e6bb9a03aeb6f5f3bca1412b43b919dd0467b21 Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 23 Aug 2024 15:13:33 -0300 Subject: [PATCH] Fix: Arrumado conflitos e alterada a logica no checkLocal --- lib/actions/actions.dart | 88 ++++--------------- lib/app_state.dart | 5 +- lib/flutter_flow/nav/nav.dart | 16 ---- lib/pages/home_page/home_page_widget.dart | 4 - .../preferences_settings_widget.dart | 11 --- pubspec.lock | 2 +- 6 files changed, 22 insertions(+), 104 deletions(-) diff --git a/lib/actions/actions.dart b/lib/actions/actions.dart index e9e8b45f..262d3df9 100644 --- a/lib/actions/actions.dart +++ b/lib/actions/actions.dart @@ -1,4 +1,4 @@ -import 'dart:math'; +import 'dart:developer'; import 'package:flutter/material.dart'; // import 'package:hub/components/organisms/bottom_arrow_linked_locals/bottom_arrow_linked_locals_component_widget.dart'; @@ -160,12 +160,8 @@ Future singInLoginAction( AppState().serialNumber = await getSerialNumber() ?? ''; AppState().isLogged = true; - - bool _haveLocal = await checkLocals(context: context, model: model); - print(await checkLocals(context: context, model: model)); - AppState().haveLocal = _haveLocal; - - await toggleApp(context, AppState().haveLocal); + AppState().haveLocal = + await checkLocals(context: context, model: model); } else { if (PhpGroup.loginCall.msg((loginCall?.jsonBody ?? '')) == null) { DialogUtil.errorDefault(context); @@ -320,7 +316,7 @@ Future toggleApp(BuildContext context, bool haveLocal) async { ), }, ); - else + else if (haveLocal == false) context.goNamed( 'receptionPage', extra: { @@ -390,24 +386,22 @@ Future checkLocals({ required BuildContext context, required FlutterFlowModel model, }) async { - bool itemFound = false; - var modalResult; + final response = await PhpGroup.getLocalsCall.call( + devUUID: AppState().devUUID, + userUUID: AppState().userUUID, + ); + log(response.jsonBody.toString()); -<<<<<<< HEAD // Verificação rápida de erro para evitar processamento desnecessário. if (response.jsonBody['error']) { + DialogUtil.errorDefault(context); return false; } - - // 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); - if (itemFound) { - if (response.jsonBody['locais'] - .any((local) => local['CLU_STATUS'] == "A")) { - return true; - } + List locals = response.jsonBody['locais'] ?? []; + if (locals != null && locals.isEmpty) { + await toggleApp(context, false); + return false; + } else if (locals.where((local) => local['CLU_STATUS'] != 'A').isNotEmpty) { await showModalBottomSheet( isScrollControlled: true, backgroundColor: Colors.transparent, @@ -419,57 +413,9 @@ Future checkLocals({ child: const BottomArrowLinkedLocalsComponentWidget(), ), ); // Chamada oti - return false; - } else { - return false; } -======= - do { - // A chamada para a API permanece a mesma, assumindo que é necessária sempre. - final response = await PhpGroup.getLocalsCall.call( - devUUID: AppState().devUUID, - userUUID: AppState().userUUID, - ); - - // Verificação rápida de erro para evitar processamento desnecessário. - if (response.jsonBody['error']) { - return false; - } - - // Uso eficiente de coleções para verificar a condição desejada. - final String uuid = cliUUID ?? AppState().cliUUID; - itemFound = response.jsonBody['locais'].any( - (local) => local['CLI_ID'] == uuid && local['CLU_STATUS'] == "A", - ); - - // Log e retorno condicional baseado no resultado da busca. - if (itemFound) { - return true; - } else { - // A chamada para showModalBottomSheet permanece, mas a atualização da UI é otimizada. - modalResult = 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(), - ), - ), - ); - safeSetState( - () {}); // Chamada otimizada fora do then para evitar encadeamentos desnecessários. - } - } while (modalResult != true); - - return false; ->>>>>>> main + await toggleApp(context, true); + return true; } Future answersRequest(BuildContext context, String? ref, String? task, diff --git a/lib/app_state.dart b/lib/app_state.dart index 5db6acee..3c6f0587 100644 --- a/lib/app_state.dart +++ b/lib/app_state.dart @@ -159,6 +159,9 @@ class AppState extends ChangeNotifier { await _safeInitAsync(() async { _whatsapp = await secureStorage.getBool('whatsapp') ?? _whatsapp; }); + await _safeInitAsync(() async { + _haveLocal = await secureStorage.getBool('ff_have_local') ?? _haveLocal; + }); } void update(VoidCallback callback) { @@ -412,7 +415,7 @@ class AppState extends ChangeNotifier { bool get haveLocal => _haveLocal; set haveLocal(bool value) { _haveLocal = value; - secureStorage.setBool('ff_local', value); + secureStorage.setBool('ff_have_local', value); } void deleteIsLogged() { diff --git a/lib/flutter_flow/nav/nav.dart b/lib/flutter_flow/nav/nav.dart index 53dd29fa..74dacafd 100644 --- a/lib/flutter_flow/nav/nav.dart +++ b/lib/flutter_flow/nav/nav.dart @@ -4,12 +4,8 @@ import 'package:flutter/material.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/pages/fast_pass_page/fast_pass_page_widget.dart'; import 'package:hub/pages/message_history_page/message_history_page_widget.dart'; -<<<<<<< HEAD import 'package:hub/pages/preferences_settings_page/preferences_settings_widget.dart'; import 'package:hub/pages/reception_page/reception_page_widget.dart'; -======= -import 'package:hub/pages/no_connection_page/no_connection_page.dart'; ->>>>>>> main import 'package:provider/provider.dart'; import '/backend/schema/structs/index.dart'; @@ -85,21 +81,9 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) => GoRouter( params.isEmpty ? const HomePageWidget() : const HomePageWidget(), ), FFRoute( -<<<<<<< HEAD name: 'receptionPage', path: '/receptionPage', builder: (context, params) => const ReceptionPageWidget()), -======= - name: 'no-connection', - path: '/no-connection', - builder: (context, params) => const NoConnectionScreen(), - ), - // FFRoute( - // name: 'visitHistoryPage', - // path: '/visitHistoryPage', - // builder: (context, params) => const VisitHistoryPageWidget(), - // ), ->>>>>>> main FFRoute( name: 'messageHistoryPage', path: '/messageHistoryPage', diff --git a/lib/pages/home_page/home_page_widget.dart b/lib/pages/home_page/home_page_widget.dart index ae78222d..fa31da21 100644 --- a/lib/pages/home_page/home_page_widget.dart +++ b/lib/pages/home_page/home_page_widget.dart @@ -28,7 +28,6 @@ class _HomePageWidgetState extends State { bool localStatus = false; final scaffoldKey = GlobalKey(); -<<<<<<< HEAD Future checkLocalStatus() async { localStatus = await checkLocals( context: context, @@ -36,8 +35,6 @@ class _HomePageWidgetState extends State { ); } -======= ->>>>>>> main @override void initState() { super.initState(); @@ -80,7 +77,6 @@ class _HomePageWidgetState extends State { localStatus = await checkLocals( context: context, model: _model, - safeSetState: safeSetState, ); if (AppState().cliUUID.isEmpty) { diff --git a/lib/pages/preferences_settings_page/preferences_settings_widget.dart b/lib/pages/preferences_settings_page/preferences_settings_widget.dart index c9f228c4..180c1cc2 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_widget.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_widget.dart @@ -65,18 +65,7 @@ class PreferencesPageWidget extends StatelessWidget { Expanded( flex: 2, child: ListView.builder( -<<<<<<< HEAD itemCount: 7, // Assuming 4 items for simplicity -======= - // gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( - // crossAxisCount: 3, - // crossAxisSpacing: 12.0, - // mainAxisSpacing: 12.0, - // childAspectRatio: 1.0, - // mainAxisExtent: 100.0, - // ), - itemCount: 8, // Assuming 4 items for simplicity ->>>>>>> main padding: const EdgeInsets.symmetric(horizontal: 20.0), physics: const AlwaysScrollableScrollPhysics(), itemBuilder: (BuildContext context, int index) { diff --git a/pubspec.lock b/pubspec.lock index ab70e828..49fbc8b6 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -66,7 +66,7 @@ packages: source: hosted version: "2.0.3" bloc: - dependency: "direct main" + dependency: transitive description: name: bloc sha256: "106842ad6569f0b60297619e9e0b1885c2fb9bf84812935490e6c5275777804e"