This commit is contained in:
Hamza-Ayed
2024-09-11 10:10:18 +03:00
parent 8a9d270672
commit 98ee34490c
13 changed files with 373 additions and 202 deletions

View File

@@ -36,9 +36,12 @@ final PaymobPayment paymobPayment = PaymobPayment();
final PaymobPaymentWallet paymobPaymentWallet = PaymobPaymentWallet();
DbSql sql = DbSql.instance;
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
@pragma('vm:entry-point')
Future<void> backgroundMessageHandler(RemoteMessage message) async {
await Firebase.initializeApp();
if (Platform.isAndroid) {
if (message.notification != null && message.notification!.title != null) {
if (message.notification?.title == 'Order' ||
@@ -47,7 +50,7 @@ Future<void> backgroundMessageHandler(RemoteMessage message) async {
Log.print('myListString: $myListString');
// Decode the JSON string to a list
var myList;
List<dynamic> myList;
try {
myList = jsonDecode(myListString) as List<dynamic>;
} catch (e) {
@@ -55,7 +58,7 @@ Future<void> backgroundMessageHandler(RemoteMessage message) async {
myList = [];
}
Future.delayed(const Duration(seconds: 1));
await Future.delayed(const Duration(seconds: 1));
NotificationController().showNotification(
message.notification!.title.toString(),
message.notification!.body.toString(),
@@ -67,6 +70,7 @@ Future<void> backgroundMessageHandler(RemoteMessage message) async {
if (isOverlayActive) {
await FlutterOverlayWindow.closeOverlay();
}
await FlutterOverlayWindow.showOverlay(
enableDrag: true,
flag: OverlayFlag.focusPointer,
@@ -78,8 +82,6 @@ Future<void> backgroundMessageHandler(RemoteMessage message) async {
);
await FlutterOverlayWindow.shareData(myList);
// Bubble().startBubbleHead(sendAppToBackground: true);
}
} else {
FirebaseMessagesController().fireBaseTitles(message);
@@ -87,8 +89,6 @@ Future<void> backgroundMessageHandler(RemoteMessage message) async {
}
}
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
@pragma('vm:entry-point')
void overlayMain() async {
WidgetsFlutterBinding.ensureInitialized();
@@ -105,21 +105,18 @@ void closeOverLay() {
void main() async {
WidgetsFlutterBinding.ensureInitialized();
WakelockPlus.enable();
// Request location permission first
await WakelockPlus.enable();
// Request location permission
PermissionStatus status = await Permission.location.request();
if (status.isDenied) {
WidgetsBinding.instance.addPostFrameCallback((_) {
getPermissionLocation();
});
// Handle the case when permission is denied
// You might want to show a dialog explaining why the permission is needed
return;
}
// Set up the overlay entry point
// FlutterOverlayWindow.overlayMain = overlayMain;
await LocationController().startLocationUpdates();
await LocationController().startLocationUpdates();
await GetStorage.init();
Stripe.publishableKey = AK.publishableKeyStripe;
@@ -131,12 +128,12 @@ void main() async {
FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);
NotificationController().initNotifications();
List<Future> initializationTasks = [
await Future.wait([
FirebaseMessagesController().getNotificationSettings(),
FirebaseMessagesController().getToken(),
];
]);
await Future.wait(initializationTasks);
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
@@ -160,8 +157,6 @@ void main() async {
}
class MyApp extends StatelessWidget {
MyApp({super.key});
@override
Widget build(BuildContext context) {
LocaleController localController = Get.put(LocaleController());
@@ -172,18 +167,14 @@ class MyApp extends StatelessWidget {
debugShowCheckedModeBanner: false,
locale: localController.language,
theme: localController.appTheme,
key: UniqueKey(),
initialRoute: '/',
// home: SplashScreen(),
routes: {
'/order': (context) => OrderRequestPage(),
},
getPages: [
GetPage(name: '/', page: () => SplashScreen()),
GetPage(
name: '/order-page',
page: () => OrderRequestPage(),
arguments: box.read(BoxName.rideArguments)),
name: '/order-page',
page: () => OrderRequestPage(),
arguments: box.read(BoxName.rideArguments),
),
],
);
}