Update main.dart with enhanced documentation
This commit is contained in:
parent
ae209066df
commit
29a0ab903a
1 changed files with 18 additions and 3 deletions
|
|
@ -18,32 +18,41 @@ import 'package:mangayomi/modules/more/settings/appearance/providers/theme_mode_
|
|||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:media_kit/media_kit.dart';
|
||||
|
||||
// Global instance of the Isar database.
|
||||
late Isar isar;
|
||||
|
||||
/// Overrides the default HTTP client to allow all certificates
|
||||
class MyHttpoverrides extends HttpOverrides {
|
||||
@override
|
||||
HttpClient createHttpClient(SecurityContext? context) {
|
||||
return super.createHttpClient(context)
|
||||
..badCertificateCallback =
|
||||
(X509Certificate cert, String host, int port) => true;
|
||||
..badCertificateCallback = (X509Certificate cert, String host, int port) => true;
|
||||
}
|
||||
}
|
||||
|
||||
/// Entry point of the application.
|
||||
void main(List<String> args) async {
|
||||
// Override the default HTTP client.
|
||||
HttpOverrides.global = MyHttpoverrides();
|
||||
// If running on desktop platforms and web view title bar widget is active, exit.
|
||||
if (Platform.isLinux || Platform.isWindows || Platform.isMacOS) {
|
||||
if (runWebViewTitleBarWidget(args)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure widget and media kits are initialized.
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
MediaKit.ensureInitialized();
|
||||
|
||||
// Initialize the Isar database.
|
||||
isar = await StorageProvider().initDB(null);
|
||||
await StorageProvider().requestPermission();
|
||||
|
||||
// Start the app.
|
||||
runApp(const ProviderScope(child: MyApp()));
|
||||
}
|
||||
|
||||
/// Initialize date formatting based on available locales.
|
||||
_iniDateFormatting() {
|
||||
initializeDateFormatting();
|
||||
final supportedLocales = DateFormat.allLocalesWithSymbols();
|
||||
|
|
@ -52,6 +61,8 @@ _iniDateFormatting() {
|
|||
}
|
||||
}
|
||||
|
||||
/// The main app widget. This is a `ConsumerStatefulWidget` which allows it to consume
|
||||
/// providers from the `flutter_riverpod` package.
|
||||
class MyApp extends ConsumerStatefulWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
|
|
@ -62,6 +73,7 @@ class MyApp extends ConsumerStatefulWidget {
|
|||
class _MyAppState extends ConsumerState<MyApp> {
|
||||
@override
|
||||
void initState() {
|
||||
// Initialize date formatting upon app start.
|
||||
_iniDateFormatting();
|
||||
super.initState();
|
||||
}
|
||||
|
|
@ -69,6 +81,8 @@ class _MyAppState extends ConsumerState<MyApp> {
|
|||
// This widget is the root of your application.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Retrieve theme settings, localization settings, and router from providers.
|
||||
// Define light and dark theme data.
|
||||
final isDarkTheme = ref.watch(themeModeStateProvider);
|
||||
final blendLevel = ref.watch(blendLevelStateProvider);
|
||||
final pureBlackDarkMode = ref.watch(pureBlackDarkModeStateProvider);
|
||||
|
|
@ -111,6 +125,7 @@ class _MyAppState extends ConsumerState<MyApp> {
|
|||
fontFamily: GoogleFonts.aBeeZee().fontFamily,
|
||||
);
|
||||
final router = ref.watch(routerProvider);
|
||||
// Return the main MaterialApp with router, themes, and localization settings.
|
||||
return MaterialApp.router(
|
||||
darkTheme: themeDark,
|
||||
themeMode: isDarkTheme ? ThemeMode.dark : ThemeMode.light,
|
||||
|
|
|
|||
Loading…
Reference in a new issue