import 'package:cidade_social/app/app_store.dart'; import 'package:cidade_social/app/modules/address/dao/country_dao.dart'; import 'package:cidade_social/app/modules/address/dao/neighborhood_dao.dart'; import 'package:cidade_social/app/modules/address/dao/neighborhoodaddress_dao.dart'; import 'package:cidade_social/app/modules/auth/auth_store.dart'; import 'package:cidade_social/app/modules/splash/splash_store.dart'; import 'package:cidade_social/app/shared/components/hollow_button_components.dart'; import 'package:cidade_social/app/shared/utils/constants.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:cidade_social/app/shared/components/bottomsheet_component.dart'; import 'package:cidade_social/app/shared/loading.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:flutter_modular/flutter_modular.dart'; class SplashPage extends StatefulWidget { const SplashPage({Key? key}) : super(key: key); @override _SplashPageState createState() => _SplashPageState(); } class _SplashPageState extends State { var store = Modular.get(); onDoneLoading() async { var neighborhoodAddressList = await NeighborhoodAddressDAO.getList(); var neighborhoodList = await NeighborhoodDAO.getList(); var countryList = await CountryDAO.getList(); if (neighborhoodList.isEmpty || neighborhoodAddressList.isEmpty || countryList.isEmpty) { debugPrint("## onDoneLoading sem dados no banco"); if(await store.hasInternet == false){ store.setInfo("Para abrir o app, precisamos carregar informações básicas para a coleta de dados offline. Por favor, conecte-se à internet e tente novamente."); }else if(Modular.get().credentialApp.isEmpty || Modular.get().credentialApp.isNotEmpty && Modular.get().credentialApp == 'FAIL'){ store.setInfo("Para abrir o app, precisamos carregar informações básicas para a coleta de dados offline. Por favor, tente novamente. [CA]"); store.setIsLoading(false); throw Exception("Credencial vazia, falha ou inválida."); }else{ store.setInfo("Para abrir o app, precisamos carregar informações básicas para a coleta de dados offline. Por favor, tente novamente."); } store.setIsLoading(false); } else { debugPrint("## onDoneLoading com dados no banco"); Modular.get().verifyLoginPasswordRecorded(); } } @override void initState() { store.getCredentialApp().then((value) { store.loadData().whenComplete(() => onDoneLoading()); }); super.initState(); } @override Widget build(BuildContext context) { SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(statusBarColor: Theme.of(context).highlightColor)); return Observer( name: "SplashPage Observer", builder: (_) { return Scaffold( bottomSheet: const BottomSheetComponent(isSplash: true), body: Container( height: MediaQuery.of(context).size.height, width: MediaQuery.of(context).size.width, color: Theme.of(context).highlightColor, child: Column( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Image.asset( "assets/icons/logo_cidade_social.png", color: Colors.white, ), Column( mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.max, children: [ Visibility( visible: store.isLoading, child: const LoadingComponent(), ), Visibility( visible: store.info.isNotEmpty, child: Padding( padding: const EdgeInsets.symmetric(horizontal: 10), child: Text( store.info, textScaleFactor: 1.0, textAlign: TextAlign.center, style: const TextStyle(color: Colors.white, fontSize: 15), ), ), ), Visibility( visible: !store.isLoading, child: Container( padding: const EdgeInsets.only(top: 6), width: MediaQuery.of(context).size.width * 0.55, child: HollowButtonComponent( label: "Tente novamente", onPressed: () { store.setIsLoading(true); store.setInfo(Constants.basicDataLoadingText); store.getCredentialApp().then((value) { store.loadData().whenComplete(() => onDoneLoading()); }); }, ), ), ), ], ), ], ), ), ); }, ); } }