[FIX] teste
parent
ccb82eb992
commit
f3989aa13a
@ -0,0 +1,4 @@
|
||||
# bottomsheet_component
|
||||
|
||||
Projeto flutter da plataforma
|
||||
|
@ -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,)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -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
|
@ -0,0 +1,4 @@
|
||||
# filled_button_components
|
||||
|
||||
Projeto flutter da plataforma
|
||||
|
@ -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<Bind> binds = [
|
||||
Bind.singleton((i) => SplashStore()),
|
||||
];
|
||||
|
||||
@override
|
||||
final List<ModularRoute> routes = [
|
||||
ChildRoute('/', child: (_, args) => const SplashPage()),
|
||||
];
|
||||
}
|
@ -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<SplashPage> {
|
||||
var store = Modular.get<SplashStore>();
|
||||
|
||||
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<AppStore>().credentialApp.isEmpty || Modular.get<AppStore>().credentialApp.isNotEmpty && Modular.get<AppStore>().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<AuthStore>().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: <Widget>[
|
||||
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());
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -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<bool> hasInternet = CoreUtils.verifyInternetConnection();
|
||||
|
||||
Future<void> loadData() async {
|
||||
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
||||
String version = packageInfo.version;
|
||||
if(Modular.get<AppStore>().credentialApp.isNotEmpty && Modular.get<AppStore>().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<void> _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<AppStore>()
|
||||
.credentialApp, page: countPage);
|
||||
totalPages = map['total_pages'];
|
||||
List<NeighborhoodAddressModel> result = map['results'];
|
||||
for (var model in result) {
|
||||
model.versionApp = version;
|
||||
await NeighborhoodAddressDAO.save(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _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<NeighborhoodModel> result = await NeighborhoodRepository.getNeighborhoods(Modular
|
||||
.get<AppStore>()
|
||||
.credentialApp);
|
||||
for (var model in result) {
|
||||
model.versionApp = version;
|
||||
await NeighborhoodDAO.save(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _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<CountryModel> result = await CountryRepository.getCountries(Modular
|
||||
.get<AppStore>()
|
||||
.credentialApp);
|
||||
for (var model in result) {
|
||||
model.versionApp = version;
|
||||
await CountryDAO.save(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> getCredentialApp() async {
|
||||
try {
|
||||
var response = await AuthRepository.getTokenByCredential().timeout(const Duration(seconds: 40));
|
||||
if(response != null) {
|
||||
Modular.get<AppStore>().setCredentialApp(response);
|
||||
}
|
||||
} catch (err){
|
||||
debugPrint(err.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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}
|
||||
''';
|
||||
}
|
||||
}
|
@ -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
|
Loading…
Reference in New Issue