45 lines
1.4 KiB
Dart
45 lines
1.4 KiB
Dart
import 'package:flutter/material.dart';
|
|||
|
|
import 'package:flutter/services.dart';
|
||
|
|
|
||
|
|
import 'services/storage.dart';
|
||
|
|
import 'state/app_state.dart';
|
||
|
|
import 'ui/common.dart';
|
||
|
|
import 'ui/home_shell.dart';
|
||
|
|
|
||
|
|
Future<void> main() async {
|
||
|
|
WidgetsFlutterBinding.ensureInitialized();
|
||
|
|
// Portrait only; also set in AndroidManifest.xml and Info.plist.
|
||
|
|
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||
|
|
final state = AppState(await Storage.open());
|
||
|
|
runApp(DailyTechNewsApp(state: state));
|
||
|
|
state.init();
|
||
|
|
}
|
||
|
|
|
||
|
|
class DailyTechNewsApp extends StatelessWidget {
|
||
|
|
const DailyTechNewsApp({super.key, required this.state});
|
||
|
|
|
||
|
|
final AppState state;
|
||
|
|
|
||
|
|
static const _seed = Color(0xFF3355DD);
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
ThemeData theme(Brightness brightness) => ThemeData(
|
||
|
|
colorScheme: ColorScheme.fromSeed(seedColor: _seed, brightness: brightness),
|
||
|
|
cardTheme: const CardThemeData(margin: EdgeInsets.zero),
|
||
|
|
);
|
||
|
|
|
||
|
|
// Rebuild when the theme setting changes; everything else listens itself.
|
||
|
|
return ListenableBuilder(
|
||
|
|
listenable: state,
|
||
|
|
builder: (context, _) => MaterialApp(
|
||
|
|
title: appName,
|
||
|
|
debugShowCheckedModeBanner: false,
|
||
|
|
theme: theme(Brightness.light),
|
||
|
|
darkTheme: theme(Brightness.dark),
|
||
|
|
themeMode: state.settings.themeMode,
|
||
|
|
home: HomeShell(state: state),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|