Skip to content
This repository has been archived by the owner on Apr 25, 2022. It is now read-only.

Commit

Permalink
feat(settings): more colors options
Browse files Browse the repository at this point in the history
  • Loading branch information
CCXXXI committed Oct 2, 2021
1 parent b45ee42 commit e9aa395
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
13 changes: 7 additions & 6 deletions lib/settings/settings_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ class SettingsPage extends StatelessWidget {
settingKey: 'overrideColor',
onChange: logic.updateTheme,
childrenIfEnabled: [
ColorPickerSettingsTile(
settingKey: 'color',
title: '主题色',
defaultValue: ecnuColor,
onChange: logic.updateTheme,
),
for (final c in ['primary', 'secondary', 'surface'])
ColorPickerSettingsTile(
settingKey: 'color.$c',
title: c,
defaultValue: ecnuColor,
onChange: logic.updateTheme,
),
],
);

Expand Down
16 changes: 10 additions & 6 deletions lib/settings/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ import 'package:get/get.dart';

import '../utils/messages.dart';

const ecnuColor = Color(0xffa41f35);

Color get _color => Settings.getValue('overrideColor', false)
? ConversionUtils.colorFromString(Settings.getValue('color', '#ffa41f35'))
: ecnuColor;
const _ecnuColorStr = '#ffa41f35';
final ecnuColor = ConversionUtils.colorFromString(_ecnuColorStr);

ThemeMode get _themeMode =>
ThemeMode.values[Settings.getValue('themeMode', ThemeMode.system.index)];
Expand All @@ -17,9 +14,16 @@ bool get _dark =>
_themeMode == ThemeMode.dark ||
_themeMode == ThemeMode.system && Get.isPlatformDarkMode;

Color _c(String key) => Settings.getValue('overrideColor', false)
? ConversionUtils.colorFromString(
Settings.getValue('color.$key', _ecnuColorStr))
: ecnuColor;

ThemeData get theme => ThemeData.from(
colorScheme: (_dark ? ColorScheme.dark : ColorScheme.light)(
primary: _color,
primary: _c('primary'),
secondary: _c('secondary'),
surface: _c('surface'),
),
textTheme: (_dark ? ThemeData.dark : ThemeData.light)()
.textTheme
Expand Down

0 comments on commit e9aa395

Please sign in to comment.