2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-12 02:05:29 +00:00

Adds "dark mode" support (#317)

* Adds "dark mode" support

- Uses adaptive_theme package

* CI fixes

* More fixes

* Update release notes
This commit is contained in:
Oliver
2023-04-16 21:10:57 +10:00
committed by GitHub
parent e7f5141aa9
commit a3d712d11d
7 changed files with 99 additions and 29 deletions

View File

@ -3,6 +3,7 @@ import "dart:async";
import "package:flutter/material.dart";
import "package:flutter/services.dart";
import "package:adaptive_theme/adaptive_theme.dart";
import "package:flutter_gen/gen_l10n/app_localizations.dart";
import "package:flutter_localizations/flutter_localizations.dart";
import "package:flutter_localized_locales/flutter_localized_locales.dart";
@ -22,6 +23,8 @@ Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
final savedThemeMode = await AdaptiveTheme.getThemeMode();
await runZonedGuarded<Future<void>>(() async {
PackageInfo info = await PackageInfo.fromPlatform();
@ -53,7 +56,7 @@ Future<void> main() async {
};
runApp(
InvenTreeApp()
InvenTreeApp(savedThemeMode)
);
}, (Object error, StackTrace stackTrace) async {
@ -65,8 +68,12 @@ Future<void> main() async {
class InvenTreeApp extends StatefulWidget {
// This widget is the root of your application.
const InvenTreeApp(this.savedThemeMode);
final AdaptiveThemeMode? savedThemeMode;
@override
InvenTreeAppState createState() => InvenTreeAppState();
InvenTreeAppState createState() => InvenTreeAppState(savedThemeMode);
static InvenTreeAppState? of(BuildContext context) => context.findAncestorStateOfType<InvenTreeAppState>();
@ -75,9 +82,13 @@ class InvenTreeApp extends StatefulWidget {
class InvenTreeAppState extends State<StatefulWidget> {
InvenTreeAppState(this.savedThemeMode) : super();
// Custom _locale (default = null; use system default)
Locale? _locale;
final AdaptiveThemeMode? savedThemeMode;
@override
void initState() {
super.initState();
@ -122,25 +133,36 @@ class InvenTreeAppState extends State<StatefulWidget> {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
builder: OneContext().builder,
navigatorKey: OneContext().key,
onGenerateTitle: (BuildContext context) => "InvenTree",
theme: ThemeData(
return AdaptiveTheme(
light: ThemeData(
brightness: Brightness.light,
primarySwatch: Colors.lightBlue,
secondaryHeaderColor: Colors.blueGrey
),
dark: ThemeData(
brightness: Brightness.dark,
primarySwatch: Colors.lightBlue,
secondaryHeaderColor: Colors.blueGrey,
),
home: InvenTreeHomePage(),
localizationsDelegates: [
I18N.delegate,
LocaleNamesLocalizationsDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: supported_locales,
locale: _locale,
initial: savedThemeMode ?? AdaptiveThemeMode.light,
builder: (light, dark) => MaterialApp(
theme: light,
darkTheme: dark,
debugShowCheckedModeBanner: false,
builder: OneContext().builder,
navigatorKey: OneContext().key,
onGenerateTitle: (BuildContext context) => "InvenTree",
home: InvenTreeHomePage(),
localizationsDelegates: [
I18N.delegate,
LocaleNamesLocalizationsDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: supported_locales,
locale: _locale,
)
);
}
}