mirror of
https://github.com/git-touch/git-touch
synced 2025-03-05 11:48:02 +01:00
fix: follow system brightness
This commit is contained in:
parent
5c6428a36d
commit
fccb79b2cc
@ -16,12 +16,7 @@ class MyApp extends StatelessWidget {
|
||||
);
|
||||
default:
|
||||
return MaterialApp(
|
||||
theme: ThemeData(
|
||||
brightness: theme.brightness,
|
||||
// primaryColorBrightness: theme.brightness,
|
||||
primaryColorLight: theme.paletteLight.background,
|
||||
primaryColorDark: theme.paletteDark.background,
|
||||
),
|
||||
theme: ThemeData(brightness: theme.brightness),
|
||||
home: Home(),
|
||||
);
|
||||
}
|
||||
|
@ -137,7 +137,6 @@ class _HomeState extends State<Home> {
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
default:
|
||||
return Scaffold(
|
||||
body: _buildScreen(active),
|
||||
|
@ -97,28 +97,26 @@ class Palette {
|
||||
}
|
||||
|
||||
class ThemeModel with ChangeNotifier {
|
||||
static const kTheme = 'theme';
|
||||
static const kBrightness = 'brightness';
|
||||
|
||||
int _theme;
|
||||
int get theme => _theme;
|
||||
bool get ready => _theme != null;
|
||||
|
||||
int _brightnessValue = AppBrightnessType.followSystem;
|
||||
int get brighnessValue => _brightnessValue;
|
||||
|
||||
/// not null
|
||||
Brightness brightnessOf(BuildContext context) {
|
||||
switch (_brightnessValue) {
|
||||
case AppBrightnessType.light:
|
||||
return Brightness.light;
|
||||
case AppBrightnessType.dark:
|
||||
return Brightness.dark;
|
||||
default:
|
||||
return MediaQuery.of(context).platformBrightness;
|
||||
Brightness systemBrightness = Brightness.light;
|
||||
void setSystemBrightness(Brightness v) {
|
||||
// print('systemBrightness: $v');
|
||||
if (v != systemBrightness) {
|
||||
Future.microtask(() {
|
||||
systemBrightness = v;
|
||||
notifyListeners();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
int _brightnessValue = AppBrightnessType.followSystem;
|
||||
int get brighnessValue => _brightnessValue;
|
||||
|
||||
// could be null
|
||||
Brightness get brightness {
|
||||
switch (_brightnessValue) {
|
||||
@ -127,7 +125,7 @@ class ThemeModel with ChangeNotifier {
|
||||
case AppBrightnessType.dark:
|
||||
return Brightness.dark;
|
||||
default:
|
||||
return null;
|
||||
return systemBrightness;
|
||||
}
|
||||
}
|
||||
|
||||
@ -161,7 +159,7 @@ class ThemeModel with ChangeNotifier {
|
||||
);
|
||||
|
||||
Palette paletteOf(BuildContext context) {
|
||||
switch (brightnessOf(context)) {
|
||||
switch (brightness) {
|
||||
case Brightness.light:
|
||||
return paletteLight;
|
||||
case Brightness.dark:
|
||||
@ -173,7 +171,7 @@ class ThemeModel with ChangeNotifier {
|
||||
|
||||
Future<void> init() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final v = prefs.getInt(kTheme);
|
||||
final v = prefs.getInt(StorageKeys.theme);
|
||||
Fimber.d('read theme: $v');
|
||||
if (AppThemeType.values.contains(v)) {
|
||||
_theme = v;
|
||||
@ -194,7 +192,7 @@ class ThemeModel with ChangeNotifier {
|
||||
Future<void> setTheme(int v) async {
|
||||
_theme = v;
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setInt(kTheme, v);
|
||||
await prefs.setInt(StorageKeys.theme, v);
|
||||
Fimber.d('write theme: $v');
|
||||
notifyListeners();
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ class CommonScaffold extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Provider.of<ThemeModel>(context);
|
||||
// FIXME: A hack to get brightness before MaterialApp been built
|
||||
theme.setSystemBrightness(MediaQuery.of(context).platformBrightness);
|
||||
|
||||
switch (theme.theme) {
|
||||
case AppThemeType.cupertino:
|
||||
@ -32,7 +34,6 @@ class CommonScaffold extends StatelessWidget {
|
||||
default:
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
brightness: theme.brightnessOf(context),
|
||||
title: title,
|
||||
actions: [
|
||||
if (action != null) action,
|
||||
|
@ -170,7 +170,7 @@ class ObjectScreen extends StatelessWidget {
|
||||
text,
|
||||
language: _language,
|
||||
theme: themeMap[
|
||||
theme.brightnessOf(context) == Brightness.dark
|
||||
theme.brightness == Brightness.dark
|
||||
? codeProvider.themeDark
|
||||
: codeProvider.theme],
|
||||
padding: CommonStyle.padding,
|
||||
|
@ -230,7 +230,7 @@ class UserScreen extends StatelessWidget {
|
||||
spacing: 3,
|
||||
children: week.contributionDays.map((day) {
|
||||
var color = convertColor(day.color);
|
||||
if (theme.brightnessOf(context) == Brightness.dark) {
|
||||
if (theme.brightness == Brightness.dark) {
|
||||
color = Color.fromRGBO(0xff - color.red,
|
||||
0xff - color.green, 0xff - color.blue, 1);
|
||||
}
|
||||
|
@ -15,11 +15,13 @@ export 'extensions.dart';
|
||||
export 'package:flutter_vector_icons/flutter_vector_icons.dart';
|
||||
|
||||
class StorageKeys {
|
||||
static const accounts = 'accounts';
|
||||
@deprecated
|
||||
static const account = 'account';
|
||||
@deprecated
|
||||
static const github = 'github';
|
||||
|
||||
static const accounts = 'accounts';
|
||||
static const theme = 'theme';
|
||||
static const newsFilter = 'news.filter';
|
||||
}
|
||||
|
||||
class CommonStyle {
|
||||
|
Loading…
x
Reference in New Issue
Block a user