Initial commit for driver_tripz
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
import 'package:intl/date_symbol_data_local.dart';
|
||||
import 'package:sefer_driver/controller/functions/crud.dart';
|
||||
import 'package:sefer_driver/views/home/Captin/orderCaptin/order_request_page.dart';
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
@@ -15,6 +18,7 @@ import 'package:flutter/services.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';
|
||||
@@ -95,6 +99,16 @@ Future<void> backgroundMessageHandler(RemoteMessage message) async {
|
||||
}
|
||||
}
|
||||
|
||||
/// تهيئة Firebase بوعي لمنع تهيئة مكرّرة على أندرويد (isolates متعددة)
|
||||
Future<void> initFirebaseIfNeeded() async {
|
||||
if (Firebase.apps.isEmpty) {
|
||||
await Firebase.initializeApp(
|
||||
options: DefaultFirebaseOptions.currentPlatform);
|
||||
} else {
|
||||
Firebase.app();
|
||||
}
|
||||
}
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
void notificationTapBackground(NotificationResponse notificationResponse) {
|
||||
Log.print('Notification tapped in background!');
|
||||
@@ -122,21 +136,65 @@ Future<void> closeOverLay() async {
|
||||
}
|
||||
//--- Main Application ---
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
||||
void main() {
|
||||
runZonedGuarded(() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
await WakelockPlus.enable();
|
||||
await GetStorage.init();
|
||||
Stripe.publishableKey = AK.publishableKeyStripe;
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
]);
|
||||
await initFirebaseIfNeeded();
|
||||
await WakelockPlus.enable();
|
||||
await GetStorage.init();
|
||||
await initializeDateFormatting();
|
||||
|
||||
runApp(const MyApp());
|
||||
Stripe.publishableKey = AK.publishableKeyStripe;
|
||||
|
||||
await SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
]);
|
||||
|
||||
// سجل الهاندلر تبع رسائل الخلفية (لازم يكون Top-Level ومع @pragma)
|
||||
FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);
|
||||
|
||||
runApp(const MyApp());
|
||||
}, (error, stack) {
|
||||
// ==== START: ERROR FILTER ====
|
||||
final errorString = error.toString();
|
||||
|
||||
// اطبع كل شيء محلياً
|
||||
// (يمكنك استبدال print بـ Log.print إن رغبت)
|
||||
print("Caught Dart error: $error");
|
||||
print(stack);
|
||||
|
||||
// تجاهُل بعض الأخطاء المعروفة
|
||||
final isIgnoredError = errorString.contains('PERMISSION_DENIED') ||
|
||||
errorString.contains('FormatException') ||
|
||||
errorString.contains('Null check operator used on a null value');
|
||||
|
||||
if (!isIgnoredError) {
|
||||
// أرسل فقط ما ليس ضمن قائمة التجاهل
|
||||
CRUD.addError(error.toString(), stack.toString(), 'main');
|
||||
} else {
|
||||
print("Ignoring error and not sending to server: $errorString");
|
||||
}
|
||||
// ==== END: ERROR FILTER ====
|
||||
});
|
||||
}
|
||||
|
||||
// void main() async {
|
||||
// WidgetsFlutterBinding.ensureInitialized();
|
||||
// await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
||||
|
||||
// await WakelockPlus.enable();
|
||||
// await GetStorage.init();
|
||||
// Stripe.publishableKey = AK.publishableKeyStripe;
|
||||
// SystemChrome.setPreferredOrientations([
|
||||
// DeviceOrientation.portraitUp,
|
||||
// DeviceOrientation.portraitDown,
|
||||
// ]);
|
||||
|
||||
// runApp(const MyApp());
|
||||
// }
|
||||
|
||||
class MyApp extends StatefulWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
|
||||
@@ -172,7 +230,16 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
||||
FirebaseMessaging.onBackgroundMessage(backgroundMessageHandler);
|
||||
await FirebaseMessagesController().getToken();
|
||||
await NotificationController().initNotifications();
|
||||
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],
|
||||
"tone1",
|
||||
);
|
||||
// You can add your other initializations here
|
||||
// For example:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user