Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

add theme settings

Predidit2d03f758b9c9
diff --git a/lib/app_widget.dart b/lib/app_widget.dart
index fb6c5107..f286c587 100644
--- a/lib/app_widget.dart
+++ b/lib/app_widget.dart
@@ -5,6 +5,9 @@ import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:adaptive_theme/adaptive_theme.dart';
import 'package:flutter_displaymode/flutter_displaymode.dart';
+import 'package:hive/hive.dart';
+import 'package:kazumi/utils/utils.dart';
+import 'package:kazumi/utils/storage.dart';
class AppWidget extends StatefulWidget {
const AppWidget({super.key});
@@ -14,18 +17,32 @@ class AppWidget extends StatefulWidget {
}
class _AppWidgetState extends State<AppWidget> {
+ Box setting = GStorage.setting;
+
@override
Widget build(BuildContext context) {
- var app = AdaptiveTheme(
- light: ThemeData(
- useMaterial3: true,
- brightness: Brightness.light,
- ),
- dark: ThemeData(
+ dynamic color;
+ dynamic defaultThemeColor =
+ setting.get(SettingBoxKey.themeColor, defaultValue: 'default');
+ if (defaultThemeColor == 'default') {
+ color = null;
+ } else {
+ color = Color(int.parse(defaultThemeColor, radix: 16));
+ }
+ bool oledEnhance =
+ setting.get(SettingBoxKey.oledEnhance, defaultValue: false);
+ var defaultDarkTheme = ThemeData(
useMaterial3: true,
brightness: Brightness.dark,
- ),
- initial: AdaptiveThemeMode.light,
+ colorSchemeSeed: color);
+ var oledDarkTheme = Utils.oledDarkTheme(defaultDarkTheme);
+ var app = AdaptiveTheme(
+ light: ThemeData(
+ useMaterial3: true,
+ brightness: Brightness.light,
+ colorSchemeSeed: color),
+ dark: oledEnhance ? oledDarkTheme : defaultDarkTheme,
+ initial: AdaptiveThemeMode.system,
builder: (theme, darkTheme) => MaterialApp.router(
title: "Kazumi",
localizationsDelegates: GlobalMaterialLocalizations.delegates,
@@ -49,7 +66,11 @@ class _AppWidgetState extends State<AppWidget> {
late List modes;
FlutterDisplayMode.supported.then((value) {
modes = value;
+ var storageDisplay = setting.get(SettingBoxKey.displayMode);
DisplayMode f = DisplayMode.auto;
+ if (storageDisplay != null) {
+ f = modes.firstWhere((e) => e.toString() == storageDisplay);
+ }
DisplayMode preferred = modes.toList().firstWhere((el) => el == f);
FlutterDisplayMode.setPreferredMode(preferred);
});
diff --git a/lib/bean/settings/color_type.dart b/lib/bean/settings/color_type.dart
new file mode 100644
index 00000000..bc98d215
--- /dev/null
+++ b/lib/bean/settings/color_type.dart
@@ -0,0 +1,23 @@
+import 'package:flutter/material.dart';
+
+final List<Map<String, dynamic>> colorThemeTypes = [
+ {'color': Colors.purple, 'label': '默认'},
+ {'color': Colors.pink, 'label': '粉红色'},
+ {'color': Colors.red, 'label': '红色'},
+ {'color': Colors.orange, 'label': '橙色'},
+ {'color': Colors.amber, 'label': '琥珀色'},
+ {'color': Colors.yellow, 'label': '黄色'},
+ {'color': Colors.lime, 'label': '酸橙色'},
+ {'color': Colors.lightGreen, 'label': '浅绿色'},
+ {'color': Colors.green, 'label': '绿色'},
+ {'color': Colors.teal, 'label': '青色'},
+ {'color': Colors.cyan, 'label': '蓝绿色'},
+ {'color': Colors.lightBlue, 'label': '浅蓝色'},
+ {'color': Colors.blue, 'label': '蓝色'},
+ {'color': Colors.indigo, 'label': '靛蓝色'},
+ {'color': Colors.purple, 'label': '紫色'},
+ {'color': Colors.deepPurple, 'label': '深紫色'},
+ {'color': Colors.blueGrey, 'label': '蓝灰色'},
+ {'color': Colors.brown, 'label': '棕色'},
+ {'color': Colors.grey, 'label': '灰色'},
+];
diff --git a/lib/pages/my/my_module.dart b/lib/pages/my/my_module.dart
index 34833c91..c04d4c36 100644
--- a/lib/pages/my/my_module.dart
+++ b/lib/pages/my/my_module.dart
@@ -5,11 +5,13 @@ import 'package:kazumi/pages/about/about_module.dart';
import 'package:kazumi/pages/plugin_editor/plugin_module.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:kazumi/pages/history/history_module.dart';
+import 'package:kazumi/pages/settings/theme_settings_page.dart';
class MyModule extends Module {
@override
void routes(r) {
r.child("/", child: (_) => const MyPage());
+ r.child("/theme", child: (_) => const ThemeSettingsPage());
r.child("/danmaku",
child: (_) => const DanmakuSettingsPage(),
transition: Platform.isWindows || Platform.isLinux || Platform.isMacOS
diff --git a/lib/pages/my/my_page.dart b/lib/pages/my/my_page.dart
index 45780051..548538c5 100644
--- a/lib/pages/my/my_page.dart
+++ b/lib/pages/my/my_page.dart
@@ -37,6 +37,14 @@ class _MyPageState extends State<MyPage> {
dense: false,
title: const Text('弹幕设置'),
),
+ ListTile(
+ onTap: () async {
+ Modular.to.pushNamed('/tab/my/theme');
+ },
+ dense: false,
+ title: const Text('外观设置'),
+ // trailing: const Icon(Icons.navigate_next),
+ ),
ListTile(
onTap: () {
Modular.to.pushNamed('/tab/my/about');
diff --git a/lib/pages/popular/popular_page.dart b/lib/pages/popular/popular_page.dart
index 7353d7e9..5198db38 100644
--- a/lib/pages/popular/popular_page.dart
+++ b/lib/pages/popular/popular_page.dart
@@ -89,119 +89,116 @@ class _PopularPageState extends State<PopularPage>
onPopInvoked: (bool didPop) async {
onBackPressed(context);
},
- child: SafeArea(
- child: RefreshIndicator(
- onRefresh: () async {
- await popularController.queryBangumiListFeed();
- },
- child: Scaffold(
- appBar: SysAppBar(
- backgroundColor:
- Theme.of(context).colorScheme.primary.withOpacity(0.5),
- title: Stack(
- children: [
- TextField(
- focusNode: _focusNode,
- controller: _controller,
- style: const TextStyle(color: Colors.white, fontSize: 20),
- decoration: const InputDecoration(
- hintText: '快速搜索',
- hintStyle: TextStyle(color: Colors.white, fontSize: 20),
- border: InputBorder.none,
- prefixIcon: Icon(Icons.search, color: Colors.white),
- ),
- autocorrect: false,
- autofocus: false,
- onTap: () {
- setState(() {
- _focusNode.requestFocus();
- _controller.clear();
- });
- },
- onChanged: (_) {
- scrollController.jumpTo(0.0);
- },
- onSubmitted: (t) {
- if (t != '') {
- popularController.searchKeyword = t;
- popularController
- .queryBangumi(popularController.searchKeyword);
- } else {
- popularController.queryBangumiListFeed();
- }
- },
- ),
- Positioned.fill(
- child: GestureDetector(
- behavior: HitTestBehavior.translucent,
- onPanStart: (_) => windowManager.startDragging(),
- child: Container(),
- ),
+ child: RefreshIndicator(
+ onRefresh: () async {
+ await popularController.queryBangumiListFeed();
+ },
+ child: Scaffold(
+ appBar: SysAppBar(
+ backgroundColor:
+ Theme.of(context).colorScheme.primary.withOpacity(0.5),
+ title: Stack(
+ children: [
+ TextField(
+ focusNode: _focusNode,
+ controller: _controller,
+ style: const TextStyle(color: Colors.white, fontSize: 20),
+ decoration: const InputDecoration(
+ hintText: '快速搜索',
+ hintStyle: TextStyle(color: Colors.white, fontSize: 20),
+ border: InputBorder.none,
+ prefixIcon: Icon(Icons.search, color: Colors.white),
),
- ],
- ),
- // actions: [IconButton(onPressed: () {
- // popularController.queryBangumi(popularController.keyword);
- // }, icon: const Icon(Icons.search))],
- ),
- body: CustomScrollView(
- controller: scrollController,
- slivers: [
- const SliverToBoxAdapter(
- child: Padding(
- padding:
- const EdgeInsets.only(top: 10, bottom: 10, left: 16),
- // child: Row(
- // mainAxisAlignment: MainAxisAlignment.spaceBetween,
- // children: [
- // Text(
- // '每日放送',
- // style: Theme.of(context).textTheme.titleMedium,
- // ),
- // ],
- // ),
+ autocorrect: false,
+ autofocus: false,
+ onTap: () {
+ setState(() {
+ _focusNode.requestFocus();
+ _controller.clear();
+ });
+ },
+ onChanged: (_) {
+ scrollController.jumpTo(0.0);
+ },
+ onSubmitted: (t) {
+ if (t != '') {
+ popularController.searchKeyword = t;
+ popularController
+ .queryBangumi(popularController.searchKeyword);
+ } else {
+ popularController.queryBangumiListFeed();
+ }
+ },
+ ),
+ Positioned.fill(
+ child: GestureDetector(
+ behavior: HitTestBehavior.translucent,
+ onPanStart: (_) => windowManager.startDragging(),
+ child: Container(),
),
),
- SliverPadding(
- padding: const EdgeInsets.fromLTRB(
- StyleString.safeSpace, 0, StyleString.safeSpace, 0),
- sliver: Observer(builder: (context) {
- if (popularController.bangumiList.isEmpty &&
- timeout == true) {
- return HttpError(
- errMsg: '什么都没有找到 (´;ω;`)',
- fn: () {
- popularController.queryBangumiListFeed();
- },
- );
- }
- if (popularController.bangumiList.isEmpty &&
- timeout == false) {
- return const SliverToBoxAdapter(
- child: SizedBox(
- height: 600,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.center,
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- CircularProgressIndicator(),
- ],
- )),
- );
- }
- return contentGrid(popularController.bangumiList);
- })),
],
),
- floatingActionButton: FloatingActionButton(
- onPressed: () {
- scrollController.jumpTo(0.0);
- popularController.scrollOffset = 0.0;
- },
- child: const Icon(Icons.arrow_upward),
- ),
- // backgroundColor: themedata.colorScheme.primaryContainer,
+ // actions: [IconButton(onPressed: () {
+ // popularController.queryBangumi(popularController.keyword);
+ // }, icon: const Icon(Icons.search))],
+ ),
+ body: CustomScrollView(
+ controller: scrollController,
+ slivers: [
+ const SliverToBoxAdapter(
+ child: Padding(
+ padding: const EdgeInsets.only(top: 10, bottom: 10, left: 16),
+ // child: Row(
+ // mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ // children: [
+ // Text(
+ // '每日放送',
+ // style: Theme.of(context).textTheme.titleMedium,
+ // ),
+ // ],
+ // ),
+ ),
+ ),
+ SliverPadding(
+ padding: const EdgeInsets.fromLTRB(
+ StyleString.safeSpace, 0, StyleString.safeSpace, 0),
+ sliver: Observer(builder: (context) {
+ if (popularController.bangumiList.isEmpty &&
+ timeout == true) {
+ return HttpError(
+ errMsg: '什么都没有找到 (´;ω;`)',
+ fn: () {
+ popularController.queryBangumiListFeed();
+ },
+ );
+ }
+ if (popularController.bangumiList.isEmpty &&
+ timeout == false) {
+ return const SliverToBoxAdapter(
+ child: SizedBox(
+ height: 600,
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.center,
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ CircularProgressIndicator(),
+ ],
+ )),
+ );
+ }
+ return contentGrid(popularController.bangumiList);
+ })),
+ ],
+ ),
+ floatingActionButton: FloatingActionButton(
+ onPressed: () {
+ scrollController.jumpTo(0.0);
+ popularController.scrollOffset = 0.0;
+ },
+ child: const Icon(Icons.arrow_upward),
),
+ // backgroundColor: themedata.colorScheme.primaryContainer,
),
),
);
diff --git a/lib/pages/settings/theme_settings_page.dart b/lib/pages/settings/theme_settings_page.dart
new file mode 100644
index 00000000..64702faf
--- /dev/null
+++ b/lib/pages/settings/theme_settings_page.dart
@@ -0,0 +1,294 @@
+import 'dart:io';
+import 'package:flutter/material.dart';
+import 'package:flutter_modular/flutter_modular.dart';
+import 'package:kazumi/utils/storage.dart';
+import 'package:hive/hive.dart';
+import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
+import 'package:adaptive_theme/adaptive_theme.dart';
+import 'package:kazumi/pages/popular/popular_controller.dart';
+import 'package:kazumi/bean/appbar/sys_app_bar.dart';
+import 'package:kazumi/bean/settings/color_type.dart';
+import 'package:kazumi/bean/settings/settings.dart';
+import 'package:kazumi/utils/utils.dart';
+
+class ThemeSettingsPage extends StatefulWidget {
+ const ThemeSettingsPage({super.key});
+
+ @override
+ State<ThemeSettingsPage> createState() => _ThemeSettingsPageState();
+}
+
+class _ThemeSettingsPageState extends State<ThemeSettingsPage> {
+ dynamic navigationBarState;
+ Box setting = GStorage.setting;
+ late dynamic defaultDanmakuArea;
+ late dynamic defaultThemeMode;
+ late dynamic defaultThemeColor;
+ late bool oledEnhance;
+ final PopularController popularController = Modular.get<PopularController>();
+
+ @override
+ void initState() {
+ super.initState();
+ defaultThemeMode =
+ setting.get(SettingBoxKey.themeMode, defaultValue: 'system');
+ defaultThemeColor =
+ setting.get(SettingBoxKey.themeColor, defaultValue: 'default');
+ oledEnhance = setting.get(SettingBoxKey.oledEnhance, defaultValue: false);
+ }
+
+ void onBackPressed(BuildContext context) {
+ Modular.to.navigate('/tab/my/');
+ }
+
+ void setTheme(Color? color) {
+ var defaultDarkTheme = ThemeData(
+ useMaterial3: true,
+ brightness: Brightness.dark,
+ colorSchemeSeed: color,
+ );
+ var oledDarkTheme = Utils.oledDarkTheme(defaultDarkTheme);
+ AdaptiveTheme.of(context).setTheme(
+ light: ThemeData(
+ useMaterial3: true,
+ brightness: Brightness.light,
+ colorSchemeSeed: color,
+ ),
+ dark: oledEnhance ? oledDarkTheme : defaultDarkTheme,
+ );
+ defaultThemeColor = color?.value.toRadixString(16) ?? 'default';
+ setting.put(SettingBoxKey.themeColor, defaultThemeColor);
+ }
+
+ void resetTheme() {
+ var defaultDarkTheme = ThemeData(
+ useMaterial3: true,
+ brightness: Brightness.dark,
+ );
+ var oledDarkTheme = Utils.oledDarkTheme(defaultDarkTheme);
+ AdaptiveTheme.of(context).setTheme(
+ light: ThemeData(
+ useMaterial3: true,
+ brightness: Brightness.light,
+ ),
+ dark: oledEnhance ? oledDarkTheme : defaultDarkTheme,
+ );
+ defaultThemeColor = 'default';
+ setting.put(SettingBoxKey.themeColor, 'default');
+ }
+
+ void updateTheme(String theme) async {
+ if (theme == 'dark') {
+ AdaptiveTheme.of(context).setDark();
+ }
+ if (theme == 'light') {
+ AdaptiveTheme.of(context).setLight();
+ }
+ if (theme == 'system') {
+ AdaptiveTheme.of(context).setSystem();
+ }
+ await setting.put(SettingBoxKey.themeMode, theme);
+ setState(() {
+ defaultThemeMode = theme;
+ });
+ }
+
+ void updateOledEnhance() {
+ dynamic color;
+ oledEnhance = setting.get(SettingBoxKey.oledEnhance, defaultValue: false);
+ if (defaultThemeColor == 'default') {
+ color = null;
+ } else {
+ color = Color(int.parse(defaultThemeColor, radix: 16));
+ }
+ setTheme(color);
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ // This method is rerun every time setState is called, for instance as done
+ // by the _incrementCounter method above.
+ //
+ // The Flutter framework has been optimized to make rerunning build methods
+ // fast, so that you can just rebuild anything that needs updating rather
+ // than having to individually change instances of widgets.
+ return PopScope(
+ canPop: false,
+ onPopInvoked: (bool didPop) async {
+ onBackPressed(context);
+ },
+ child: Scaffold(
+ appBar: const SysAppBar(title: Text('外观设置')),
+ body: Column(
+ children: [
+ ListTile(
+ onTap: () async {
+ final List<Map<String, dynamic>> colorThemes = colorThemeTypes;
+ SmartDialog.show(
+ useAnimation: false,
+ builder: (context) {
+ return AlertDialog(
+ title: const Text('配色方案'),
+ content: StatefulBuilder(builder:
+ (BuildContext context, StateSetter setState) {
+ return Wrap(
+ alignment: WrapAlignment.center,
+ spacing: 22,
+ runSpacing: 18,
+ children: [
+ ...colorThemes.map(
+ (e) {
+ final index = colorThemes.indexOf(e);
+ return GestureDetector(
+ onTap: () {
+ index == 0
+ ? resetTheme()
+ : setTheme(e['color']);
+ SmartDialog.dismiss();
+ },
+ child: Column(
+ children: [
+ Container(
+ width: 46,
+ height: 46,
+ decoration: BoxDecoration(
+ color: e['color'].withOpacity(0.8),
+ borderRadius:
+ BorderRadius.circular(50),
+ border: Border.all(
+ width: 2,
+ color:
+ e['color'].withOpacity(0.8),
+ ),
+ ),
+ child: const AnimatedOpacity(
+ opacity: 0,
+ duration:
+ Duration(milliseconds: 200),
+ child: Icon(
+ Icons.done,
+ color: Colors.black,
+ size: 20,
+ ),
+ ),
+ ),
+ const SizedBox(height: 3),
+ Text(
+ e['label'],
+ style: TextStyle(
+ fontSize: 12,
+ color: Theme.of(context)
+ .colorScheme
+ .outline,
+ ),
+ ),
+ ],
+ ),
+ );
+ },
+ )
+ ],
+ );
+ }),
+ );
+ });
+ },
+ dense: false,
+ title: const Text('配色方案'),
+ ),
+ Platform.isAndroid
+ ? ListTile(
+ onTap: () async {
+ Modular.to.pushNamed('/tab/my/theme/display');
+ },
+ dense: false,
+ title: const Text('屏幕帧率'),
+ // trailing: const Icon(Icons.navigate_next),
+ )
+ : Container(),
+ ListTile(
+ onTap: () {
+ SmartDialog.show(
+ useAnimation: false,
+ builder: (context) {
+ return AlertDialog(
+ title: const Text('主题模式'),
+ content: StatefulBuilder(
+ builder:
+ (BuildContext context, StateSetter setState) {
+ return Wrap(
+ spacing: 8,
+ runSpacing: 2,
+ children: [
+ defaultThemeMode == 'system'
+ ? FilledButton(
+ onPressed: () {
+ updateTheme('system');
+ SmartDialog.dismiss();
+ },
+ child: const Text("跟随系统"))
+ : FilledButton.tonal(
+ onPressed: () {
+ updateTheme('system');
+ SmartDialog.dismiss();
+ },
+ child: const Text("跟随系统")),
+ defaultThemeMode == 'light'
+ ? FilledButton(
+ onPressed: () {
+ updateTheme('light');
+ SmartDialog.dismiss();
+ },
+ child: const Text("浅色"))
+ : FilledButton.tonal(
+ onPressed: () {
+ updateTheme('light');
+ SmartDialog.dismiss();
+ },
+ child: const Text("浅色")),
+ defaultThemeMode == 'dark'
+ ? FilledButton(
+ onPressed: () {
+ updateTheme('dark');
+ SmartDialog.dismiss();
+ },
+ child: const Text("深色"))
+ : FilledButton.tonal(
+ onPressed: () {
+ updateTheme('dark');
+ SmartDialog.dismiss();
+ },
+ child: const Text("深色")),
+ ],
+ );
+ },
+ ),
+ );
+ });
+ },
+ dense: false,
+ title: const Text('主题模式'),
+ subtitle: Text(
+ defaultThemeMode == 'light'
+ ? '浅色'
+ : (defaultThemeMode == 'dark' ? '深色' : '跟随系统'),
+ style: Theme.of(context)
+ .textTheme
+ .labelMedium!
+ .copyWith(color: Theme.of(context).colorScheme.outline)),
+ ),
+ InkWell(
+ child: SetSwitchItem(
+ title: 'OLED优化',
+ subTitle: '深色模式下使用纯黑背景',
+ setKey: SettingBoxKey.oledEnhance,
+ callFn: (_) => {updateOledEnhance()},
+ defaultVal: false,
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}
diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart
index 8e3cba22..9704ce83 100644
--- a/lib/utils/utils.dart
+++ b/lib/utils/utils.dart
@@ -345,4 +345,18 @@ class Utils {
return Api.version;
}
}
+
+ static oledDarkTheme(ThemeData defaultDarkTheme) {
+ return defaultDarkTheme.copyWith(
+ scaffoldBackgroundColor: Colors.black,
+ colorScheme: defaultDarkTheme.colorScheme.copyWith(
+ onPrimary: Colors.black,
+ onSecondary: Colors.black,
+ // background: Colors.black,
+ // onBackground: Colors.black,
+ surface: Colors.black,
+ onSurface: Colors.white,
+ ),
+ );
+ }
}