diff --git a/lib/main.dart b/lib/main.dart index de4afdf..7bfd2ef 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -36,7 +36,7 @@ void main() async { await setupPushNotification(); await initMediaStorage(); - await initFCMService(); + initFCMService(); gCameras = await availableCameras(); diff --git a/lib/src/app.dart b/lib/src/app.dart index e091031..9f657b3 100644 --- a/lib/src/app.dart +++ b/lib/src/app.dart @@ -152,10 +152,12 @@ class _MyAppState extends State with WidgetsBindingObserver { const InputDecorationTheme(border: OutlineInputBorder())), darkTheme: ThemeData.dark().copyWith( colorScheme: ColorScheme.fromSeed( - brightness: Brightness.dark, // <-- the only line added - seedColor: const Color(0xFF57CC99)), - inputDecorationTheme: - const InputDecorationTheme(border: OutlineInputBorder()), + brightness: Brightness.dark, // <-- the only line added + seedColor: const Color(0xFF57CC99), + ), + inputDecorationTheme: const InputDecorationTheme( + border: OutlineInputBorder(), + ), ), themeMode: context.watch().themeMode, initialRoute: '/', @@ -184,9 +186,8 @@ class MyAppMainWidget extends StatefulWidget { } class _MyAppMainWidgetState extends State { - Future _isUserCreated = - isUserCreated(); // Assume this is a function that checks if the user is created - bool _showOnboarding = true; // Initial state for onboarding + Future _isUserCreated = isUserCreated(); + bool _showOnboarding = true; @override Widget build(BuildContext context) { diff --git a/lib/src/views/home_view.dart b/lib/src/views/home_view.dart index 4dfa5eb..0f872c7 100644 --- a/lib/src/views/home_view.dart +++ b/lib/src/views/home_view.dart @@ -1,7 +1,9 @@ +import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:pie_menu/pie_menu.dart'; import 'package:provider/provider.dart'; import 'package:twonly/src/providers/send_next_media_to.dart'; +import 'package:twonly/src/services/notification_service.dart'; import 'camera_to_share/camera_preview_view.dart'; import 'chats/chat_list_view.dart'; import 'package:flutter/material.dart'; @@ -34,10 +36,28 @@ class HomeViewState extends State { activePageIdx = index; }); }; + + selectNotificationStream.stream + .listen((NotificationResponse? response) async { + globalUpdateOfHomeViewPageIndex(1); + }); + initAsync(); + } + + Future initAsync() async { + var notificationAppLaunchDetails = + await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails(); + + if (notificationAppLaunchDetails != null) { + if (notificationAppLaunchDetails.didNotificationLaunchApp) { + globalUpdateOfHomeViewPageIndex(1); + } + } } @override void dispose() { + selectNotificationStream.close(); // disable globalCallbacks to the flutter tree globalUpdateOfHomeViewPageIndex = (a) {}; super.dispose();