main function
Implementation
Future<void> main() async {
// ── Step 1: Ensure Flutter bindings ─────────────────────────────────────
WidgetsFlutterBinding.ensureInitialized();
// ── Step 2: Configure logger ─────────────────────────────────────────────
_setupLogging();
// ── Step 3: Firebase (optional) ─────────────────────────────────────────
// await Firebase.initializeApp(
// options: DefaultFirebaseOptions.currentPlatform,
// );
// ── Step 4: CrashReporter ────────────────────────────────────────────────
await CrashReporter.init(useCrashlytics: false /* set true when Firebase is configured */);
// ── Step 5: Analytics ────────────────────────────────────────────────────
await AnalyticsService.init(useFirebase: false /* set true when Firebase is configured */);
// ── Step 6: Flutter framework error hook ─────────────────────────────────
FlutterError.onError = CrashReporter.instance.onFlutterError;
// ── Step 7: Platform-specific orientation ────────────────────────────────
if (!kIsWeb) {
// Allow both orientations on mobile; desktop handles this automatically.
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
}
// ── Step 8: System UI style ───────────────────────────────────────────────
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.dark,
),
);
// ── Step 9: Log app start ─────────────────────────────────────────────────
await AnalyticsService.instance.logEvent(AnalyticsEvents.appOpened);
// ── Step 10: Run app inside error zone ───────────────────────────────────
await _runApp();
}