Files
intaleq/lib/main.dart
Hamza-Ayed 7595be8067 25-09-22/1
2025-09-22 17:28:19 +03:00

198 lines
6.6 KiB
Dart

import 'dart:async';
import 'dart:io';
import 'dart:math';
import 'package:Intaleq/controller/functions/crud.dart';
import 'package:Intaleq/controller/payment/paymob/paymob_response.dart';
import 'package:Intaleq/views/home/HomePage/contact_us.dart';
import 'package:Intaleq/views/home/HomePage/share_app_page.dart';
import 'package:Intaleq/views/home/my_wallet/passenger_wallet.dart';
import 'package:Intaleq/views/home/profile/passenger_profile_page.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:flutter_stripe/flutter_stripe.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:flutter/services.dart';
import 'package:quick_actions/quick_actions.dart';
import 'package:wakelock_plus/wakelock_plus.dart';
import 'constant/api_key.dart';
import 'constant/info.dart';
import 'constant/notification.dart';
import 'controller/firebase/firbase_messge.dart';
import 'controller/firebase/local_notification.dart';
import 'controller/functions/encrypt_decrypt.dart';
import 'controller/functions/secure_storage.dart';
import 'controller/home/deep_link_controller.dart';
import 'controller/local/local_controller.dart';
import 'controller/local/translations.dart';
import 'controller/payment/paymob/paymob_wallet.dart';
import 'firebase_options.dart';
import 'models/db_sql.dart';
import 'splash_screen_page.dart';
final box = GetStorage();
final storage = FlutterSecureStorage();
// final PaymobPayment paymobPayment = PaymobPayment();
final PaymobPayment paymobPayment = PaymobPayment();
final PaymobPaymentWallet paymobPaymentWallet = PaymobPaymentWallet();
DbSql sql = DbSql.instance;
// EncryptionHelper encryptionHelper = EncryptionHelper.instance;
@pragma('vm:entry-point')
Future<void> backgroundMessageHandler(RemoteMessage message) async {
await Firebase.initializeApp();
FirebaseMessagesController().fireBaseTitles(message);
}
void main() async {
WidgetsFlutterBinding.ensureInitialized();
WakelockPlus.enable();
await GetStorage.init();
// --- إضافة جديدة: تهيئة وحدة التحكم في الروابط العميقة ---
Get.put(DeepLinkController(), permanent: true);
// ----------------------------------------------------
final AppInitializer initializer = AppInitializer();
await initializer.initializeApp();
await EncryptionHelper.initialize();
NotificationController notificationController =
Get.put(NotificationController());
Stripe.publishableKey = AK.publishableKey;
// if (box.read(BoxName.driverID) != null) {}
if (Platform.isAndroid || Platform.isIOS) {
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
await FirebaseMessagesController().requestFirebaseMessagingPermission();
FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);
List<Future> initializationTasks = [
FirebaseMessagesController().getNotificationSettings(),
FirebaseMessagesController().getToken(),
];
// cameras = await availableCameras();
await Future.wait(initializationTasks);
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
}
await notificationController.initNotifications();
// Generate a random index to pick a message
final random = Random();
final randomMessage = messages[random.nextInt(messages.length)];
// Schedule the notification with the random message
notificationController.scheduleNotificationsForSevenDays(
randomMessage.split(':')[0],
randomMessage.split(':')[1],
"tone1",
);
// final encryptionHelper = await EncryptionHelper.initialize();
final QuickActions quickActions = QuickActions();
quickActions.initialize((String shortcutType) {
// print('Activated shortcut: $shortcutType');
if (shortcutType == 'share_app') {
Get.toNamed('/shareApp');
} else if (shortcutType == 'wallet') {
Get.toNamed('/wallet');
} else if (shortcutType == 'profile') {
Get.toNamed('/profile');
} else if (shortcutType == 'contact_support') {
Get.toNamed('/contactSupport');
}
});
quickActions.setShortcutItems(<ShortcutItem>[
ShortcutItem(
type: 'share_app',
localizedTitle: 'Share App'.tr,
icon: 'icon_share',
),
ShortcutItem(
type: 'wallet',
localizedTitle: 'Wallet'.tr,
icon: 'icon_wallet',
),
ShortcutItem(
type: 'profile',
localizedTitle: 'Profile'.tr,
icon: 'icon_user',
),
ShortcutItem(
type: 'contact_support',
localizedTitle: 'Contact Support'.tr,
icon: 'icon_support',
),
]);
runZonedGuarded<Future<void>>(() async {
runApp(const MyApp());
}, (error, stack) {
// ==== START: ERROR FILTER ====
String errorString = error.toString();
// Print all errors to the local debug console for development
print("Caught Dart error: $error");
print(stack);
// We will check if the error contains keywords for errors we want to ignore.
// If it's one of them, we will NOT send it to the server.
bool isIgnoredError = errorString.contains('PERMISSION_DENIED') ||
errorString.contains('FormatException') ||
errorString.contains('Null check operator used on a null value');
if (!isIgnoredError) {
// Only send the error to the server if it's not in our ignore list.
CRUD.addError(error.toString(), stack.toString(), 'main');
} else {
print("Ignoring error and not sending to server: $errorString");
}
// ==== END: ERROR FILTER ====
});
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
LocaleController localController = Get.put(LocaleController());
return GetMaterialApp(
title: AppInformation.appName,
translations: MyTranslation(),
debugShowCheckedModeBanner: false,
locale: localController.language,
theme: localController.appTheme,
key: UniqueKey(),
// routes: {'/':const HomePage()},
// home: LoginCaptin());
initialRoute: '/',
getPages: [
GetPage(name: '/', page: () => SplashScreen()),
GetPage(name: '/shareApp', page: () => ShareAppPage()),
GetPage(name: '/wallet', page: () => PassengerWallet()),
GetPage(name: '/profile', page: () => PassengerProfilePage()),
GetPage(name: '/contactSupport', page: () => ContactUsPage()),
],
// home: SplashScreen()
);
}
}