main function
Application execution starts here.
Implementation
void main() {
/// Run and handle an error zone to customise the action performed upon
/// an error or exception. This allows for error logging for debug purposes
/// as well as communicating errors to Crashlytics if enabled.
runZonedGuarded<Future<void>>(() async {
/// Necessary to initialise Flutter when running native code before
/// starting the application.
final binding = WidgetsFlutterBinding.ensureInitialized();
/// Initialise local file-based logging.
await FlutterLogs.initLogs(
logLevelsEnabled: [
LogLevel.INFO,
LogLevel.WARNING,
LogLevel.ERROR,
LogLevel.SEVERE
],
timeStampFormat: TimeStampFormat.DATE_FORMAT_1,
directoryStructure: DirectoryStructure.FOR_DATE,
logTypesEnabled: ['device', 'network', 'errors'],
logFileExtension: LogFileExtension.LOG,
);
/// Ensure no pop-in for the app icon.
binding.addPostFrameCallback((_) async {
final context = binding.rootElement;
if (context != null) {
precacheImage(const AssetImage('assets/meta/icon.png'), context);
}
});
/// Ensure the top and bottom bars are shown at launch and wake prevention
/// is disabled if not reverted from entering a media source.
Wakelock.disable();
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
/// Used in order to access and initialise an [AppModel] without requiring
/// a [WidgetRef].
final container = ProviderContainer();
final appModel = container.read(appProvider);
await appModel.initialise();
/// Start the application, specifying the [ProviderContainer] with the
/// already initialised [AppModel].
runApp(
UncontrolledProviderScope(
container: container,
child: const JidoujishoApp(),
),
);
}, (exception, stack) {
/// Printror details to the console.
final details = FlutterErrorDetails(exception: exception, stack: stack);
/// Log the error.
FlutterLogs.logError('jidoujisho', 'Error', details.toString());
});
}