migração flutter 2.2.1

This commit is contained in:
Renan
2021-06-01 16:52:01 -03:00
parent c44fcdddea
commit dd6bbb650b
25 changed files with 568 additions and 469 deletions
+1 -1
View File
@@ -35,7 +35,7 @@ class SplashScreen extends StatelessWidget {
backgroundColor: Colors.blueGrey.shade800,
screenFunction: ()async{
await c.firebaseCloudMessagingListeners();
await c.verTutorial();
//await c.verTutorial();
var screen = await c.verUsuLogado();
return screen;
},
+44 -24
View File
@@ -13,8 +13,9 @@ import '../funcoes_gerais.dart';
class SplashController extends GetxController {
bool _tutorialOk = false;
FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
//bool _tutorialOk = false;
//FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
//FirebaseMessaging _firebaseMessaging = FirebaseMessaging.instance;
@override
void onInit() {
@@ -26,14 +27,14 @@ class SplashController extends GetxController {
super.onClose();
}
Future<void> verTutorial()async{
SharedPreferences prefs = await SharedPreferences.getInstance();
this._tutorialOk = prefs.getBool('tutorial') ?? false;
}
// 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){
if(resp.vOk!){
SharedPreferences prefs = await SharedPreferences.getInstance();
var token = prefs.getString('token_notif');
await FuncoesGerais.registraDevice(token);
@@ -48,28 +49,46 @@ class SplashController extends GetxController {
Future<void> firebaseCloudMessagingListeners() async{
try {
if (_firebaseMessaging == null) return;
//if (_firebaseMessaging == null) return;
if (Platform.isIOS) iOSPermission();
_firebaseMessaging.getToken().then((token) async {
// _firebaseMessaging.getToken().then((token) async {
// print(token);
// SharedPreferences prefs = await SharedPreferences.getInstance();
// await prefs.setString('token_notif', token);
// });
FirebaseMessaging.instance.getToken().then((token) async{
print(token);
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString('token_notif', token);
await prefs.setString('token_notif', token!);
});
_firebaseMessaging.configure(
onLaunch: this._onNotification,
onMessage: this._onNotification,
//onBackgroundMessage: this._onNotification,
onResume: this._onNotification
);
// _firebaseMessaging.configure(
// onLaunch: this._onNotification,
// onMessage: this._onNotification,
// //onBackgroundMessage: this._onNotification,
// onResume: this._onNotification
// );
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
print('Push onMessage');
Get.snackbar(message.notification!.title ?? 'Notificação', message.notification!.body ?? 'Nova notificação',
mainButton: TextButton(onPressed: () => this._onNotification(message), child: Text('Ver')),
backgroundColor: Colors.black.withOpacity(0.7),
colorText: Colors.white
);
//this._onNotification(message);
});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
print('A new onMessageOpenedApp event was published!');
print(message);
//Get.snackbar(message.notification!.title ?? 'Notificação', message.notification!.body ?? 'Nova notificação',mainButton: TextButton(onPressed: () => this._onNotification(message), child: Text('Ver')));
});
} on PlatformException catch (e) {
print(e.message);
}
}
Future<dynamic> _onNotification(Map<String, dynamic> message) async{
void _onNotification(RemoteMessage message){
Get.to(() => NotificacoesScreen());
//print(message);
//print(message['aps']['alert']['title']);
@@ -77,12 +96,13 @@ class SplashController extends GetxController {
}
void iOSPermission() {
_firebaseMessaging.requestNotificationPermissions(
IosNotificationSettings(sound: true, badge: true, alert: true));
_firebaseMessaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings) {
print("Settings registered: $settings");
});
FirebaseMessaging.instance.requestPermission();
// _firebaseMessaging.requestNotificationPermissions(
// IosNotificationSettings(sound: true, badge: true, alert: true));
// _firebaseMessaging.onIosSettingsRegistered
// .listen((IosNotificationSettings settings) {
// print("Settings registered: $settings");
// });
}
}