2024-07-12 13:14:09 +02:00
|
|
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
2024-06-19 19:31:18 +02:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2024-05-15 13:35:01 +02:00
|
|
|
import '../constants.dart';
|
|
|
|
import '../services/auth/auth_gate.dart';
|
|
|
|
import '../themes/theme_provider.dart';
|
2024-04-29 14:36:25 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:firebase_core/firebase_core.dart';
|
2024-04-30 19:25:16 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2024-04-29 14:36:25 +02:00
|
|
|
import 'firebase_options.dart';
|
2024-06-07 16:58:29 +02:00
|
|
|
import 'pages/conversations_page.dart';
|
|
|
|
import 'pages/liked_users_page.dart';
|
|
|
|
import 'pages/user_matching_page.dart';
|
|
|
|
import 'pages/user_profile_page.dart';
|
2024-07-12 13:14:09 +02:00
|
|
|
import 'services/swipe_stream_service.dart';
|
2024-04-29 14:36:25 +02:00
|
|
|
|
|
|
|
void main() async {
|
|
|
|
// Firebase stuff
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
await Firebase.initializeApp(
|
|
|
|
options: DefaultFirebaseOptions.currentPlatform,
|
|
|
|
);
|
2024-06-19 19:31:18 +02:00
|
|
|
|
|
|
|
// Init SharedPreferences
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
final isDarkMode = prefs.getBool(Constants.prefKeyThemeDarkMode) ?? false;
|
|
|
|
|
2024-07-12 13:14:09 +02:00
|
|
|
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
|
|
|
|
FlutterLocalNotificationsPlugin();
|
2024-07-12 15:08:41 +02:00
|
|
|
flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation<
|
|
|
|
AndroidFlutterLocalNotificationsPlugin>()?.requestNotificationsPermission();
|
2024-07-12 13:14:09 +02:00
|
|
|
const AndroidInitializationSettings initializationSettingsAndroid =
|
|
|
|
AndroidInitializationSettings('@mipmap/ic_launcher');
|
|
|
|
const InitializationSettings initializationSettings =
|
|
|
|
InitializationSettings(android: initializationSettingsAndroid);
|
2024-07-12 22:32:07 +02:00
|
|
|
await flutterLocalNotificationsPlugin.initialize(initializationSettings,
|
|
|
|
onDidReceiveNotificationResponse: (NotificationResponse response) {
|
|
|
|
// Handle the notification tap
|
|
|
|
if (response.payload != null) {
|
|
|
|
Navigator.push(
|
|
|
|
navigatorKey.currentState!.context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (BuildContext context) => UserProfilePage(
|
|
|
|
userId: response.payload,
|
|
|
|
titleText: 'Your new Match',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// create notification channel
|
|
|
|
const channel = AndroidNotificationChannel(
|
|
|
|
'new_match_info_channel_id',
|
|
|
|
'New Match Info Channel',
|
|
|
|
);
|
|
|
|
flutterLocalNotificationsPlugin
|
|
|
|
.resolvePlatformSpecificImplementation<
|
|
|
|
AndroidFlutterLocalNotificationsPlugin>()
|
|
|
|
?.createNotificationChannel(channel);
|
2024-07-12 13:14:09 +02:00
|
|
|
|
|
|
|
// Initialize the singleton instance with a dummy userId.
|
|
|
|
// The actual userId is set later in the HomePage.
|
|
|
|
SwipeStreamService()
|
|
|
|
.initialize('dummy_initial_user_id', flutterLocalNotificationsPlugin);
|
|
|
|
|
2024-04-30 19:25:16 +02:00
|
|
|
runApp(
|
2024-07-12 13:14:09 +02:00
|
|
|
MultiProvider(
|
|
|
|
providers: [
|
|
|
|
ChangeNotifierProvider(
|
|
|
|
create: (context) => ThemeProvider(initialIsDarkMode: isDarkMode)),
|
|
|
|
Provider<FlutterLocalNotificationsPlugin>.value(
|
|
|
|
value: flutterLocalNotificationsPlugin),
|
|
|
|
],
|
2024-04-30 19:25:16 +02:00
|
|
|
child: const MyApp(),
|
|
|
|
),
|
|
|
|
);
|
2024-04-29 14:36:25 +02:00
|
|
|
}
|
|
|
|
|
2024-07-12 13:14:09 +02:00
|
|
|
// Global key for navigation
|
|
|
|
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
|
|
|
|
2024-04-29 14:36:25 +02:00
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
const MyApp({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
|
|
|
debugShowCheckedModeBanner: false,
|
2024-05-05 10:26:49 +02:00
|
|
|
title: Constants.appTitle,
|
2024-04-30 19:25:16 +02:00
|
|
|
theme: Provider.of<ThemeProvider>(context).themeData,
|
2024-07-12 13:14:09 +02:00
|
|
|
navigatorKey: navigatorKey,
|
2024-04-29 14:36:25 +02:00
|
|
|
home: const AuthGate(),
|
2024-06-07 16:58:29 +02:00
|
|
|
routes: {
|
|
|
|
'/discover': (context) => const UserMatchingPage(),
|
|
|
|
'/favorites': (context) => const LikedUsersPage(),
|
|
|
|
'/chats': (context) => ConversationsPage(),
|
|
|
|
'/profile': (context) => const UserProfilePage(),
|
|
|
|
},
|
2024-04-29 14:36:25 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|