2024-05-08 05:03:49 -04:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import 'package:whispering_pages/api/server_provider.dart';
|
|
|
|
import 'package:whispering_pages/db/storage.dart';
|
2024-05-09 00:41:19 -04:00
|
|
|
import 'package:whispering_pages/router/router.dart';
|
2024-05-08 05:03:49 -04:00
|
|
|
import 'package:whispering_pages/settings/api_settings_provider.dart';
|
|
|
|
import 'package:whispering_pages/settings/app_settings_provider.dart';
|
|
|
|
import 'package:whispering_pages/theme/theme.dart';
|
|
|
|
|
|
|
|
void main() async {
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
|
|
|
// initialize the storage
|
|
|
|
await initStorage();
|
2024-05-09 23:23:50 -04:00
|
|
|
|
|
|
|
runApp(
|
|
|
|
const ProviderScope(
|
|
|
|
child: MyApp(),
|
2024-05-08 05:03:49 -04:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-05-10 17:49:47 -04:00
|
|
|
var routerConfig = const MyAppRouter().config;
|
2024-05-09 23:23:50 -04:00
|
|
|
|
2024-05-08 05:03:49 -04:00
|
|
|
class MyApp extends ConsumerWidget {
|
|
|
|
const MyApp({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
final servers = ref.watch(audiobookShelfServerProvider);
|
|
|
|
final apiSettings = ref.watch(apiSettingsProvider);
|
|
|
|
|
2024-05-10 17:49:47 -04:00
|
|
|
final needOnboarding = apiSettings.activeUser == null || servers.isEmpty;
|
2024-05-10 04:11:39 -04:00
|
|
|
|
2024-05-10 17:49:47 -04:00
|
|
|
if (needOnboarding) {
|
|
|
|
routerConfig.goNamed(Routes.onboarding.name);
|
|
|
|
}
|
2024-05-10 04:11:39 -04:00
|
|
|
|
2024-05-09 00:41:19 -04:00
|
|
|
return MaterialApp.router(
|
2024-05-11 04:06:25 -04:00
|
|
|
debugShowCheckedModeBanner: false,
|
2024-05-08 05:03:49 -04:00
|
|
|
theme: lightTheme,
|
|
|
|
darkTheme: darkTheme,
|
|
|
|
themeMode: ref.watch(appSettingsProvider).isDarkMode
|
|
|
|
? ThemeMode.dark
|
|
|
|
: ThemeMode.light,
|
2024-05-10 04:11:39 -04:00
|
|
|
routerConfig: routerConfig,
|
2024-05-08 05:03:49 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|