frosty/lib/main.dart

162 lines
5.4 KiB
Dart
Raw Normal View History

import 'dart:convert';
import 'dart:io';
2021-08-18 09:38:00 -04:00
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
2021-11-21 23:29:47 -05:00
import 'package:frosty/core/auth/auth_store.dart';
import 'package:frosty/screens/home/home.dart';
import 'package:frosty/screens/home/stores/categories_store.dart';
import 'package:frosty/screens/home/stores/home_store.dart';
import 'package:frosty/screens/home/stores/list_store.dart';
2022-01-07 21:56:45 -05:00
import 'package:frosty/screens/home/stores/search_store.dart';
import 'package:frosty/screens/settings/stores/settings_store.dart';
import 'package:mobx/mobx.dart';
2021-10-05 00:16:46 -04:00
import 'package:provider/provider.dart';
2021-12-29 21:06:01 -05:00
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:shared_preferences/shared_preferences.dart';
2021-08-18 09:38:00 -04:00
2021-12-29 21:06:01 -05:00
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
2022-01-09 12:53:40 -05:00
// Create and initialize the authentication store
final authStore = AuthStore();
await authStore.init();
2022-01-09 12:53:40 -05:00
// Get the shared preferences instance and obtain the existing user settings if it exists.
// If default settings don't exist, use an empty JSON string to use the default values.
final preferences = await SharedPreferences.getInstance();
final userSettings = preferences.getString('settings') ?? '{}';
// Initialize a settings store from the settings JSON string.
final settingsStore = SettingsStore.fromJson(jsonDecode(userSettings));
2022-01-09 12:53:40 -05:00
// Create a MobX reaction that will save the settings on disk every time they are changed.
autorun((_) => preferences.setString('settings', jsonEncode(settingsStore)));
2021-12-29 21:06:01 -05:00
await SentryFlutter.init(
(options) {
options.tracesSampleRate = 1.0;
},
appRunner: () => runApp(
MultiProvider(
providers: [
Provider<AuthStore>(create: (_) => authStore),
Provider<SettingsStore>(create: (_) => settingsStore),
],
child: const MyApp(),
),
),
2021-12-29 21:06:01 -05:00
);
2021-08-18 09:38:00 -04:00
}
class MyApp extends StatelessWidget {
2021-09-09 00:08:36 -04:00
const MyApp({Key? key}) : super(key: key);
2021-08-18 09:38:00 -04:00
@override
Widget build(BuildContext context) {
final authStore = context.read<AuthStore>();
final settingsStore = context.read<SettingsStore>();
final lightTheme = ThemeData(
scaffoldBackgroundColor: Colors.white,
splashFactory: Platform.isIOS ? NoSplash.splashFactory : null,
fontFamily: 'Inter',
appBarTheme: const AppBarTheme(
color: Colors.white,
elevation: 0.0,
titleTextStyle: TextStyle(
fontFamily: 'Inter',
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.black,
),
iconTheme: IconThemeData(color: Colors.black),
),
colorScheme: ColorScheme.fromSwatch(
primarySwatch: Colors.deepPurple,
accentColor: Colors.deepPurpleAccent,
),
toggleableActiveColor: Colors.deepPurpleAccent,
tabBarTheme: const TabBarTheme(
labelColor: Colors.black,
unselectedLabelColor: Colors.grey,
),
);
final darkTheme = ThemeData(
scaffoldBackgroundColor: Colors.grey.shade900,
brightness: Brightness.dark,
splashFactory: Platform.isIOS ? NoSplash.splashFactory : null,
fontFamily: 'Inter',
appBarTheme: AppBarTheme(
color: Colors.grey.shade900,
elevation: 0.0,
titleTextStyle: const TextStyle(
fontFamily: 'Inter',
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
2022-01-07 02:27:38 -05:00
colorScheme: ColorScheme.fromSwatch(
brightness: Brightness.dark,
primarySwatch: Colors.deepPurple,
accentColor: Colors.deepPurpleAccent,
),
dialogBackgroundColor: Colors.grey.shade900,
2022-01-09 12:53:40 -05:00
toggleableActiveColor: Colors.deepPurpleAccent,
);
2021-11-22 01:26:17 -05:00
2022-01-07 02:27:38 -05:00
final oledTheme = ThemeData(
canvasColor: Colors.black,
splashFactory: Platform.isIOS ? NoSplash.splashFactory : null,
2022-01-07 02:27:38 -05:00
fontFamily: 'Inter',
appBarTheme: const AppBarTheme(
color: Colors.black,
elevation: 0.0,
titleTextStyle: TextStyle(
fontFamily: 'Inter',
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
2022-01-07 02:27:38 -05:00
colorScheme: ColorScheme.fromSwatch(
brightness: Brightness.dark,
primarySwatch: Colors.deepPurple,
accentColor: Colors.deepPurpleAccent,
),
dialogBackgroundColor: Colors.black,
2022-01-09 12:53:40 -05:00
toggleableActiveColor: Colors.deepPurpleAccent,
2021-08-18 09:38:00 -04:00
);
return Observer(
builder: (context) {
return MaterialApp(
title: 'Frosty',
theme: lightTheme,
darkTheme: settingsStore.themeType == ThemeType.dark || settingsStore.themeType == ThemeType.system ? darkTheme : oledTheme,
themeMode: settingsStore.themeType == ThemeType.system
? ThemeMode.system
: settingsStore.themeType == ThemeType.light
? ThemeMode.light
: ThemeMode.dark,
home: Home(
homeStore: HomeStore(),
topSectionStore: ListStore(
authStore: authStore,
listType: ListType.top,
),
categoriesSectionStore: CategoriesStore(authStore: authStore),
followedStreamsStore: authStore.isLoggedIn
? ListStore(
authStore: authStore,
listType: ListType.followed,
)
: null,
searchStore: SearchStore(authStore: authStore),
),
);
},
);
2021-08-18 09:38:00 -04:00
}
}