Dark mode settings save to SharedPreferences
This commit is contained in:
parent
b37600f7e1
commit
d5855b2433
|
|
@ -1,5 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:quickgui/src/globals.dart';
|
||||||
|
import 'package:quickgui/src/mixins/preferences_mixin.dart';
|
||||||
import 'package:quickgui/src/model/app_theme.dart';
|
import 'package:quickgui/src/model/app_theme.dart';
|
||||||
import 'package:quickgui/src/pages/main_page.dart';
|
import 'package:quickgui/src/pages/main_page.dart';
|
||||||
|
|
||||||
|
|
@ -10,16 +12,30 @@ class App extends StatefulWidget {
|
||||||
State<App> createState() => _AppState();
|
State<App> createState() => _AppState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _AppState extends State<App> {
|
class _AppState extends State<App> with PreferencesMixin {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Consumer<AppTheme>(
|
return FutureBuilder<bool?>(
|
||||||
builder: (context, appTheme, _) => MaterialApp(
|
future: getPreference<bool>(prefThemeMode),
|
||||||
theme: ThemeData(primarySwatch: Colors.pink),
|
builder: (context, AsyncSnapshot<bool?> snapshot) {
|
||||||
darkTheme: ThemeData.dark(),
|
if (snapshot.connectionState == ConnectionState.done) {
|
||||||
themeMode: appTheme.themeMode,
|
if (snapshot.data != null) {
|
||||||
home: const MainPage(title: 'Quickgui - A Flutter frontend for Quickget and Quickemu'),
|
context.read<AppTheme>().useDarkMode = snapshot.data!;
|
||||||
),
|
}
|
||||||
|
return Consumer<AppTheme>(
|
||||||
|
builder: (context, appTheme, _) => MaterialApp(
|
||||||
|
theme: ThemeData(primarySwatch: Colors.pink),
|
||||||
|
darkTheme: ThemeData.dark(),
|
||||||
|
themeMode: appTheme.themeMode,
|
||||||
|
home: const MainPage(title: 'Quickgui - A Flutter frontend for Quickget and Quickemu'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return const Center(
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,3 +2,4 @@ import 'dart:io';
|
||||||
|
|
||||||
var gIsSnap = Platform.environment['SNAP']?.isNotEmpty ?? false;
|
var gIsSnap = Platform.environment['SNAP']?.isNotEmpty ?? false;
|
||||||
const String prefWorkingDirectory = 'workingDirectory';
|
const String prefWorkingDirectory = 'workingDirectory';
|
||||||
|
const String prefThemeMode = 'themeMode';
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:quickgui/src/globals.dart';
|
||||||
import 'package:quickgui/src/mixins/app_version.dart';
|
import 'package:quickgui/src/mixins/app_version.dart';
|
||||||
|
import 'package:quickgui/src/mixins/preferences_mixin.dart';
|
||||||
import 'package:quickgui/src/model/app_theme.dart';
|
import 'package:quickgui/src/model/app_theme.dart';
|
||||||
|
|
||||||
class LeftMenu extends StatelessWidget {
|
class LeftMenu extends StatelessWidget with PreferencesMixin {
|
||||||
const LeftMenu({Key? key}) : super(key: key);
|
const LeftMenu({Key? key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -27,6 +29,7 @@ class LeftMenu extends StatelessWidget {
|
||||||
value: Theme.of(context).brightness == Brightness.dark,
|
value: Theme.of(context).brightness == Brightness.dark,
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
appTheme.useDarkMode = value;
|
appTheme.useDarkMode = value;
|
||||||
|
savePreference(prefThemeMode, value);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue