25-3/12/1
This commit is contained in:
241
lib/main.dart
241
lib/main.dart
@@ -25,7 +25,6 @@ import 'controller/firebase/local_notification.dart';
|
||||
import 'controller/functions/encrypt_decrypt.dart';
|
||||
import 'controller/functions/location_controller.dart';
|
||||
import 'controller/functions/secure_storage.dart';
|
||||
import 'controller/home/payment/captain_wallet_controller.dart';
|
||||
import 'controller/local/local_controller.dart';
|
||||
import 'controller/local/translations.dart';
|
||||
import 'controller/payment/paymob/paymob_wallet.dart';
|
||||
@@ -123,76 +122,92 @@ Future<void> closeOverLay() async {
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await WakelockPlus.enable();
|
||||
|
||||
await GetStorage.init();
|
||||
|
||||
final AppInitializer initializer = AppInitializer();
|
||||
|
||||
await initializer.initializeApp();
|
||||
await Future.delayed(Duration.zero);
|
||||
await EncryptionHelper.initialize();
|
||||
|
||||
Stripe.publishableKey = AK.publishableKeyStripe;
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
]);
|
||||
|
||||
PermissionStatus status1 = await Permission.location.status;
|
||||
// if (status1.isGranted) {
|
||||
await LocationController().startLocationUpdates();
|
||||
// }
|
||||
|
||||
if (Platform.isAndroid || Platform.isIOS) {
|
||||
NotificationController notificationController =
|
||||
Get.put(NotificationController());
|
||||
await Firebase.initializeApp(
|
||||
options: DefaultFirebaseOptions.currentPlatform,
|
||||
);
|
||||
await FirebaseMessagesController().requestFirebaseMessagingPermission();
|
||||
|
||||
FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);
|
||||
|
||||
await notificationController.initNotifications();
|
||||
|
||||
// Generate a random index to pick a message
|
||||
final random = Random();
|
||||
final randomMessage = driverMessages[random.nextInt(driverMessages.length)];
|
||||
|
||||
// Schedule the notification with the random message
|
||||
notificationController.scheduleNotificationsForSevenDays(
|
||||
randomMessage.split(':')[0],
|
||||
randomMessage.split(':')[1],
|
||||
"ding",
|
||||
);
|
||||
|
||||
await Future.wait([
|
||||
FirebaseMessagesController().getNotificationSettings(),
|
||||
FirebaseMessagesController().getToken(),
|
||||
]);
|
||||
// await FacebookAuth.instance.init();
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
]);
|
||||
}
|
||||
|
||||
String? key = (await storage.read(key: BoxName.payMobApikey));
|
||||
|
||||
String? apiKey = EncryptionHelper.instance.decryptData(key!);
|
||||
PaymobPayment.instance.initialize(
|
||||
apiKey: apiKey,
|
||||
integrationID: int.parse(AK.integrationIdPayMob),
|
||||
userTokenExpiration: 200,
|
||||
iFrameID: 837992,
|
||||
);
|
||||
|
||||
PaymobPaymentWallet.instance.initialize(
|
||||
apiKey: apiKey,
|
||||
integrationID: int.parse(AK.integrationIdPayMobWallet),
|
||||
userTokenExpiration: 200,
|
||||
iFrameID: 837992,
|
||||
);
|
||||
runApp(MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
class MyApp extends StatefulWidget {
|
||||
@override
|
||||
_MyAppState createState() => _MyAppState();
|
||||
}
|
||||
|
||||
class _MyAppState extends State<MyApp> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_initApp();
|
||||
}
|
||||
|
||||
Future<void> _initApp() async {
|
||||
try {
|
||||
await Firebase.initializeApp(
|
||||
options: DefaultFirebaseOptions.currentPlatform);
|
||||
final AppInitializer initializer = AppInitializer();
|
||||
await initializer.initializeApp();
|
||||
await EncryptionHelper.initialize();
|
||||
|
||||
if (Platform.isAndroid || Platform.isIOS) {
|
||||
Get.put(
|
||||
NotificationController()); // Initialize NotificationController here
|
||||
await FirebaseMessaging.instance.requestPermission();
|
||||
FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);
|
||||
await NotificationController().initNotifications();
|
||||
|
||||
// Generate a random index to pick a message
|
||||
final random = Random();
|
||||
final randomMessage =
|
||||
driverMessages[random.nextInt(driverMessages.length)];
|
||||
// Schedule the notification with the random message
|
||||
NotificationController().scheduleNotificationsForSevenDays(
|
||||
randomMessage.split(':')[0],
|
||||
randomMessage.split(':')[1],
|
||||
"ding",
|
||||
);
|
||||
|
||||
await Future.wait([
|
||||
FirebaseMessagesController().getNotificationSettings(),
|
||||
FirebaseMessagesController().getToken(),
|
||||
]);
|
||||
|
||||
PermissionStatus status1 = await Permission.location.status;
|
||||
if (status1.isGranted) {
|
||||
await LocationController().startLocationUpdates();
|
||||
}
|
||||
}
|
||||
|
||||
String? key = (await storage.read(key: BoxName.payMobApikey));
|
||||
if (key != null) {
|
||||
String? apiKey = EncryptionHelper.instance.decryptData(key);
|
||||
if (apiKey != null) {
|
||||
PaymobPayment.instance.initialize(
|
||||
// Use .instance
|
||||
apiKey: apiKey,
|
||||
integrationID: int.parse(AK.integrationIdPayMob),
|
||||
userTokenExpiration: 200,
|
||||
iFrameID: 837992,
|
||||
);
|
||||
|
||||
PaymobPaymentWallet.instance.initialize(
|
||||
// Use .instance
|
||||
apiKey: apiKey,
|
||||
integrationID: int.parse(AK.integrationIdPayMobWallet),
|
||||
userTokenExpiration: 200,
|
||||
iFrameID: 837992,
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print("Error initializing app: $e");
|
||||
// Handle initialization errors appropriately. Maybe show an error message to the user.
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
LocaleController localController = Get.put(LocaleController());
|
||||
@@ -215,3 +230,99 @@ class MyApp extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// void main() async {
|
||||
// WidgetsFlutterBinding.ensureInitialized();
|
||||
// await WakelockPlus.enable();
|
||||
//
|
||||
// await GetStorage.init();
|
||||
//
|
||||
// final AppInitializer initializer = AppInitializer();
|
||||
//
|
||||
// await initializer.initializeApp();
|
||||
// await Future.delayed(Duration.zero);
|
||||
// await EncryptionHelper.initialize();
|
||||
//
|
||||
// Stripe.publishableKey = AK.publishableKeyStripe;
|
||||
//
|
||||
// PermissionStatus status1 = await Permission.location.status;
|
||||
// // if (status1.isGranted) {
|
||||
// await LocationController().startLocationUpdates();
|
||||
// // }
|
||||
//
|
||||
// if (Platform.isAndroid || Platform.isIOS) {
|
||||
// NotificationController notificationController =
|
||||
// Get.put(NotificationController());
|
||||
// await Firebase.initializeApp(
|
||||
// options: DefaultFirebaseOptions.currentPlatform,
|
||||
// );
|
||||
// await FirebaseMessagesController().requestFirebaseMessagingPermission();
|
||||
//
|
||||
// FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);
|
||||
//
|
||||
// await notificationController.initNotifications();
|
||||
//
|
||||
// // Generate a random index to pick a message
|
||||
// final random = Random();
|
||||
// final randomMessage = driverMessages[random.nextInt(driverMessages.length)];
|
||||
//
|
||||
// // Schedule the notification with the random message
|
||||
// notificationController.scheduleNotificationsForSevenDays(
|
||||
// randomMessage.split(':')[0],
|
||||
// randomMessage.split(':')[1],
|
||||
// "ding",
|
||||
// );
|
||||
//
|
||||
// await Future.wait([
|
||||
// FirebaseMessagesController().getNotificationSettings(),
|
||||
// FirebaseMessagesController().getToken(),
|
||||
// ]);
|
||||
// // await FacebookAuth.instance.init();
|
||||
// SystemChrome.setPreferredOrientations([
|
||||
// DeviceOrientation.portraitUp,
|
||||
// DeviceOrientation.portraitDown,
|
||||
// ]);
|
||||
// }
|
||||
//
|
||||
// String? key = (await storage.read(key: BoxName.payMobApikey));
|
||||
//
|
||||
// String? apiKey = EncryptionHelper.instance.decryptData(key!);
|
||||
// PaymobPayment.instance.initialize(
|
||||
// apiKey: apiKey,
|
||||
// integrationID: int.parse(AK.integrationIdPayMob),
|
||||
// userTokenExpiration: 200,
|
||||
// iFrameID: 837992,
|
||||
// );
|
||||
//
|
||||
// PaymobPaymentWallet.instance.initialize(
|
||||
// apiKey: apiKey,
|
||||
// integrationID: int.parse(AK.integrationIdPayMobWallet),
|
||||
// userTokenExpiration: 200,
|
||||
// iFrameID: 837992,
|
||||
// );
|
||||
// runApp(MyApp());
|
||||
// }
|
||||
//
|
||||
// class MyApp extends StatelessWidget {
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// LocaleController localController = Get.put(LocaleController());
|
||||
// return GetMaterialApp(
|
||||
// navigatorKey: navigatorKey,
|
||||
// title: AppInformation.appName,
|
||||
// translations: MyTranslation(),
|
||||
// debugShowCheckedModeBanner: false,
|
||||
// locale: localController.language,
|
||||
// theme: localController.appTheme,
|
||||
// initialRoute: '/',
|
||||
// getPages: [
|
||||
// GetPage(name: '/', page: () => SplashScreen()),
|
||||
// GetPage(
|
||||
// name: '/order-page',
|
||||
// page: () => OrderRequestPage(),
|
||||
// arguments: box.read(BoxName.rideArguments),
|
||||
// ),
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user