diff --git a/bottomsheet_component/README.md b/bottomsheet_component/README.md new file mode 100644 index 0000000..a71691d --- /dev/null +++ b/bottomsheet_component/README.md @@ -0,0 +1,4 @@ +# bottomsheet_component + +Projeto flutter da plataforma + diff --git a/bottomsheet_component/lib/bottomsheet_component.dart b/bottomsheet_component/lib/bottomsheet_component.dart new file mode 100644 index 0000000..8e1d1fc --- /dev/null +++ b/bottomsheet_component/lib/bottomsheet_component.dart @@ -0,0 +1,32 @@ +import 'package:flutter/material.dart'; + +class BottomSheetComponent extends StatelessWidget { + final bool isSplash; + const BottomSheetComponent({this.isSplash=false, Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return SafeArea( + child: Container( + decoration: BoxDecoration( + border: Border.all(width: 0, color: isSplash ? Theme.of(context).highlightColor : Colors.white), + color: isSplash ? Theme.of(context).highlightColor : Colors.white, + ), + child: SizedBox( + height: 50, + width: MediaQuery.of(context).size.width, + child: Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Image.asset("assets/icons/logo_siabes.png", + width: 140, + color: isSplash ? Colors.white : Theme.of(context).primaryColor, + height: 33,) + ], + ), + ), + ), + ); + } +} diff --git a/bottomsheet_component/pubspec.yaml b/bottomsheet_component/pubspec.yaml new file mode 100644 index 0000000..735fd3a --- /dev/null +++ b/bottomsheet_component/pubspec.yaml @@ -0,0 +1,16 @@ +name: bottomsheet_component +description: Uma biblioteca Flutter personalizada +version: 1.0.0 + +environment: + sdk: ">=2.16.2 <3.0.0" + +authors: + - Kleber Cardoso +homepage: https://git.ae3tecnologia.com.br/Kleber-rr/components.git +dependencies: + flutter: + sdk: flutter + +flutter: + uses-material-design: true diff --git a/hollow_button_components/README.md b/hollow_button_component/README.md similarity index 100% rename from hollow_button_components/README.md rename to hollow_button_component/README.md diff --git a/hollow_button_components/lib/hollow_button_components.dart b/hollow_button_component/lib/hollow_button_components.dart similarity index 100% rename from hollow_button_components/lib/hollow_button_components.dart rename to hollow_button_component/lib/hollow_button_components.dart diff --git a/hollow_button_components/pubspec.yaml b/hollow_button_component/pubspec.yaml similarity index 100% rename from hollow_button_components/pubspec.yaml rename to hollow_button_component/pubspec.yaml diff --git a/splash_module/README.md b/splash_module/README.md new file mode 100644 index 0000000..2589e7b --- /dev/null +++ b/splash_module/README.md @@ -0,0 +1,4 @@ +# filled_button_components + +Projeto flutter da plataforma + diff --git a/splash_module/lib/splash_module.dart b/splash_module/lib/splash_module.dart new file mode 100644 index 0000000..f848826 --- /dev/null +++ b/splash_module/lib/splash_module.dart @@ -0,0 +1,15 @@ +import 'package:cidade_social/app/modules/splash/splash_page.dart'; +import 'package:cidade_social/app/modules/splash/splash_store.dart'; +import 'package:flutter_modular/flutter_modular.dart'; + +class SplashModule extends Module { + @override + final List binds = [ + Bind.singleton((i) => SplashStore()), + ]; + + @override + final List routes = [ + ChildRoute('/', child: (_, args) => const SplashPage()), + ]; +} diff --git a/splash_module/lib/splash_page.dart b/splash_module/lib/splash_page.dart new file mode 100644 index 0000000..b08f0a6 --- /dev/null +++ b/splash_module/lib/splash_page.dart @@ -0,0 +1,122 @@ +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()); + }); + }, + ), + ), + ), + ], + ), + ], + ), + ), + ); + }, + ); + } +} \ No newline at end of file diff --git a/splash_module/lib/splash_store.dart b/splash_module/lib/splash_store.dart new file mode 100644 index 0000000..a383fc8 --- /dev/null +++ b/splash_module/lib/splash_store.dart @@ -0,0 +1,121 @@ +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/address/model/country_model.dart'; +import 'package:cidade_social/app/modules/address/model/neighborhood_model.dart'; +import 'package:cidade_social/app/modules/address/model/neighborhoodaddress_model.dart'; +import 'package:cidade_social/app/modules/address/repository/country_respository.dart'; +import 'package:cidade_social/app/modules/address/repository/neighborhood_respository.dart'; +import 'package:cidade_social/app/modules/address/repository/neighborhoodaddress_respository.dart'; +import 'package:cidade_social/app/modules/auth/auth_respository.dart'; +import 'package:cidade_social/app/shared/utils/constants.dart'; +import 'package:cidade_social/app/shared/utils/core_utils.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter_modular/flutter_modular.dart'; +import 'package:mobx/mobx.dart'; +import 'package:package_info_plus/package_info_plus.dart'; + +part 'splash_store.g.dart'; + +class SplashStore = _SplashStoreBase with _$SplashStore; + +abstract class _SplashStoreBase with Store { + + @observable + String info = ""; + + @action + void setInfo(String value) => info = value; + + @observable + bool isLoading = true; + + @action + void setIsLoading(bool value) => isLoading = value; + + Future hasInternet = CoreUtils.verifyInternetConnection(); + + Future loadData() async { + PackageInfo packageInfo = await PackageInfo.fromPlatform(); + String version = packageInfo.version; + if(Modular.get().credentialApp.isNotEmpty && Modular.get().credentialApp != 'FAIL') { + debugPrint('## loadData started at ${CoreUtils.dateToString(DateTime.now(), 'HH:mm:ss')}'); + _getCountries(version); + _getNeighborhoods(version); + await _getNeighborhoodAddresses(version); + debugPrint('## loadData finished at ${CoreUtils.dateToString(DateTime.now(), 'HH:mm:ss')}'); + } + return; + } + + Future _getNeighborhoodAddresses(String version) async { + var neighborhoodAddressList = await NeighborhoodAddressDAO.getList(); + var neighborhoodAddressListOutdate = await NeighborhoodAddressDAO.getOutdated(version: version); + if (neighborhoodAddressList.isEmpty || neighborhoodAddressListOutdate.isNotEmpty) { + int? deletedCount = await NeighborhoodAddressDAO.deleteAll(); + debugPrint('deletedCount: ${deletedCount ?? 0}'); + int totalPages = 1; + int countPage = 0; + setInfo(Constants.basicDataLoadingText); + while(countPage < totalPages) { + countPage++; + var map = await NeighborhoodAddressRepository.getAllAddressByPagination(Modular + .get() + .credentialApp, page: countPage); + totalPages = map['total_pages']; + List result = map['results']; + for (var model in result) { + model.versionApp = version; + await NeighborhoodAddressDAO.save(model); + } + } + } + } + + Future _getNeighborhoods(String version) async { + var neighborhoodList = await NeighborhoodDAO.getList(); + var neighborhoodListOutdate = await NeighborhoodDAO.getOutdated(version: version); + if (neighborhoodList.isEmpty || neighborhoodListOutdate.isNotEmpty) { + int? deletedCount = await NeighborhoodDAO.deleteAll(); + debugPrint('deletedCount: ${deletedCount ?? 0}'); + setInfo(Constants.basicDataLoadingText); + List result = await NeighborhoodRepository.getNeighborhoods(Modular + .get() + .credentialApp); + for (var model in result) { + model.versionApp = version; + await NeighborhoodDAO.save(model); + } + } + } + + Future _getCountries(String version) async { + var countryList = await CountryDAO.getList(); + var countryListOutdate = await CountryDAO.getOutdated(version: version); + if (countryList.isEmpty || countryListOutdate.isNotEmpty) { + int? deletedCount = await CountryDAO.deleteAll(); + debugPrint('deletedCount: ${deletedCount ?? 0}'); + setInfo(Constants.basicDataLoadingText); + List result = await CountryRepository.getCountries(Modular + .get() + .credentialApp); + for (var model in result) { + model.versionApp = version; + await CountryDAO.save(model); + } + } + } + + Future getCredentialApp() async { + try { + var response = await AuthRepository.getTokenByCredential().timeout(const Duration(seconds: 40)); + if(response != null) { + Modular.get().setCredentialApp(response); + } + } catch (err){ + debugPrint(err.toString()); + } + } + +} \ No newline at end of file diff --git a/splash_module/lib/splash_store.g.dart b/splash_module/lib/splash_store.g.dart new file mode 100644 index 0000000..25dad3a --- /dev/null +++ b/splash_module/lib/splash_store.g.dart @@ -0,0 +1,75 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'splash_store.dart'; + +// ************************************************************************** +// StoreGenerator +// ************************************************************************** + +// ignore_for_file: non_constant_identifier_names, unnecessary_brace_in_string_interps, unnecessary_lambdas, prefer_expression_function_bodies, lines_longer_than_80_chars, avoid_as, avoid_annotating_with_dynamic, no_leading_underscores_for_local_identifiers + +mixin _$SplashStore on _SplashStoreBase, Store { + late final _$infoAtom = Atom(name: '_SplashStoreBase.info', context: context); + + @override + String get info { + _$infoAtom.reportRead(); + return super.info; + } + + @override + set info(String value) { + _$infoAtom.reportWrite(value, super.info, () { + super.info = value; + }); + } + + late final _$isLoadingAtom = + Atom(name: '_SplashStoreBase.isLoading', context: context); + + @override + bool get isLoading { + _$isLoadingAtom.reportRead(); + return super.isLoading; + } + + @override + set isLoading(bool value) { + _$isLoadingAtom.reportWrite(value, super.isLoading, () { + super.isLoading = value; + }); + } + + late final _$_SplashStoreBaseActionController = + ActionController(name: '_SplashStoreBase', context: context); + + @override + void setInfo(String value) { + final _$actionInfo = _$_SplashStoreBaseActionController.startAction( + name: '_SplashStoreBase.setInfo'); + try { + return super.setInfo(value); + } finally { + _$_SplashStoreBaseActionController.endAction(_$actionInfo); + } + } + + @override + void setIsLoading(bool value) { + final _$actionInfo = _$_SplashStoreBaseActionController.startAction( + name: '_SplashStoreBase.setIsLoading'); + try { + return super.setIsLoading(value); + } finally { + _$_SplashStoreBaseActionController.endAction(_$actionInfo); + } + } + + @override + String toString() { + return ''' +info: ${info}, +isLoading: ${isLoading} + '''; + } +} diff --git a/splash_module/pubspec.yaml b/splash_module/pubspec.yaml new file mode 100644 index 0000000..629534e --- /dev/null +++ b/splash_module/pubspec.yaml @@ -0,0 +1,16 @@ +name: filled_button_component +description: Uma biblioteca Flutter personalizada +version: 1.0.0 + +environment: + sdk: ">=2.16.2 <3.0.0" + +authors: + - Kleber Cardoso +homepage: https://git.ae3tecnologia.com.br/Kleber-rr/components.git +dependencies: + flutter: + sdk: flutter + +flutter: + uses-material-design: true