基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
feat: support multiple actions in error widget (#756)
ErBW_s76a94e59f185
diff --git a/lib/bean/widget/error_widget.dart b/lib/bean/widget/error_widget.dartindex 8d6cdc56..a60302e7 100644--- a/lib/bean/widget/error_widget.dart+++ b/lib/bean/widget/error_widget.dart@@ -1,17 +1,14 @@import 'package:flutter/material.dart';class GeneralErrorWidget extends StatelessWidget {- const GeneralErrorWidget(- {required this.errMsg,- this.fn,- this.showButton = true,- this.btnText,- super.key});+ const GeneralErrorWidget({+ required this.errMsg,+ this.actions,+ super.key,+ });- final String? errMsg;- final bool showButton;- final Function()? fn;- final String? btnText;+ final String errMsg;+ final List<Widget>? actions;@overrideWidget build(BuildContext context) {@@ -19,7 +16,6 @@ class GeneralErrorWidget extends StatelessWidget {crossAxisAlignment: CrossAxisAlignment.center,mainAxisAlignment: MainAxisAlignment.center,children: [- const SizedBox(height: 30),LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) {return ConstrainedBox(@@ -27,7 +23,7 @@ class GeneralErrorWidget extends StatelessWidget {maxWidth: constraints.maxWidth * 2 / 3,),child: Text(- errMsg ?? '请求异常',+ errMsg,textAlign: TextAlign.center,style: Theme.of(context).textTheme.titleSmall,),@@ -35,19 +31,41 @@ class GeneralErrorWidget extends StatelessWidget {},),const SizedBox(height: 20),- showButton ? FilledButton.tonal(- onPressed: fn,- style: ButtonStyle(- backgroundColor: WidgetStateProperty.resolveWith((states) {- return Theme.of(context).colorScheme.primary.withAlpha(20);- }),+ if (actions != null)+ Wrap(+ alignment: WrapAlignment.center,+ spacing: 8,+ runSpacing: 8,+ children: actions!,),- child: Text(- btnText ?? '点击重试',- style: TextStyle(color: Theme.of(context).colorScheme.primary),- ),- ) : Container(),],);}}++class GeneralErrorButton extends StatelessWidget {+ const GeneralErrorButton({+ super.key,+ required this.onPressed,+ required this.text,+ });++ final Function() onPressed;+ final String text;++ @override+ Widget build(BuildContext context) {+ return FilledButton.tonal(+ onPressed: onPressed,+ style: ButtonStyle(+ backgroundColor: WidgetStateProperty.resolveWith((_) {+ return Theme.of(context).colorScheme.primary.withAlpha(20);+ }),+ ),+ child: Text(+ text,+ style: TextStyle(color: Theme.of(context).colorScheme.primary),+ ),+ );+ }+}diff --git a/lib/pages/about/about_page.dart b/lib/pages/about/about_page.dartindex fcb9cd52..052a5df2 100644--- a/lib/pages/about/about_page.dart+++ b/lib/pages/about/about_page.dart@@ -199,6 +199,7 @@ class _AboutPageState extends State<AboutPage> {onPressed: (_) {KazumiDialog.show(builder: (context) {return SimpleDialog(+ clipBehavior: Clip.antiAlias,title: const Text('关闭时'),children: [for (int i = 0; i < 3; i++)diff --git a/lib/pages/error/storage_error_page.dart b/lib/pages/error/storage_error_page.dartindex c9af50b0..67de7d4d 100644--- a/lib/pages/error/storage_error_page.dart+++ b/lib/pages/error/storage_error_page.dart@@ -16,10 +16,14 @@ class StorageErrorPage extends StatelessWidget {body: Center(child: GeneralErrorWidget(errMsg: '存储初始化错误: 检测到一个Kazumi实例已在运行, 请勿重复启动该程序。(0x02)',- btnText: '退出程序',- fn: () {- exit(0);- },+ actions: [+ GeneralErrorButton(+ onPressed: () {+ exit(0);+ },+ text: '退出程序',+ ),+ ],),),);diff --git a/lib/pages/info/info_page.dart b/lib/pages/info/info_page.dartindex 55d75291..f138c3ec 100644--- a/lib/pages/info/info_page.dart+++ b/lib/pages/info/info_page.dart@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';import 'package:flutter_modular/flutter_modular.dart';import 'package:kazumi/bean/dialog/dialog_helper.dart';import 'package:kazumi/bean/widget/error_widget.dart';+import 'package:kazumi/pages/collect/collect_controller.dart';import 'package:kazumi/pages/info/info_controller.dart';import 'package:kazumi/bean/card/bangumi_info_card.dart';import 'package:flutter_mobx/flutter_mobx.dart';@@ -28,6 +29,7 @@ class InfoPage extends StatefulWidget {class _InfoPageState extends State<InfoPage>with SingleTickerProviderStateMixin {final InfoController infoController = Modular.get<InfoController>();+ final CollectController collectController = Modular.get<CollectController>();final VideoPageController videoPageController =Modular.get<VideoPageController>();final PluginsController pluginsController = Modular.get<PluginsController>();@@ -74,26 +76,124 @@ class _InfoPageState extends State<InfoPage>void showAliasSearchDialog(String pluginName) {if (infoController.bangumiItem.alias.isEmpty) {- KazumiDialog.showToast(message: '无可用别名');+ KazumiDialog.showToast(message: '无可用别名,试试手动检索');return;}+ final aliasNotifier =+ ValueNotifier<List<String>>(infoController.bangumiItem.alias);KazumiDialog.show(builder: (context) {return Dialog(- child: ListView(- shrinkWrap: true,- children: infoController.bangumiItem.alias- .map((alias) => ListTile(+ clipBehavior: Clip.antiAlias,+ child: ValueListenableBuilder<List<String>>(+ valueListenable: aliasNotifier,+ builder: (context, aliasList, child) {+ return ListView(+ shrinkWrap: true,+ children: aliasList.asMap().entries.map((entry) {+ final index = entry.key;+ final alias = entry.value;+ return ListTile(title: Text(alias),+ trailing: IconButton(+ onPressed: () {+ KazumiDialog.show(+ builder: (context) {+ return AlertDialog(+ title: const Text('删除确认'),+ content: const Text('删除后无法恢复,确认要永久删除这个别名吗?'),+ actions: [+ TextButton(+ onPressed: () {+ KazumiDialog.dismiss();+ },+ child: Text(+ '取消',+ style: TextStyle(+ color: Theme.of(context)+ .colorScheme+ .outline),+ ),+ ),+ TextButton(+ onPressed: () {+ KazumiDialog.dismiss();+ aliasList.removeAt(index);+ aliasNotifier.value = List.from(aliasList);+ collectController.updateLocalCollect(+ infoController.bangumiItem);+ if (aliasList.isEmpty) {+ // pop whole dialog when empty+ Navigator.of(context).pop();+ }+ },+ child: const Text('确认'),+ ),+ ],+ );+ },+ );+ },+ icon: Icon(Icons.delete),+ ),onTap: () {KazumiDialog.dismiss();queryManager.querySource(alias, pluginName);},- ))- .toList(),- ));+ );+ }).toList(),+ );+ },+ ),+ );});}+ void showCustomSearchDialog(String pluginName) {+ KazumiDialog.show(+ builder: (context) {+ final TextEditingController textController = TextEditingController();+ return AlertDialog(+ title: const Text('输入别名'),+ content: TextField(+ controller: textController,+ onSubmitted: (keyword) {+ if (textController.text != '') {+ infoController.bangumiItem.alias.add(textController.text);+ KazumiDialog.dismiss();+ queryManager.querySource(textController.text, pluginName);+ }+ },+ ),+ actions: [+ TextButton(+ onPressed: () {+ KazumiDialog.dismiss();+ },+ child: Text(+ '取消',+ style: TextStyle(color: Theme.of(context).colorScheme.outline),+ ),+ ),+ TextButton(+ onPressed: () {+ if (textController.text != '') {+ infoController.bangumiItem.alias.add(textController.text);+ collectController+ .updateLocalCollect(infoController.bangumiItem);+ KazumiDialog.dismiss();+ queryManager.querySource(textController.text, pluginName);+ }+ },+ child: const Text(+ '确认',+ ),+ ),+ ],+ );+ },+ );+ }+@overrideWidget build(BuildContext context) {return PopScope(@@ -246,28 +346,40 @@ class _InfoPageState extends State<InfoPage>? GeneralErrorWidget(errMsg:'${plugin.name} 检索失败 重试或左右滑动以切换到其他视频来源',- btnText: '重试',- fn: () {- queryManager.querySource(- popularController.keyword,- plugin.name);- })+ actions: [+ GeneralErrorButton(+ onPressed: () {+ queryManager.querySource(+ popularController.keyword,+ plugin.name);+ },+ text: '重试',+ ),+ ],+ ): cardList.isEmpty- ? (infoController- .bangumiItem.alias.isNotEmpty- ? GeneralErrorWidget(- errMsg:- '${plugin.name} 无结果 使用别名或左右滑动以切换到其他视频来源',- btnText: '别名检索',- fn: () {+ ? GeneralErrorWidget(+ errMsg:+ '${plugin.name} 无结果 使用别名或左右滑动以切换到其他视频来源',+ actions: [+ GeneralErrorButton(+ onPressed: () {showAliasSearchDialog(- plugin.name);- })- : GeneralErrorWidget(- errMsg:- '${plugin.name} 无结果 左右滑动以切换到其他视频来源',- showButton: false,- ))+ plugin.name,+ );+ },+ text: '别名检索',+ ),+ GeneralErrorButton(+ onPressed: () {+ showCustomSearchDialog(+ plugin.name,+ );+ },+ text: '手动检索',+ ),+ ],+ ): ListView(children: cardList));}),),diff --git a/lib/pages/plugin_editor/plugin_shop_page.dart b/lib/pages/plugin_editor/plugin_shop_page.dartindex b0967d50..92849b18 100644--- a/lib/pages/plugin_editor/plugin_shop_page.dart+++ b/lib/pages/plugin_editor/plugin_shop_page.dart@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';import 'package:flutter_mobx/flutter_mobx.dart';import 'package:flutter_modular/flutter_modular.dart';import 'package:kazumi/bean/dialog/dialog_helper.dart';+import 'package:kazumi/bean/widget/error_widget.dart';import 'package:kazumi/plugins/plugins_controller.dart';import 'package:kazumi/bean/appbar/sys_app_bar.dart';import 'package:hive/hive.dart';@@ -19,6 +20,7 @@ class _PluginShopPageState extends State<PluginShopPage> {bool timeout = false;bool loading = false;late bool enableGitProxy;+// 排序方式状态:false=按更新时间排序,true=按名称排序bool sortByName = false;final PluginsController pluginsController = Modular.get<PluginsController>();@@ -187,28 +189,24 @@ class _PluginShopPageState extends State<PluginShopPage> {Widget get timeoutWidget {return Center(- child: Column(- mainAxisAlignment: MainAxisAlignment.center,- children: [- Text('啊咧(⊙.⊙) 无法访问远程仓库 ${enableGitProxy ? '镜像已启用' : '镜像已禁用'}'),- const SizedBox(- height: 10,- ),- FilledButton.tonal(+ child: GeneralErrorWidget(+ errMsg: '啊咧(⊙.⊙) 无法访问远程仓库\n${enableGitProxy ? '镜像已启用' : '镜像已禁用'}',+ actions: [+ GeneralErrorButton(onPressed: () {Modular.to.pushNamed('/settings/webdav/');},- child: Text(enableGitProxy ? '禁用镜像' : '启用镜像')),- const SizedBox(- height: 10,- ),- FilledButton.tonal(+ text: enableGitProxy ? '禁用镜像' : '启用镜像',+ ),+ GeneralErrorButton(onPressed: () {_handleRefresh();},- child: const Text('刷新'))- ],- ));+ text: '刷新',+ ),+ ],+ ),+ );}@overridediff --git a/lib/pages/popular/popular_page.dart b/lib/pages/popular/popular_page.dartindex cbe10a53..e17cf201 100644--- a/lib/pages/popular/popular_page.dart+++ b/lib/pages/popular/popular_page.dart@@ -106,7 +106,8 @@ class _PopularPageState extends State<PopularPage>child: Scaffold(appBar: SysAppBar(needTopOffset: false,- leadingWidth: 66, // default 56 + 10+ // default 56 + 10+ leadingWidth: 66,leading: (navigationBarState.isBottom)? Row(children: [@@ -182,10 +183,7 @@ class _PopularPageState extends State<PopularPage>children: [SizedBox(height: showTagFilter ? 50 : 0,- child: Padding(- padding: const EdgeInsets.fromLTRB(0, 0, 14, 0),- child: tagFilter(),- ),+ child: tagFilter(),),Expanded(child: CustomScrollView(@@ -218,9 +216,15 @@ class _PopularPageState extends State<PopularPage>height: 400,child: GeneralErrorWidget(errMsg: '什么都没有找到 (´;ω;`)',- fn: () {- popularController.queryBangumiList();- },+ actions: [+ GeneralErrorButton(+ onPressed: () {+ popularController+ .queryBangumiList();+ },+ text: '点击重试',+ ),+ ],),),);@@ -296,7 +300,6 @@ class _PopularPageState extends State<PopularPage>'搞笑','奇幻','百合',- '异世界','恋爱','悬疑','热血',@@ -305,6 +308,7 @@ class _PopularPageState extends State<PopularPage>'轻改','偶像','治愈',+ '异世界',];final ScrollController tagScrollController = ScrollController();