Skip to content

Commit

Permalink
feat: black theme (#76)
Browse files Browse the repository at this point in the history
* feat: black theme

* fix: `ToggleButton` not clear in black theme
  • Loading branch information
MiaoMint authored Sep 24, 2023
1 parent 66d6962 commit ea539a0
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 6 deletions.
1 change: 1 addition & 0 deletions assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"theme-system": "System",
"theme-light": "Light",
"theme-dark": "Dark",
"theme-black": "Black",
"nsfw": "NSFW",
"nsfw-subtitle": "Show NSFW content",
"external-player": "Preferred video player",
Expand Down
1 change: 1 addition & 0 deletions assets/i18n/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"theme-system": "跟随系统",
"theme-light": "浅色",
"theme-dark": "深色",
"theme-black": "黑色",
"nsfw": "NSFW",
"nsfw-subtitle": "显示 NSFW 内容",
"external-player": "优先使用的视频播放器",
Expand Down
38 changes: 38 additions & 0 deletions lib/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,50 @@ class ApplicationController extends GetxController {
super.onInit();
}

ThemeData get currentThemeData {
switch (themeText.value) {
case "light":
return ThemeData.light(useMaterial3: true);
case "dark":
return ThemeData.dark(useMaterial3: true);
case "black":
return ThemeData.dark(
useMaterial3: true,
).copyWith(
scaffoldBackgroundColor: Colors.black,
canvasColor: Colors.black,
cardColor: Colors.black,
dialogBackgroundColor: Colors.black,
primaryColor: Colors.black,
hintColor: Colors.black,
primaryColorDark: Colors.black,
primaryColorLight: Colors.black,
colorScheme: const ColorScheme.dark(
primary: Colors.white,
onBackground: Colors.white,
onSecondary: Colors.white,
onSurface: Colors.white,
secondary: Colors.black,
surface: Colors.black,
background: Colors.black,
onPrimary: Colors.black,
primaryContainer: Color.fromARGB(255, 31, 31, 31),
surfaceTint: Colors.black,
),
);
default:
return ThemeData.light(useMaterial3: true);
}
}

ThemeMode get theme {
switch (themeText.value) {
case "light":
return ThemeMode.light;
case "dark":
return ThemeMode.dark;
case "black":
return ThemeMode.light;
default:
return ThemeMode.system;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class _MainAppState extends fluent.State<MainApp> {
title: "Miru",
debugShowCheckedModeBanner: false,
themeMode: c.theme,
theme: ThemeData(useMaterial3: true),
theme: c.currentThemeData,
darkTheme: ThemeData.dark(useMaterial3: true),
home: const AndroidMainPage(),
localizationsDelegates: [
Expand Down
16 changes: 11 additions & 5 deletions lib/pages/settings/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,17 @@ class _SettingsPageState extends State<SettingsPage> {
desktopWidget: Icon(fluent.FluentIcons.color, size: 24),
),
title: 'settings.theme'.i18n,
itemNameValue: {
'settings.theme-system'.i18n: 'system',
'settings.theme-light'.i18n: 'light',
'settings.theme-dark'.i18n: 'dark',
},
itemNameValue: () {
final map = {
'settings.theme-system'.i18n: 'system',
'settings.theme-light'.i18n: 'light',
'settings.theme-dark'.i18n: 'dark',
};
if (Platform.isAndroid) {
map['settings.theme-black'.i18n] = 'black';
}
return map;
}(),
buildSubtitle: () => 'settings.theme-subtitle'.i18n,
applyValue: (value) {
Get.find<ApplicationController>().changeTheme(value);
Expand Down
9 changes: 9 additions & 0 deletions lib/widgets/button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ class PlatformToggleButton extends fluent.StatelessWidget {
Widget _buildAndroid(BuildContext context) {
return TextButton(
onPressed: () => onChanged?.call(!checked),
style: ButtonStyle(
side: MaterialStateProperty.all(
BorderSide(
color: checked
? Theme.of(context).colorScheme.primary
: Colors.transparent,
),
),
),
child: Text(
text,
style: TextStyle(
Expand Down

0 comments on commit ea539a0

Please sign in to comment.