2024-05-25 18:09:39 +02:00
|
|
|
import 'package:fl_toast/fl_toast.dart';
|
2024-02-10 18:29:41 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2024-02-11 01:08:51 +01:00
|
|
|
import 'package:provider/provider.dart';
|
2024-05-25 18:09:39 +02:00
|
|
|
import 'package:hive_flutter/hive_flutter.dart';
|
2024-05-23 20:05:55 +02:00
|
|
|
import 'package:simplecloudnotifier/nav_layout.dart';
|
|
|
|
import 'package:simplecloudnotifier/state/app_theme.dart';
|
2024-05-25 18:09:39 +02:00
|
|
|
import 'package:simplecloudnotifier/state/application_log.dart';
|
|
|
|
import 'package:simplecloudnotifier/state/globals.dart';
|
|
|
|
import 'package:simplecloudnotifier/state/request_log.dart';
|
2024-05-23 20:05:55 +02:00
|
|
|
import 'package:simplecloudnotifier/state/user_account.dart';
|
|
|
|
|
|
|
|
void main() async {
|
2024-05-25 18:09:39 +02:00
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
|
|
|
await Hive.initFlutter();
|
|
|
|
await Globals().init();
|
|
|
|
|
|
|
|
Hive.registerAdapter(SCNRequestAdapter());
|
|
|
|
Hive.registerAdapter(SCNLogAdapter());
|
|
|
|
|
|
|
|
try {
|
|
|
|
await Hive.openBox<SCNRequest>('scn-requests');
|
|
|
|
await Hive.openBox<SCNLog>('scn-logs');
|
|
|
|
} catch (e) {
|
|
|
|
print(e);
|
|
|
|
Hive.deleteBoxFromDisk('scn-requests');
|
|
|
|
Hive.deleteBoxFromDisk('scn-logs');
|
|
|
|
await Hive.openBox<SCNRequest>('scn-requests');
|
|
|
|
await Hive.openBox<SCNLog>('scn-logs');
|
|
|
|
}
|
2024-02-10 19:57:17 +01:00
|
|
|
|
2024-02-11 01:08:51 +01:00
|
|
|
runApp(
|
|
|
|
MultiProvider(
|
|
|
|
providers: [
|
2024-05-21 23:20:34 +02:00
|
|
|
ChangeNotifierProvider(
|
|
|
|
create: (context) => UserAccount(),
|
|
|
|
lazy: false,
|
|
|
|
),
|
|
|
|
ChangeNotifierProvider(
|
|
|
|
create: (context) => AppTheme(),
|
|
|
|
lazy: false,
|
|
|
|
),
|
2024-02-11 01:08:51 +01:00
|
|
|
],
|
|
|
|
child: const SCNApp(),
|
|
|
|
),
|
|
|
|
);
|
2024-02-10 18:29:41 +01:00
|
|
|
}
|
|
|
|
|
2024-02-10 19:57:17 +01:00
|
|
|
class SCNApp extends StatelessWidget {
|
|
|
|
const SCNApp({super.key});
|
2024-02-10 18:29:41 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-05-25 18:09:39 +02:00
|
|
|
Provider.of<UserAccount>(context); // ensure UserAccount is loaded (unneccessary if lazy: false is set in MultiProvider ??)
|
2024-02-18 16:23:10 +01:00
|
|
|
|
2024-02-11 01:08:51 +01:00
|
|
|
return Consumer<AppTheme>(
|
|
|
|
builder: (context, appTheme, child) => MaterialApp(
|
|
|
|
title: 'SimpleCloudNotifier',
|
|
|
|
theme: ThemeData(
|
|
|
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue, brightness: appTheme.darkMode ? Brightness.dark : Brightness.light),
|
|
|
|
useMaterial3: true,
|
|
|
|
),
|
2024-05-25 18:09:39 +02:00
|
|
|
home: const ToastProvider(child: SCNNavLayout()),
|
2024-02-10 18:29:41 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|