Skip to content

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

feat(ui): redesign and unify error states

Predidita530f7033bbc
diff --git a/lib/bean/widget/bangumi_mirror_error_widget.dart b/lib/bean/widget/bangumi_mirror_error_widget.dart
index 4dcb34f2..e0d9b4ff 100644
--- a/lib/bean/widget/bangumi_mirror_error_widget.dart
+++ b/lib/bean/widget/bangumi_mirror_error_widget.dart
@@ -18,18 +18,18 @@ class BangumiMirrorErrorWidget extends StatelessWidget {
final mirrorEnabled = GStorage.getSetting(SettingsKeys.enableBangumiProxy);
return GeneralErrorWidget(
- errMsg: '啊咧(⊙.⊙) 无法加载数据\nBangumi 镜像${mirrorEnabled ? '已启用' : '已禁用'}',
+ title: '暂时无法加载番剧',
+ errMsg: '请检查网络连接,或调整镜像设置后重试。\nBangumi 镜像${mirrorEnabled ? '已启用' : '已禁用'}',
+ icon: Icons.cloud_off_rounded,
+ onRetry: onRetry,
actions: [
- GeneralErrorButton(
+ GeneralErrorButton.tonal(
onPressed: () async {
await context.pushNamed('/settings/webdav/');
onSettingsReturned?.call();
},
- text: '镜像开关',
- ),
- GeneralErrorButton(
- onPressed: onRetry,
- text: '点击重试',
+ icon: Icons.tune_rounded,
+ text: '镜像设置',
),
],
);
diff --git a/lib/bean/widget/error_widget.dart b/lib/bean/widget/error_widget.dart
index a60302e7..e29e7195 100644
--- a/lib/bean/widget/error_widget.dart
+++ b/lib/bean/widget/error_widget.dart
@@ -1,71 +1,165 @@
import 'package:flutter/material.dart';
+import 'package:material_new_shapes/material_new_shapes.dart';
+/// Shrink-wraps in slivers and scrolls within bounded page or media surfaces.
class GeneralErrorWidget extends StatelessWidget {
const GeneralErrorWidget({
required this.errMsg,
- this.actions,
+ this.title = '出了点问题',
+ this.icon = Icons.error_outline_rounded,
+ this.onRetry,
+ this.retryText = '重试',
+ this.actions = const [],
+ this.compact = false,
super.key,
});
+ final String title;
final String errMsg;
- final List<Widget>? actions;
+ final IconData icon;
+ final VoidCallback? onRetry;
+ final String retryText;
+ final List<Widget> actions;
+ final bool compact;
@override
Widget build(BuildContext context) {
- return Column(
- crossAxisAlignment: CrossAxisAlignment.center,
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- LayoutBuilder(
- builder: (BuildContext context, BoxConstraints constraints) {
- return ConstrainedBox(
- constraints: BoxConstraints(
- maxWidth: constraints.maxWidth * 2 / 3,
+ final theme = Theme.of(context);
+ final colors = theme.colorScheme;
+ final errorActions = [
+ if (onRetry != null)
+ GeneralErrorButton(
+ onPressed: onRetry,
+ text: retryText,
+ icon: Icons.refresh_rounded,
+ ),
+ ...actions,
+ ];
+
+ return Center(
+ child: SingleChildScrollView(
+ primary: false,
+ padding: EdgeInsets.all(compact ? 16 : 24),
+ child: ConstrainedBox(
+ constraints: const BoxConstraints(maxWidth: 440),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ ExcludeSemantics(
+ child: ClipPath(
+ clipper: const _ErrorShapeClipper(),
+ child: ColoredBox(
+ color: colors.errorContainer,
+ child: SizedBox.square(
+ dimension: compact ? 48 : 80,
+ child: Icon(icon,
+ size: compact ? 24 : 36,
+ color: colors.onErrorContainer),
+ ),
+ ),
+ ),
),
- child: Text(
- errMsg,
- textAlign: TextAlign.center,
- style: Theme.of(context).textTheme.titleSmall,
+ SizedBox(height: compact ? 16 : 24),
+ Semantics(
+ liveRegion: true,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Semantics(
+ header: true,
+ child: Text(
+ title,
+ textAlign: TextAlign.center,
+ style: (compact
+ ? theme.textTheme.titleMedium
+ : theme.textTheme.headlineSmall)
+ ?.copyWith(
+ color: colors.onSurface,
+ fontWeight: FontWeight.w700),
+ ),
+ ),
+ if (errMsg.isNotEmpty) ...[
+ const SizedBox(height: 8),
+ Text(
+ errMsg,
+ textAlign: TextAlign.center,
+ style: theme.textTheme.bodyMedium
+ ?.copyWith(color: colors.onSurfaceVariant),
+ ),
+ ],
+ ],
+ ),
),
- );
- },
- ),
- const SizedBox(height: 20),
- if (actions != null)
- Wrap(
- alignment: WrapAlignment.center,
- spacing: 8,
- runSpacing: 8,
- children: actions!,
+ if (errorActions.isNotEmpty) ...[
+ SizedBox(height: compact ? 16 : 24),
+ Wrap(
+ alignment: WrapAlignment.center,
+ spacing: 8,
+ runSpacing: 8,
+ children: errorActions,
+ ),
+ ],
+ ],
),
- ],
+ ),
+ ),
);
}
}
+class _ErrorShapeClipper extends CustomClipper<Path> {
+ const _ErrorShapeClipper();
+
+ static final _path = MaterialShapes.cookie4Sided.toPath();
+
+ @override
+ Path getClip(Size size) => _path
+ .transform(Matrix4.diagonal3Values(size.width, size.height, 1).storage);
+
+ @override
+ bool shouldReclip(_ErrorShapeClipper oldClipper) => false;
+}
+
class GeneralErrorButton extends StatelessWidget {
const GeneralErrorButton({
super.key,
required this.onPressed,
required this.text,
- });
+ this.icon,
+ }) : _tonal = false;
+
+ const GeneralErrorButton.tonal({
+ super.key,
+ required this.onPressed,
+ required this.text,
+ this.icon,
+ }) : _tonal = true;
- final Function() onPressed;
+ final VoidCallback? onPressed;
final String text;
+ final IconData? icon;
+ final bool _tonal;
@override
Widget build(BuildContext context) {
- return FilledButton.tonal(
+ final style = ButtonStyle(
+ minimumSize: const WidgetStatePropertyAll(Size(64, 48)),
+ padding: const WidgetStatePropertyAll(
+ EdgeInsets.symmetric(horizontal: 24, vertical: 12)),
+ shape: WidgetStateProperty.resolveWith((states) => RoundedRectangleBorder(
+ borderRadius: BorderRadius.circular(
+ states.contains(WidgetState.pressed) ? 16 : 28),
+ )),
+ animationDuration: MediaQuery.disableAnimationsOf(context)
+ ? Duration.zero
+ : const Duration(milliseconds: 200),
+ );
+ final button = _tonal ? FilledButton.tonalIcon : FilledButton.icon;
+ return button(
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),
- ),
+ style: style,
+ icon: icon == null ? null : Icon(icon, size: 20),
+ label: Text(text, textAlign: TextAlign.center),
);
}
}
diff --git a/lib/bean/widget/image_preview.dart b/lib/bean/widget/image_preview.dart
index 918a9512..417b88aa 100644
--- a/lib/bean/widget/image_preview.dart
+++ b/lib/bean/widget/image_preview.dart
@@ -6,6 +6,7 @@ import 'package:photo_view/photo_view.dart';
import 'package:photo_view/photo_view_gallery.dart';
import 'package:kazumi/bean/widget/loading_indicator.dart';
+import 'package:kazumi/bean/widget/media_error_widget.dart';
import 'package:kazumi/utils/device.dart';
class ImageViewerRouteArgs {
@@ -263,27 +264,11 @@ class _ImageViewerState extends State<ImageViewer> {
);
}
- Widget _buildErrorWidget(BuildContext context) {
- return Center(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- Icon(
- Icons.broken_image,
- size: 48,
- color: Theme.of(context).colorScheme.onErrorContainer,
- ),
- const SizedBox(height: 8),
- Text(
- '图片加载失败',
- style: TextStyle(
- color: Theme.of(context).colorScheme.onErrorContainer,
- ),
- ),
- ],
- ),
- );
- }
+ Widget _buildErrorWidget() => const MediaErrorWidget(
+ title: '图片加载失败',
+ errMsg: '请检查网络连接,返回后重新打开图片。',
+ icon: Icons.broken_image_outlined,
+ );
Widget _buildSingleImage() {
return Listener(
@@ -303,8 +288,7 @@ class _ImageViewerState extends State<ImageViewer> {
loadingBuilder: (context, event) => const Center(
child: LoadingIndicator(),
),
- errorBuilder: (context, error, stackTrace) =>
- _buildErrorWidget(context),
+ errorBuilder: (context, error, stackTrace) => _buildErrorWidget(),
),
),
);
@@ -343,8 +327,7 @@ class _ImageViewerState extends State<ImageViewer> {
heroAttributes: index == _currentIndex
? PhotoViewHeroAttributes(tag: _heroTagForIndex(index))
: null,
- errorBuilder: (context, error, stackTrace) =>
- _buildErrorWidget(context),
+ errorBuilder: (context, error, stackTrace) => _buildErrorWidget(),
);
},
),
diff --git a/lib/bean/widget/media_error_widget.dart b/lib/bean/widget/media_error_widget.dart
new file mode 100644
index 00000000..efb863f1
--- /dev/null
+++ b/lib/bean/widget/media_error_widget.dart
@@ -0,0 +1,35 @@
+import 'package:flutter/material.dart';
+import 'package:kazumi/bean/widget/error_widget.dart';
+
+class MediaErrorWidget extends StatelessWidget {
+ const MediaErrorWidget({
+ super.key,
+ required this.title,
+ required this.errMsg,
+ required this.icon,
+ });
+
+ final String title;
+ final String errMsg;
+ final IconData icon;
+
+ @override
+ Widget build(BuildContext context) {
+ final theme = Theme.of(context);
+ // Media surfaces stay black regardless of the app theme.
+ return Theme(
+ data: theme.copyWith(
+ colorScheme: ColorScheme.fromSeed(
+ seedColor: theme.colorScheme.primary,
+ brightness: Brightness.dark,
+ ),
+ ),
+ child: GeneralErrorWidget(
+ title: title,
+ errMsg: errMsg,
+ icon: icon,
+ compact: true,
+ ),
+ );
+ }
+}
diff --git a/lib/pages/error/storage_error_page.dart b/lib/pages/error/storage_error_page.dart
index 6a5ba0d1..16405f5c 100644
--- a/lib/pages/error/storage_error_page.dart
+++ b/lib/pages/error/storage_error_page.dart
@@ -15,29 +15,29 @@ class StorageErrorPage extends StatelessWidget {
appBar: AppBar(
title: const Text('内部错误'),
),
- body: Center(
- child: FutureBuilder<Directory>(
- future: getApplicationSupportDirectory(),
- builder: (context, snapshot) {
- if (snapshot.connectionState == ConnectionState.done) {
- final supportDir = snapshot.data;
- final path = supportDir != null ? '$supportDir' : '未知路径';
- return GeneralErrorWidget(
- errMsg: '存储初始化错误 \n 当前储存位置 $path \n 尝试删除该目录以重置本地存储',
- actions: [
- GeneralErrorButton(
- onPressed: () {
- exit(0);
- },
- text: '退出程序',
- ),
- ],
- );
- } else {
- return const LoadingIndicator();
- }
- },
- ),
+ body: FutureBuilder<Directory>(
+ future: getApplicationSupportDirectory(),
+ builder: (context, snapshot) {
+ if (snapshot.connectionState == ConnectionState.done) {
+ final path = snapshot.data?.path ?? '未知路径';
+ return GeneralErrorWidget(
+ title: '无法初始化本地存储',
+ icon: Icons.storage_rounded,
+ errMsg: '当前存储位置:\n$path\n\n可在退出后删除该目录以重置本地存储,此操作会清除本地数据。',
+ actions: [
+ GeneralErrorButton(
+ onPressed: () {
+ exit(0);
+ },
+ text: '退出程序',
+ icon: Icons.close_rounded,
+ ),
+ ],
+ );
+ } else {
+ return const Center(child: LoadingIndicator());
+ }
+ },
),
);
}
diff --git a/lib/pages/index_module.dart b/lib/pages/index_module.dart
index e7eb5ad1..26ca4380 100644
--- a/lib/pages/index_module.dart
+++ b/lib/pages/index_module.dart
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';
+import 'package:kazumi/bean/widget/error_widget.dart';
import 'package:kazumi/bean/widget/image_preview.dart';
import 'package:kazumi/pages/collect/collect_module.dart';
import 'package:kazumi/pages/index_page.dart';
@@ -91,7 +92,10 @@ final indexModule = createModule(
'/error',
child: (context, state) => Scaffold(
appBar: AppBar(title: const Text('Kazumi')),
- body: const Center(child: Text('初始化失败')),
+ body: const GeneralErrorWidget(
+ title: '初始化失败',
+ errMsg: '请重新启动应用后再试。',
+ ),
),
)
..module(tabModule)
diff --git a/lib/pages/info/character_page.dart b/lib/pages/info/character_page.dart
index bb476c94..ceb3b216 100644
--- a/lib/pages/info/character_page.dart
+++ b/lib/pages/info/character_page.dart
@@ -113,13 +113,9 @@ class _CharacterPageState extends State<CharacterPage> {
final character = _character;
if (character != null && character.id == 0) {
return GeneralErrorWidget(
- errMsg: '人物资料加载失败',
- actions: [
- GeneralErrorButton(
- onPressed: _loadCharacter,
- text: '点击重试',
- ),
- ],
+ title: '人物资料加载失败',
+ errMsg: '请检查网络连接后重试。',
+ onRetry: _loadCharacter,
);
}
@@ -173,13 +169,9 @@ class _CharacterPageState extends State<CharacterPage> {
if (_commentsError) {
return SliverFillRemaining(
child: GeneralErrorWidget(
- errMsg: '什么都没有找到 (´;ω;`)',
- actions: [
- GeneralErrorButton(
- onPressed: _loadComments,
- text: '点击重试',
- ),
- ],
+ title: '人物吐槽加载失败',
+ errMsg: '请检查网络连接后重试。',
+ onRetry: _loadComments,
),
);
}
diff --git a/lib/pages/info/info_tabview.dart b/lib/pages/info/info_tabview.dart
index d8ee81a4..f3a88084 100644
--- a/lib/pages/info/info_tabview.dart
+++ b/lib/pages/info/info_tabview.dart
@@ -69,8 +69,7 @@ class InfoTabView extends StatefulWidget {
State<InfoTabView> createState() => _InfoTabViewState();
}
-class _InfoTabViewState extends State<InfoTabView>
- with SingleTickerProviderStateMixin {
+class _InfoTabViewState extends State<InfoTabView> {
final maxWidth = 950.0;
bool fullIntro = false;
bool fullTag = false;
@@ -109,8 +108,6 @@ class _InfoTabViewState extends State<InfoTabView>
children: [
Text('简介', style: TextStyle(fontSize: 18)),
const SizedBox(height: 8),
- // https://stackoverflow.com/questions/54091055/flutter-how-to-get-the-number-of-text-lines
- // only show expand button when line > 7
LayoutBuilder(builder: (context, constraints) {
final span = TextSpan(text: widget.bangumiItem.summary);
final tp =
@@ -122,7 +119,6 @@ class _InfoTabViewState extends State<InfoTabView>
crossAxisAlignment: CrossAxisAlignment.end,
children: [
SizedBox(
- // make intro expandable
height: fullIntro ? null : 120,
width: MediaQuery.sizeOf(context).width > maxWidth
? maxWidth
@@ -167,7 +163,6 @@ class _InfoTabViewState extends State<InfoTabView>
? widget.bangumiItem.tags.length
: 13, (int index) {
if (!fullTag && index == 12) {
- // make tag expandable
return ActionChip(
label: Text(
'更多 +',
@@ -226,13 +221,9 @@ class _InfoTabViewState extends State<InfoTabView>
return SliverFillRemaining(
hasScrollBody: false,
child: GeneralErrorWidget(
- errMsg: '获取关联条目失败,请重试',
- actions: [
- GeneralErrorButton(
- onPressed: widget.loadRelations,
- text: '重试',
- ),
- ],
+ title: '关联条目加载失败',
+ errMsg: '请检查网络连接后重试。',
+ onRetry: widget.loadRelations,
),
);
}
@@ -304,7 +295,6 @@ class _InfoTabViewState extends State<InfoTabView>
);
}
- /// Bone for Skeleton Loader
Widget get infoBodyBone {
return Center(
child: Padding(
@@ -343,6 +333,10 @@ class _InfoTabViewState extends State<InfoTabView>
builder: (BuildContext context) {
return NotificationListener<ScrollEndNotification>(
onNotification: (scrollEnd) {
+ // Scrolling a long error message must not trigger pagination.
+ if (scrollEnd.depth != 0) {
+ return false;
+ }
final metrics = scrollEnd.metrics;
if (metrics.pixels >= metrics.maxScrollExtent - 200) {
widget.loadMoreComments(loadMore: widget.commentsList.isNotEmpty);
@@ -430,16 +424,9 @@ class _InfoTabViewState extends State<InfoTabView>
if (widget.commentsQueryTimeout) {
return SliverFillRemaining(
child: GeneralErrorWidget(
- errMsg: '获取失败,请重试',
- actions: [
- GeneralErrorButton(
- onPressed: () {
- widget.loadMoreComments(
- loadMore: widget.commentsList.isNotEmpty);
- },
- text: '重试',
- ),
- ],
+ title: '评论加载失败',
+ errMsg: '请检查网络连接后重试。',
+ onRetry: () => widget.loadMoreComments(loadMore: false),
),
);
}
@@ -514,15 +501,9 @@ class _InfoTabViewState extends State<InfoTabView>
if (widget.staffQueryTimeout) {
return SliverFillRemaining(
child: GeneralErrorWidget(
- errMsg: '获取失败,请重试',
- actions: [
- GeneralErrorButton(
- onPressed: () {
- widget.loadStaff();
- },
- text: '重试',
- ),
- ],
+ title: '制作人员加载失败',
+ errMsg: '请检查网络连接后重试。',
+ onRetry: widget.loadStaff,
),
);
}
@@ -596,15 +577,9 @@ class _InfoTabViewState extends State<InfoTabView>
if (widget.charactersQueryTimeout) {
return SliverFillRemaining(
child: GeneralErrorWidget(
- errMsg: '获取失败,请重试',
- actions: [
- GeneralErrorButton(
- onPressed: () {
- widget.loadCharacters();
- },
- text: '重试',
- ),
- ],
+ title: '角色列表加载失败',
+ errMsg: '请检查网络连接后重试。',
+ onRetry: widget.loadCharacters,
),
);
}
@@ -648,18 +623,12 @@ class _InfoTabViewState extends State<InfoTabView>
controller: widget.tabController,
children: [
Builder(
- // This Builder is needed to provide a BuildContext that is
- // "inside" the NestedScrollView, so that
- // sliverOverlapAbsorberHandleFor() can find the
- // NestedScrollView.
+ // Resolve the overlap handle inside the NestedScrollView.
builder: (BuildContext context) {
return CustomScrollView(
scrollBehavior: const ScrollBehavior().copyWith(
scrollbars: false,
),
- // The PageStorageKey should be unique to this ScrollView;
- // it allows the list to remember its scroll position when
- // the tab view is not on the screen.
key: PageStorageKey<String>('概览'),
slivers: <Widget>[
SliverOverlapInjector(
diff --git a/lib/pages/logs/logs_page.dart b/lib/pages/logs/logs_page.dart
index 1112f2df..de5cb4aa 100644
--- a/lib/pages/logs/logs_page.dart
+++ b/lib/pages/logs/logs_page.dart
@@ -8,6 +8,7 @@ import 'package:path_provider/path_provider.dart';
import 'package:kazumi/bean/appbar/sys_app_bar.dart';
import 'package:kazumi/bean/dialog/dialog_helper.dart';
import 'package:kazumi/bean/widget/empty_state_widget.dart';
+import 'package:kazumi/bean/widget/error_widget.dart';
import 'package:kazumi/bean/widget/loading_indicator.dart';
class LogsPage extends StatefulWidget {
@@ -60,6 +61,10 @@ class _LogsPageState extends State<LogsPage> {
Future<void> _loadLogs() async {
if (!mounted) return;
+ setState(() {
+ _isLoading = true;
+ _hasError = false;
+ });
try {
final file = await _getLogsFile();
@@ -76,7 +81,6 @@ class _LogsPageState extends State<LogsPage> {
? _allLines.length
: _initialLoadCount;
- if (!mounted) return;
setState(() {
_logLines.clear();
_logLines.addAll(_allLines.take(initialCount));
@@ -89,7 +93,7 @@ class _LogsPageState extends State<LogsPage> {
_isLoading = false;
});
}
- } catch (e) {
+ } catch (_) {
if (!mounted) return;
setState(() {
_hasError = true;
@@ -112,7 +116,6 @@ class _LogsPageState extends State<LogsPage> {
final newLines = _allLines.skip(_displayedLines).take(linesToLoad);
- if (!mounted) return;
setState(() {
_logLines.addAll(newLines);
_displayedLines += linesToLoad;
@@ -174,8 +177,11 @@ class _LogsPageState extends State<LogsPage> {
}
if (_hasError) {
- return const Center(
- child: Text('加载日志失败'),
+ return GeneralErrorWidget(
+ title: '无法读取日志',
+ errMsg: '请稍后重新加载。',
+ icon: Icons.receipt_long_rounded,
+ onRetry: _loadLogs,
);
}
diff --git a/lib/pages/player/episode_comments_view.dart b/lib/pages/player/episode_comments_view.dart
index ca7694e5..b052f7af 100644
--- a/lib/pages/player/episode_comments_view.dart
+++ b/lib/pages/player/episode_comments_view.dart
@@ -2,6 +2,7 @@ import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:kazumi/bean/card/user_comments_card.dart';
+import 'package:kazumi/bean/widget/error_widget.dart';
import 'package:kazumi/bean/widget/loading_indicator.dart';
import 'package:kazumi/modules/bangumi/episode_item.dart';
import 'package:kazumi/modules/comments/comment_item.dart';
@@ -66,29 +67,17 @@ class EpisodeCommentsView extends StatelessWidget {
),
if (!isLoading && hasError && comments.isEmpty)
SliverToBoxAdapter(
- child: _DiscussionState(
+ child: GeneralErrorWidget(
icon: Icons.cloud_off_rounded,
title: '评论暂时未能加载',
- description: '请检查网络后重试,或切换分集查看讨论。',
- action: FilledButton.icon(
- onPressed: onRefresh,
- icon: const Icon(Icons.refresh_rounded, size: 20),
- label: const Text('重新加载'),
- ),
+ errMsg: '请检查网络后重试,或切换分集查看讨论。',
+ onRetry: onRefresh,
+ retryText: '重新加载',
),
)
else if (!isLoading && comments.isEmpty)
SliverToBoxAdapter(
- child: _DiscussionState(
- icon: Icons.chat_bubble_outline_rounded,
- title: '本集还没有讨论',
- description: '换一集看看,或稍后回来刷新。',
- action: FilledButton.tonalIcon(
- onPressed: onSelectEpisode,
- icon: const Icon(Icons.video_library_outlined, size: 20),
- label: const Text('切换分集'),
- ),
- ),
+ child: _EmptyDiscussion(onSelectEpisode: onSelectEpisode),
)
else if (comments.isNotEmpty) ...[
if (hasError)
@@ -328,18 +317,10 @@ class _EpisodeHeader extends StatelessWidget {
}
}
-class _DiscussionState extends StatelessWidget {
- const _DiscussionState({
- required this.title,
- required this.description,
- required this.icon,
- required this.action,
- });
+class _EmptyDiscussion extends StatelessWidget {
+ const _EmptyDiscussion({required this.onSelectEpisode});
- final String title;
- final String description;
- final IconData icon;
- final Widget action;
+ final VoidCallback onSelectEpisode;
@override
Widget build(BuildContext context) {
@@ -356,20 +337,25 @@ class _DiscussionState extends StatelessWidget {
borderRadius: BorderRadius.circular(28),
),
child: Center(
- child: Icon(icon, size: 32, color: colors.onSecondaryContainer),
+ child: Icon(Icons.chat_bubble_outline_rounded,
+ size: 32, color: colors.onSecondaryContainer),
),
),
const SizedBox(height: 20),
- Text(title,
+ Text('本集还没有讨论',
textAlign: TextAlign.center,
style: type.titleMedium?.copyWith(fontWeight: FontWeight.w700)),
const SizedBox(height: 8),
- Text(description,
+ Text('换一集看看,或稍后回来刷新。',
textAlign: TextAlign.center,
style: type.bodyMedium
?.copyWith(color: colors.onSurfaceVariant, height: 1.6)),
const SizedBox(height: 20),
- action,
+ FilledButton.tonalIcon(
+ onPressed: onSelectEpisode,
+ icon: const Icon(Icons.video_library_outlined, size: 20),
+ label: const Text('切换分集'),
+ ),
]),
);
}
diff --git a/lib/pages/plugin_editor/plugin_catalog_view.dart b/lib/pages/plugin_editor/plugin_catalog_view.dart
index 64905d21..5b1fdfac 100644
--- a/lib/pages/plugin_editor/plugin_catalog_view.dart
+++ b/lib/pages/plugin_editor/plugin_catalog_view.dart
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:kazumi/bean/card/rule_card.dart';
import 'package:kazumi/bean/dialog/dialog_helper.dart';
+import 'package:kazumi/bean/widget/error_widget.dart';
import 'package:kazumi/bean/widget/loading_indicator.dart';
import 'package:kazumi/modules/plugin/plugin_http_module.dart';
import 'package:kazumi/pages/plugin_editor/plugin_update_actions.dart';
@@ -219,23 +220,19 @@ class _PluginCatalogViewState extends State<PluginCatalogView> {
}
if (_loadFailed && _controller.pluginHTTPList.isEmpty) {
final enabled = GStorage.getSetting(SettingsKeys.enableGitProxy);
- return RuleEmptyState(
+ return GeneralErrorWidget(
title: '无法访问规则仓库',
- description: '请检查网络连接,或切换规则仓库镜像后重试。',
+ errMsg: '请检查网络连接,或切换规则仓库镜像后重试。',
icon: Icons.cloud_off_rounded,
- action: Wrap(
- alignment: WrapAlignment.center,
- spacing: 8,
- runSpacing: 8,
- children: [
- TextButton(
- onPressed: _toggleGitProxyAndRefresh,
- child: Text(enabled ? '关闭规则镜像' : '启用规则镜像')),
- FilledButton.tonalIcon(
- onPressed: _refresh,
- icon: const Icon(Icons.refresh_rounded),
- label: const Text('重新加载')),
- ]),
+ onRetry: _refresh,
+ retryText: '重新加载',
+ actions: [
+ GeneralErrorButton.tonal(
+ onPressed: _toggleGitProxyAndRefresh,
+ icon: Icons.tune_rounded,
+ text: enabled ? '关闭规则镜像' : '启用规则镜像',
+ ),
+ ],
);
}
return RuleEmptyState(
diff --git a/lib/pages/route_error_page.dart b/lib/pages/route_error_page.dart
index 63bba99e..f71ec160 100644
--- a/lib/pages/route_error_page.dart
+++ b/lib/pages/route_error_page.dart
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:kazumi/bean/appbar/sys_app_bar.dart';
+import 'package:kazumi/bean/widget/error_widget.dart';
class RouteErrorPage extends StatelessWidget {
const RouteErrorPage({
@@ -14,23 +15,16 @@ class RouteErrorPage extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: const SysAppBar(title: Text('Kazumi')),
- body: Center(
- child: Padding(
- padding: const EdgeInsets.all(24),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- const Icon(Icons.error_outline, size: 48),
- const SizedBox(height: 16),
- Text(message, textAlign: TextAlign.center),
- const SizedBox(height: 24),
- FilledButton(
- onPressed: () => context.navigate('/tab/popular/'),
- child: const Text('返回首页'),
- ),
- ],
+ body: GeneralErrorWidget(
+ title: '无法打开页面',
+ errMsg: message,
+ actions: [
+ GeneralErrorButton(
+ onPressed: () => context.navigate('/tab/popular/'),
+ icon: Icons.home_outlined,
+ text: '返回首页',
),
- ),
+ ],
),
);
}
diff --git a/lib/pages/search/image_search_page.dart b/lib/pages/search/image_search_page.dart
index 11091db4..821cf515 100644
--- a/lib/pages/search/image_search_page.dart
+++ b/lib/pages/search/image_search_page.dart
@@ -12,6 +12,7 @@ import 'package:path/path.dart' as path;
import 'package:url_launcher/url_launcher.dart';
import 'package:kazumi/bean/appbar/sys_app_bar.dart';
+import 'package:kazumi/bean/widget/error_widget.dart';
import 'package:kazumi/bean/widget/loading_indicator.dart';
import 'package:kazumi/modules/search/image_search_module.dart';
import 'package:kazumi/pages/search/search_controller.dart';
diff --git a/lib/pages/search/image_search_widgets.dart b/lib/pages/search/image_search_widgets.dart
index d87ab442..a8990164 100644
--- a/lib/pages/search/image_search_widgets.dart
+++ b/lib/pages/search/image_search_widgets.dart
@@ -151,16 +151,20 @@ class _ImageSearchResults extends StatelessWidget {
);
}
if (results.isEmpty) {
- final noMatch = error == '未找到匹配结果';
+ if (error != '未找到匹配结果') {
+ return GeneralErrorWidget(
+ title: '这次识别未完成',
+ errMsg: error,
+ icon: Icons.wifi_off_rounded,
+ onRetry: onRetry,
+ retryText: '重新识别',
+ );
+ }
return _ResultStatus(
- icon: Icon(
- noMatch
- ? Icons.image_not_supported_outlined
- : Icons.wifi_off_rounded,
- size: 48,
- color: noMatch ? colors.onSurfaceVariant : colors.error),
- title: noMatch ? '还没找到这一幕' : '这次识别未完成',
- description: noMatch ? '试试同一场景的另一张截图,\n保留完整画面与原始比例。' : error,
+ icon: Icon(Icons.image_not_supported_outlined,
+ size: 48, color: colors.onSurfaceVariant),
+ title: '还没找到这一幕',
+ description: '试试同一场景的另一张截图,\n保留完整画面与原始比例。',
action: onRetry == null
? null
: FilledButton.tonalIcon(
diff --git a/lib/pages/video/video_page.dart b/lib/pages/video/video_page.dart
index 0268d168..b2396430 100644
--- a/lib/pages/video/video_page.dart
+++ b/lib/pages/video/video_page.dart
@@ -13,6 +13,7 @@ import 'package:kazumi/bean/dialog/adaptive_bottom_sheet.dart';
import 'package:kazumi/bean/dialog/dialog_helper.dart';
import 'package:kazumi/bean/widget/embedded_native_control_area.dart';
import 'package:kazumi/bean/widget/loading_indicator.dart';
+import 'package:kazumi/bean/widget/media_error_widget.dart';
import 'package:kazumi/modules/download/download_module.dart';
import 'package:kazumi/pages/download/download_controller.dart';
import 'package:kazumi/pages/download/download_episode_sheet.dart';
@@ -648,43 +649,31 @@ class _VideoPageState extends State<VideoPage>
Container(
color: Colors.black,
child: Observer(builder: (context) {
+ final errorMessage = videoPageController.errorMessage;
+ if (errorMessage != null) {
+ return MediaErrorWidget(
+ title: '暂时无法播放',
+ errMsg: errorMessage,
+ icon: Icons.videocam_off_outlined,
+ );
+ }
return Center(
- child: videoPageController.errorMessage != null
- ? Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Icon(Icons.error_outline,
- color: Theme.of(context).colorScheme.error,
- size: 48),
- const SizedBox(height: 16),
- Padding(
- padding: const EdgeInsets.symmetric(
- horizontal: 32),
- child: Text(
- videoPageController.errorMessage!,
- style: const TextStyle(
- color: Colors.white, fontSize: 16),
- textAlign: TextAlign.center,
- ),
- ),
- ],
- )
- : Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- LoadingIndicator(
- color: Theme.of(context)
- .colorScheme
- .tertiaryContainer),
- const SizedBox(height: 10),
- Text(
- videoPageController.loading
- ? '视频资源解析中'
- : '视频资源解析成功, 播放器加载中',
- style: const TextStyle(color: Colors.white),
- ),
- ],
- ),
+ child: Column(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ LoadingIndicator(
+ color: Theme.of(context)
+ .colorScheme
+ .tertiaryContainer),
+ const SizedBox(height: 10),
+ Text(
+ videoPageController.loading
+ ? '视频资源解析中'
+ : '视频资源解析成功, 播放器加载中',
+ style: const TextStyle(color: Colors.white),
+ ),
+ ],
+ ),
);
}),
),