refactor(empty-state): 空状态支持内容居中
This commit is contained in:
1 parent
59fbd33059
commit
7463d3ee26
8 files changed
+131
-80
No files matched your search
@@ -297,6 +297,7 @@ class _DiscoverPageState extends State<DiscoverPage> {
|
||||
icon: Icons.movie_filter_outlined,
|
||||
title: l10n.noStories,
|
||||
subtitle: l10n.emptyHint,
|
||||
stretchContent: true,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -38,7 +38,6 @@ const double _synopsisFontSize = 12;
|
||||
const double _synopsisLineHeight = 1.15;
|
||||
const double _synopsisGap = 4;
|
||||
const int _maxTags = 2;
|
||||
const double _emptyListHeight = 360;
|
||||
const double _loadMoreThreshold = 240;
|
||||
|
||||
final RegExp _tagSplitter = RegExp(r'[,/、·]');
|
||||
@@ -124,37 +123,29 @@ class _FavoritesBody extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
if (favorites.error != null && favorites.cards.isEmpty) {
|
||||
return _refreshable(
|
||||
return _refreshableState(
|
||||
favorites,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: _emptyListHeight,
|
||||
child: EmptyState(
|
||||
key: const Key('favorites-error'),
|
||||
icon: Icons.cloud_off_rounded,
|
||||
title: errorText(l10n, favorites.error, l10n.favoritesError),
|
||||
actionLabel: l10n.retry,
|
||||
actionKey: const Key('favorites-retry'),
|
||||
onAction: () => unawaited(favorites.load()),
|
||||
),
|
||||
),
|
||||
],
|
||||
child: EmptyState(
|
||||
key: const Key('favorites-error'),
|
||||
icon: Icons.cloud_off_rounded,
|
||||
title: errorText(l10n, favorites.error, l10n.favoritesError),
|
||||
actionLabel: l10n.retry,
|
||||
actionKey: const Key('favorites-retry'),
|
||||
onAction: () => unawaited(favorites.load()),
|
||||
stretchContent: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
if (favorites.cards.isEmpty) {
|
||||
return _refreshable(
|
||||
return _refreshableState(
|
||||
favorites,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: _emptyListHeight,
|
||||
child: EmptyState(
|
||||
key: const Key('favorites-empty'),
|
||||
icon: Icons.star_border_rounded,
|
||||
title: l10n.noFavorites,
|
||||
subtitle: l10n.emptyHint,
|
||||
),
|
||||
),
|
||||
],
|
||||
child: EmptyState(
|
||||
key: const Key('favorites-empty'),
|
||||
icon: Icons.star_border_rounded,
|
||||
title: l10n.noFavorites,
|
||||
subtitle: l10n.emptyHint,
|
||||
stretchContent: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
return _refreshable(
|
||||
@@ -205,6 +196,20 @@ class _FavoritesBody extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _refreshableState(
|
||||
FavoriteController favorites, {
|
||||
required Widget child,
|
||||
}) {
|
||||
return AppPullToRefresh(
|
||||
onRefresh: favorites.load,
|
||||
child: CustomScrollView(
|
||||
key: const Key('favorites-empty-scroll'),
|
||||
physics: AppPullToRefresh.physics,
|
||||
slivers: [SliverFillRemaining(hasScrollBody: false, child: child)],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
bool _onScroll(ScrollNotification notification) {
|
||||
if (notification.depth != 0) return false;
|
||||
final reachedBottom =
|
||||
|
||||
@@ -348,6 +348,7 @@ class _RecommendPageState extends State<RecommendPage>
|
||||
key: const Key('recommend-feed-empty'),
|
||||
icon: Icons.movie_outlined,
|
||||
title: l10n.noStories,
|
||||
stretchContent: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import 'widgets/watch_record_card.dart';
|
||||
|
||||
const double _pageHorizontal = 14;
|
||||
const double _statsFontSize = 12;
|
||||
const double _emptyListHeight = 360;
|
||||
const double _loadMoreThreshold = 240;
|
||||
|
||||
/// 独立观看记录页。
|
||||
@@ -113,31 +112,22 @@ class _WatchRecordsBodyState extends State<_WatchRecordsBody> {
|
||||
);
|
||||
}
|
||||
if (controller.error != null && controller.records.isEmpty) {
|
||||
return _refreshable(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: _emptyListHeight,
|
||||
child: _FailureState(
|
||||
message: errorText(l10n, controller.error, l10n.progressError),
|
||||
onRetry: controller.load,
|
||||
),
|
||||
),
|
||||
],
|
||||
return _refreshableState(
|
||||
child: _FailureState(
|
||||
message: errorText(l10n, controller.error, l10n.progressError),
|
||||
onRetry: controller.load,
|
||||
),
|
||||
);
|
||||
}
|
||||
if (controller.records.isEmpty) {
|
||||
return _refreshable(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: _emptyListHeight,
|
||||
child: EmptyState(
|
||||
key: const Key('watch-records-empty'),
|
||||
icon: Icons.history_rounded,
|
||||
title: l10n.noWatchRecords,
|
||||
subtitle: l10n.emptyHint,
|
||||
),
|
||||
),
|
||||
],
|
||||
return _refreshableState(
|
||||
child: EmptyState(
|
||||
key: const Key('watch-records-empty'),
|
||||
icon: Icons.history_rounded,
|
||||
title: l10n.noWatchRecords,
|
||||
subtitle: l10n.emptyHint,
|
||||
stretchContent: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
return _refreshable(
|
||||
@@ -184,6 +174,17 @@ class _WatchRecordsBodyState extends State<_WatchRecordsBody> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _refreshableState({required Widget child}) {
|
||||
return AppPullToRefresh(
|
||||
onRefresh: controller.load,
|
||||
child: CustomScrollView(
|
||||
key: const Key('watch-records-empty-scroll'),
|
||||
physics: AppPullToRefresh.physics,
|
||||
slivers: [SliverFillRemaining(hasScrollBody: false, child: child)],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
bool _onScroll(ScrollNotification notification) {
|
||||
if (notification.depth != 0) return false;
|
||||
final reachedBottom =
|
||||
@@ -303,6 +304,7 @@ class _FailureState extends StatelessWidget {
|
||||
actionLabel: l10n.retry,
|
||||
actionKey: const Key('watch-records-retry'),
|
||||
onAction: () => unawaited(onRetry()),
|
||||
stretchContent: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user