90 lines
2.5 KiB
Dart
90 lines
2.5 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:decpisos/atualizarapp/atualizarapp.dart';
|
|
import 'package:decpisos/index/index.dart';
|
|
import 'package:decpisos/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");
|
|
});
|
|
}
|
|
|
|
}
|
|
|