108 lines
3.7 KiB
Dart
108 lines
3.7 KiB
Dart
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import '../constants.dart';
|
|
import '../services/auth/auth_gate.dart';
|
|
import '../themes/theme_provider.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:firebase_core/firebase_core.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'firebase_options.dart';
|
|
import 'pages/conversations_page.dart';
|
|
import 'pages/liked_users_page.dart';
|
|
import 'pages/user_matching_page.dart';
|
|
import 'pages/user_profile_page.dart';
|
|
import 'services/swipe_stream_service.dart';
|
|
import 'settings/settings_provider.dart';
|
|
|
|
void main() async {
|
|
// Firebase stuff
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
await Firebase.initializeApp(
|
|
options: DefaultFirebaseOptions.currentPlatform,
|
|
);
|
|
|
|
// Init SharedPreferences
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final isDarkMode = prefs.getBool(Constants.prefKeyThemeDarkMode) ?? false;
|
|
final onlySameCountry = prefs.getBool(Constants.prefKeySameCountry) ?? false;
|
|
|
|
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
|
|
FlutterLocalNotificationsPlugin();
|
|
flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation<
|
|
AndroidFlutterLocalNotificationsPlugin>()?.requestNotificationsPermission();
|
|
const AndroidInitializationSettings initializationSettingsAndroid =
|
|
AndroidInitializationSettings('@mipmap/ic_launcher');
|
|
const InitializationSettings initializationSettings =
|
|
InitializationSettings(android: initializationSettingsAndroid);
|
|
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);
|
|
|
|
// Initialize the singleton instance with a dummy userId.
|
|
// The actual userId is set later in the HomePage.
|
|
SwipeStreamService()
|
|
.initialize('dummy_initial_user_id', flutterLocalNotificationsPlugin);
|
|
|
|
runApp(
|
|
MultiProvider(
|
|
providers: [
|
|
ChangeNotifierProvider(
|
|
create: (context) => ThemeProvider(initialIsDarkMode: isDarkMode)),
|
|
Provider<FlutterLocalNotificationsPlugin>.value(
|
|
value: flutterLocalNotificationsPlugin),
|
|
ChangeNotifierProvider(
|
|
create: (context) =>
|
|
SettingsProvider(showSameCountry: onlySameCountry),
|
|
),
|
|
],
|
|
child: const MyApp(),
|
|
),
|
|
);
|
|
}
|
|
|
|
// Global key for navigation
|
|
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
debugShowCheckedModeBanner: false,
|
|
title: Constants.appTitle,
|
|
theme: Provider.of<ThemeProvider>(context).themeData,
|
|
navigatorKey: navigatorKey,
|
|
home: const AuthGate(),
|
|
routes: {
|
|
'/discover': (context) => const UserMatchingPage(),
|
|
'/favorites': (context) => const LikedUsersPage(),
|
|
'/chats': (context) => ConversationsPage(),
|
|
'/profile': (context) => const UserProfilePage(),
|
|
},
|
|
);
|
|
}
|
|
}
|