run method
Bootstraps and launches the app.
Executes the following sequential phases:
- Core bindings — initialises Sentry, EasyLocalization, Firebase, and dotenv.
- Dependency injection — calls
configureDependenciesthen awaitsgetIt.allReady()to ensure all async singletons are ready. - Error handlers — routes FlutterError and PlatformDispatcher errors to AppLogger. Registered immediately after DI so AppLogger is ready and exceptions thrown during hydration are captured.
- Hydration & debug services — initialises HydratedBloc storage and starts debug tooling.
- System UI & launch — locks orientation to portrait and calls runApp.
This method must be awaited from main().
Implementation
Future<void> run() async {
// --- PHASE 1: Core Bindings & Configuration ---
// Must happen before dotenv (asset loading) and Sentry init.
debugPrint("===== ENV =====");
debugPrint(_environment.name);
debugPrint("===== ENV =====");
SentryWidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();
await Firebase.initializeApp();
await dotenv.load(fileName: _envFilePath);
await SentryFlutter.init(
(options) => options
..dsn = dotenv.env['sentry_dsn'] ?? ''
..environment = _environment.name
..sendDefaultPii = !_environment.isProduction
..enableAutoSessionTracking = true
..tracesSampler = (context) {
final name = context.transactionContext.name;
if (name.contains('startup') || name.contains('login')) return 1.0;
return _environment.isProduction ? 0.05 : 1.0;
}
..attachScreenshot = !_environment.isProduction
..privacy.maskAllText = _environment.isProduction
..privacy.maskAllImages = _environment.isProduction
..enableAutoPerformanceTracing = true
..anrEnabled = true
..attachThreads = true
..enableWatchdogTerminationTracking = true
..reportSilentFlutterErrors = true
..enableUserInteractionBreadcrumbs = true
..enableUserInteractionTracing = true
..maxRequestBodySize = _environment.isProduction ? MaxRequestBodySize.never : MaxRequestBodySize.small
..beforeSend = (event, hint) async {
event.request?.headers.removeWhere((key, _) => key.toLowerCase() == 'authorization');
return event;
},
appRunner: _runApp,
);
}