feat: Use Android system accent color
This commit is contained in:
parent
5f3e8791dd
commit
a35229bf7d
11 changed files with 183 additions and 113 deletions
|
|
@ -2,12 +2,11 @@ import 'dart:io';
|
|||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:adaptive_theme/adaptive_theme.dart';
|
||||
import 'package:file_picker_cross/file_picker_cross.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/config/setting_keys.dart';
|
||||
import 'package:fluffychat/config/themes.dart';
|
||||
import 'package:fluffychat/widgets/theme_builder.dart';
|
||||
import '../../widgets/matrix.dart';
|
||||
import 'settings_style_view.dart';
|
||||
|
||||
|
|
@ -38,21 +37,15 @@ class SettingsStyleController extends State<SettingsStyle> {
|
|||
}
|
||||
|
||||
void setChatColor(Color? color) async {
|
||||
await Matrix.of(context).store.setItem(
|
||||
SettingKeys.chatColor,
|
||||
color?.value.toString(),
|
||||
);
|
||||
AppConfig.colorSchemeSeed = color;
|
||||
AdaptiveTheme.of(context).setTheme(
|
||||
light: FluffyThemes.buildTheme(Brightness.light),
|
||||
dark: FluffyThemes.buildTheme(Brightness.dark),
|
||||
);
|
||||
ThemeController.of(context).setPrimaryColor(color);
|
||||
}
|
||||
|
||||
AdaptiveThemeMode? currentTheme;
|
||||
ThemeMode get currentTheme => ThemeController.of(context).themeMode;
|
||||
Color? get currentColor => ThemeController.of(context).primaryColor;
|
||||
|
||||
static final List<Color?> customColors = [
|
||||
AppConfig.primaryColor,
|
||||
AppConfig.chatColor,
|
||||
Colors.blue.shade800,
|
||||
Colors.green.shade800,
|
||||
Colors.orange.shade700,
|
||||
|
|
@ -61,20 +54,20 @@ class SettingsStyleController extends State<SettingsStyle> {
|
|||
null,
|
||||
];
|
||||
|
||||
void switchTheme(AdaptiveThemeMode? newTheme) {
|
||||
void switchTheme(ThemeMode? newTheme) {
|
||||
if (newTheme == null) return;
|
||||
switch (newTheme) {
|
||||
case AdaptiveThemeMode.light:
|
||||
AdaptiveTheme.of(context).setLight();
|
||||
case ThemeMode.light:
|
||||
ThemeController.of(context).setThemeMode(ThemeMode.light);
|
||||
break;
|
||||
case AdaptiveThemeMode.dark:
|
||||
AdaptiveTheme.of(context).setDark();
|
||||
case ThemeMode.dark:
|
||||
ThemeController.of(context).setThemeMode(ThemeMode.dark);
|
||||
break;
|
||||
case AdaptiveThemeMode.system:
|
||||
AdaptiveTheme.of(context).setSystem();
|
||||
case ThemeMode.system:
|
||||
ThemeController.of(context).setThemeMode(ThemeMode.system);
|
||||
break;
|
||||
}
|
||||
setState(() => currentTheme = newTheme);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
void changeFontSizeFactor(double d) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:adaptive_theme/adaptive_theme.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
|
||||
|
|
@ -15,7 +14,6 @@ class SettingsStyleView extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
controller.currentTheme ??= AdaptiveTheme.of(context).mode;
|
||||
const colorPickerSize = 32.0;
|
||||
final wallpaper = Matrix.of(context).wallpaper;
|
||||
return Scaffold(
|
||||
|
|
@ -63,8 +61,7 @@ class SettingsStyleView extends StatelessWidget {
|
|||
child: SizedBox(
|
||||
width: colorPickerSize,
|
||||
height: colorPickerSize,
|
||||
child: AppConfig.colorSchemeSeed?.value ==
|
||||
color.value
|
||||
child: controller.currentColor == color
|
||||
? const Center(
|
||||
child: Icon(
|
||||
Icons.check,
|
||||
|
|
@ -80,21 +77,21 @@ class SettingsStyleView extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
RadioListTile<AdaptiveThemeMode>(
|
||||
RadioListTile<ThemeMode>(
|
||||
groupValue: controller.currentTheme,
|
||||
value: AdaptiveThemeMode.system,
|
||||
value: ThemeMode.system,
|
||||
title: Text(L10n.of(context)!.systemTheme),
|
||||
onChanged: controller.switchTheme,
|
||||
),
|
||||
RadioListTile<AdaptiveThemeMode>(
|
||||
RadioListTile<ThemeMode>(
|
||||
groupValue: controller.currentTheme,
|
||||
value: AdaptiveThemeMode.light,
|
||||
value: ThemeMode.light,
|
||||
title: Text(L10n.of(context)!.lightTheme),
|
||||
onChanged: controller.switchTheme,
|
||||
),
|
||||
RadioListTile<AdaptiveThemeMode>(
|
||||
RadioListTile<ThemeMode>(
|
||||
groupValue: controller.currentTheme,
|
||||
value: AdaptiveThemeMode.dark,
|
||||
value: ThemeMode.dark,
|
||||
title: Text(L10n.of(context)!.darkTheme),
|
||||
onChanged: controller.switchTheme,
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue