main function
Main entry point for the Movie Star application.
Implementation
void main() async {
// This is the main entry point for the app. The [async] is required because
// we asynchronously [await] the window manager below. Often, `main()` will
// include only [runApp].
WidgetsFlutterBinding.ensureInitialized();
final prefs = await SharedPreferences.getInstance();
// Initialise cache settings service early.
await CacheSettingsService.instance.initialize();
// Initialise Hive for local movie caching.
await Hive.initFlutter();
// Register Hive type adapters.
Hive.registerAdapter(MovieAdapter());
// Globally remove [debugPrint] messages.
// debugPrint = (String? message, {int? wrapWidth}) {
// null;
// };
// Ensure Flutter bindings are initialized for async operations
WidgetsFlutterBinding.ensureInitialized();
if (isDesktop) {
await windowManager.ensureInitialized();
const windowOptions = WindowOptions(
// Set various desktop window options here.
// Setting [alwaysOnTop] here will ensure the app starts on top of other
// apps on the desktop so that it is visible (otherwise, with GNOME on
// Ubuntu the app is often lost below other windows on startup).
// We later turn it off as we don't want to force it always on top.
alwaysOnTop: true,
// The [title] is used for the window manager's window title.
title: 'Movie Star - Manage and share ratings through private PODs',
// Set minimum window size to prevent UI element overlap.
minimumSize: Size(500, 400),
);
// Once the window manager is ready we reconfigure it a little.
await windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.show();
await windowManager.focus();
await windowManager.setAlwaysOnTop(false);
});
}
// The runApp() function takes the given Widget and makes it the root of the
// widget tree.
runApp(
ProviderScope(
overrides: [sharedPreferencesProvider.overrideWithValue(prefs)],
child: const MovieStar(),
),
);
}