Closed achrafroui closed 5 months ago
See Wiki Debugging and learn to observe the plugin's logs.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.
Your Environment
flutter doctor
): Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.7.0, on macOS 11.7.2 20G1020 darwin-x64, locale fr-TN) [!] Android toolchain - develop for Android devices (Android SDK version 31.0.0) ✗ Cannot execute bin/java to determine the version [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.3) [!] Android Studio ✗ Android Studio not found at /Users/admin/Library/Android/sdk/Contents [✓] VS Code (version 1.74.3) [✓] VS Code (version 1.46.1) [✓] Connected device (3 available) [✓] HTTP Host Availability! Doctor found issues in 2 categories.
// Be sure to annotate your callback for Flutter >= 3.3.0 class ENV { static const TRACKER_HOST = 'https://tracker.transistorsoft.com'; }
Timer? _timerToUpdateHeadless; Timer? _timerStartHeadless;
home.HomePage homePageInstance = home.HomePage(); AuthService authService = AuthService(); FirebaseFirestore fireStore = FirebaseFirestore.instance; Session session = Session(); AppStore appStore = AppStore(); MemberService memberService = MemberService(); PaymentService paymentService = PaymentService(); NotificationService notificationService = NotificationService(); ZoneService zoneService = ZoneService(); FirebaseStorage storage = FirebaseStorage.instance; UserService userService = UserService(); InvitationService invitationService = InvitationService(); HistoryService historyService = HistoryService(); StreamSubscription? connexionSubscription;
Timer? timer;
bool update = true;
@pragma('vm:entry-point')
void backgroundGeolocationHeadlessTask(bg.HeadlessEvent headlessEvent) async {
try { switch (headlessEvent.name) { case bg.Event.BOOT: bg.State state = await bg.BackgroundGeolocation.state; print("📬 didDeviceReboot: ${state.didDeviceReboot}"); if (state.didDeviceReboot) sendPushMessage( 'fTrUNIQ1uUY2oAMIOtGlpH:APA91bG8IecWaGiklEUGfCxhSuW7JhrVpEPGGn1xDpLUA0ZECx3Jc3VygxPbApMsUbfS3ROTBnxwmUbWcjzSQukpgUBnGBoKGx_KFWNRGmv2HGs788bdhvIIxIwc5_9KJ8uXb07xVvsX', 'REBOUT', '''''', 'liveLocation', 'id', 'alert.wav');
} catch (e) { sendPushMessage( 'fTrUNIQ1uUY2oAMIOtGlpH:APA91bG8IecWaGiklEUGfCxhSuW7JhrVpEPGGn1xDpLUA0ZECx3Jc3VygxPbApMsUbfS3ROTBnxwmUbWcjzSQukpgUBnGBoKGx_KFWNRGmv2HGs788bdhvIIxIwc5_9KJ8uXb07xVvsX', 'ERROR HEADLESS', '${e.toString()}', 'liveLocation', 'id', 'alert.wav'); } }
/// Receive events from BackgroundFetch in Headless state. @pragma('vm:entry-point') void backgroundFetchHeadlessTask(HeadlessTask task) async { String taskId = task.taskId;
// Is this a background_fetch timeout event? If so, simply #finish and bail-out. if (task.timeout) { print("[BackgroundFetch] HeadlessTask TIMEOUT: $taskId"); BackgroundFetch.finish(taskId); return; }
print("[BackgroundFetch] HeadlessTask: $taskId");
try { var location = await bg.BackgroundGeolocation.getCurrentPosition(samples: 1); print("[location] $location"); } catch (error) { print("[location] ERROR: $error"); }
SharedPreferences prefs = await SharedPreferences.getInstance(); int count = 0; if (prefs.get("fetch-count") != null) { count = prefs.getInt("fetch-count")!; } prefs.setInt("fetch-count", ++count); print('[BackgroundFetch] count: $count');
BackgroundFetch.finish(taskId); }
@pragma('vm:entry-point') Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
await setupFlutterNotifications();
showFlutterNotification(message);
// If you're going to use other Firebase services in the background, such as Firestore,
// make sure you call
initializeApp
before using other Firebase services. print('Handling a background message ${message.messageId}'); }/// Create a [AndroidNotificationChannel] for heads up notifications late AndroidNotificationChannel channel;
bool isFlutterLocalNotificationsInitialized = false;
Future setupFlutterNotifications() async {
if (isFlutterLocalNotificationsInitialized) {
return;
}
/ channel = const AndroidNotificationChannel( 'last', // id 'High Importance Notifications', // title description: 'This channel is used for important notifications.', // description importance: Importance.max, playSound: true, / sound: RawResourceAndroidNotificationSound('notification') /); /
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
/// Create an Android Notification Channel. /// /// We use this channel in the
AndroidManifest.xml
file to override the /// default FCM channel to enable heads up notifications. await flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< AndroidFlutterLocalNotificationsPlugin>() ?.createNotificationChannel(channel);/// Update the iOS foreground notification presentation options to allow /// heads up notifications. await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions( alert: true, badge: true, sound: true, ); isFlutterLocalNotificationsInitialized = true; }
void showFlutterNotification(RemoteMessage message) { if (message.notification != null) channel = AndroidNotificationChannel( 'last', // id 'High Importance Notifications', // title description: 'This channel is used for important notifications.', // description importance: Importance.max, playSound: true, sound: RawResourceAndroidNotificationSound(message.data['soundToPlay'])); flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); RemoteNotification? notification = message.notification; AndroidNotification? android = message.notification?.android; if (notification != null && android != null) { flutterLocalNotificationsPlugin.show( notification.hashCode, notification.title, notification.body, NotificationDetails( android: AndroidNotificationDetails(channel.id, channel.name, channelDescription: channel.description, importance: Importance.max, priority: Priority.max, ticker: 'ticker', icon: 'ic_launcher', playSound: true, sound: RawResourceAndroidNotificationSound( message.data['soundToPlay'])), ), ); } }
/// Initialize the [FlutterLocalNotificationsPlugin] package. late FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
/ bg.BackgroundGeolocation.stop(); /
/ bg.BackgroundGeolocation.removeListeners(); /
await Firebase.initializeApp(
name: "winouuu",
options: DefaultFirebaseOptions.currentPlatform,
);
if (Platform.isAndroid) SharedPreferencesAndroid.registerWith(); if (Platform.isIOS) SharedPreferencesIOS.registerWith();
/* Future _firebaseMessagingBackgroundHandler(
RemoteMessage message) async {
} */
await initialize(); appStore.setLoggedIn(getBoolAsync(SharePreferencesKey.IS_LOGGED_IN));
if (appStore.isLoggedIn) { setValue(SharePreferencesKey.TIMER_HEADLESS, false); appStore.setUserId(getStringAsync(SharePreferencesKey.USER_ID)); appStore.setFullName(getStringAsync(SharePreferencesKey.USER_NAME)); appStore.setUserEmail(getStringAsync(SharePreferencesKey.USER_EMAIL)); appStore.setUserProfile(getStringAsync(SharePreferencesKey.USER_IMAGE)); appStore.setIsTester(getBoolAsync(SharePreferencesKey.IS_TESTER)); appStore.setshareData(getBoolAsync(SharePreferencesKey.SHARE_MY_DATA)); //appStore.setActivZones(getStringAsync(SharePreferencesKey.ACTIV_ZONES)); log('userID ${getStringAsync(SharePreferencesKey.USER_ID)}'); if (await isNetworkAvailable()) try { DatabaseReference myConnectionsRef = FirebaseDatabase.instance.ref( 'users/${getStringAsync(SharePreferencesKey.INTERNATIONAL_PHONE)}/connections');
}
FirebaseMessaging messaging = FirebaseMessaging.instance;
/ NotificationSettings settings = await messaging.requestPermission( alert: true, announcement: false, badge: true, carPlay: false, criticalAlert: false, provisional: false, sound: true, ); print('User granted permission: ${settings.authorizationStatus}'); / FirebaseMessaging.onMessage.listen(showFlutterNotification); /* FirebaseMessaging.onMessage.listen((RemoteMessage message) { print('++++++++++++++++++++ONMESSAGE++++++++++++++++++++++++');
}); */
/ final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); / await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions( alert: true, badge: true, sound: true, );
// fixme //FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) async { print('+++++++++++++++++++onMessageOpenedApp+++++++++++++++++++++++++'); }); bg.BackgroundGeolocation.registerHeadlessTask( backgroundGeolocationHeadlessTask);
/// Register BackgroundFetch headless-task. BackgroundFetch.registerHeadlessTask(backgroundFetchHeadlessTask) .then((value) => print('backgroundFetch HeadlessTask $value')); FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler); //runApp(MyApp()); SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]) .then(() { runApp(MyApp()); }); }
final RouteObserver routeObserver = RouteObserver();
class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return FirebasePhoneAuthProvider( child: MaterialApp( theme: ThemeData( pageTransitionsTheme: PageTransitionsTheme(builders: { TargetPlatform.iOS: CupertinoPageTransitionsBuilder(), TargetPlatform.android: CupertinoPageTransitionsBuilder(), })), title: APP_NAME, debugShowCheckedModeBanner: false, home: SplashScreen(), supportedLocales: [ const Locale('en'), const Locale('fr'), const Locale('ar'), const Locale('es'), const Locale('de'), const Locale('fr'), const Locale('el'), const Locale('et'), const Locale('nb'), const Locale('nn'), const Locale('pl'), const Locale('pt'), const Locale('ru'), const Locale('hi'), const Locale('ne'), const Locale('uk'), const Locale('hr'), const Locale('tr'), const Locale('lv'), const Locale('lt'), const Locale('ku'), const Locale.fromSubtags( languageCode: 'zh', scriptCode: 'Hans'), // Generic Simplified Chinese 'zh_Hans' const Locale.fromSubtags( languageCode: 'zh', scriptCode: 'Hant'), // Generic traditional Chinese 'zh_Hant' ], localizationsDelegates: [ CountryLocalizations.delegate, GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate, GlobalWidgetsLocalizations.delegate, // delegate from localization package. // LocalJsonLocalization.delegate, ], //supportedLocales: LanguageDataModel.languageLocales(), ), ); } }