migração flutter 2.2.1
This commit is contained in:
@@ -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");
|
||||
// });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user