carga inicial
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import 'package:appcardsstarter/funcoes_gerais.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:animated_splash_screen/animated_splash_screen.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:page_transition/page_transition.dart';
|
||||
|
||||
import 'splash_controller.dart';
|
||||
class SplashScreen extends StatelessWidget {
|
||||
final SplashController c = Get.put(SplashController());
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedSplashScreen.withScreenFunction(
|
||||
splash: Container(
|
||||
width: double.maxFinite,
|
||||
height: Get.size.height,
|
||||
//color: Colors.red,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
child: Container(width: 120.0,height: 120.0,child: Image.asset('assets/images/logo.png',fit: BoxFit.contain,))
|
||||
),
|
||||
SizedBox(height: 10.0,),
|
||||
Text(FuncoesGerais.nomeApp,style: TextStyle(color: Colors.green.shade600,fontSize: 22.0),),
|
||||
LinearProgressIndicator()
|
||||
],
|
||||
),
|
||||
),
|
||||
//splashIconSize: 90.0,
|
||||
splashIconSize: Get.size.height,
|
||||
splashTransition: SplashTransition.slideTransition,
|
||||
pageTransitionType: PageTransitionType.fade,
|
||||
backgroundColor: Colors.white,
|
||||
screenFunction: ()async{
|
||||
await c.firebaseCloudMessagingListeners();
|
||||
await c.verTutorial();
|
||||
var screen = await c.verUsuLogado();
|
||||
return screen;
|
||||
},
|
||||
//backgroundColor: Colors.blue
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:appcardsstarter/atualizarapp/atualizarapp.dart';
|
||||
import 'package:appcardsstarter/index/index.dart';
|
||||
import 'package:appcardsstarter/notificacoes/notificacoes.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../funcoes_gerais.dart';
|
||||
|
||||
class SplashController extends GetxController {
|
||||
|
||||
bool _tutorialOk = false;
|
||||
FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
Future<void> verTutorial()async{
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
this._tutorialOk = prefs.getBool('tutorial') ?? false;
|
||||
}
|
||||
|
||||
Future<Widget> verUsuLogado()async{
|
||||
var resp = await FuncoesGerais.checkVersaoMinimaOk();
|
||||
if(resp.vOk){
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
var token = prefs.getString('token_notif');
|
||||
await FuncoesGerais.registraDevice(token);
|
||||
return IndexScreen();
|
||||
}
|
||||
else{
|
||||
return AtualizarScreen(linkLoja: resp.linkLoja);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Future<void> firebaseCloudMessagingListeners() async{
|
||||
try {
|
||||
|
||||
if (_firebaseMessaging == null) return;
|
||||
|
||||
if (Platform.isIOS) iOSPermission();
|
||||
|
||||
_firebaseMessaging.getToken().then((token) async {
|
||||
print(token);
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('token_notif', token);
|
||||
});
|
||||
|
||||
_firebaseMessaging.configure(
|
||||
onLaunch: this._onNotification,
|
||||
onMessage: this._onNotification,
|
||||
//onBackgroundMessage: this._onNotification,
|
||||
onResume: this._onNotification
|
||||
);
|
||||
} on PlatformException catch (e) {
|
||||
print(e.message);
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> _onNotification(Map<String, dynamic> message) async{
|
||||
Get.to(() => NotificacoesScreen());
|
||||
//print(message);
|
||||
//print(message['aps']['alert']['title']);
|
||||
//Get.rawSnackbar(message: message['aps']['alert']['title']);
|
||||
}
|
||||
|
||||
void iOSPermission() {
|
||||
_firebaseMessaging.requestNotificationPermissions(
|
||||
IosNotificationSettings(sound: true, badge: true, alert: true));
|
||||
_firebaseMessaging.onIosSettingsRegistered
|
||||
.listen((IosNotificationSettings settings) {
|
||||
print("Settings registered: $settings");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user