merge: 统一下拉与加载指示器
This commit is contained in:
commit
db8433ace3
26 files changed
+127
-241
No files matched your search
@@ -1282,3 +1282,9 @@ $ flutter test
|
|||||||
- 普通二级页标题栏改为透明、白色标题与返回图标;统一卡片 12 圆角、1px 描边和无阴影策略。
|
- 普通二级页标题栏改为透明、白色标题与返回图标;统一卡片 12 圆角、1px 描边和无阴影策略。
|
||||||
- 覆盖新剧、筛选、榜单、预约、收藏、观看历史、下载、设置、钱包、VIP、通知、详情、登录、关于;播放器沉浸区保持纯黑。
|
- 覆盖新剧、筛选、榜单、预约、收藏、观看历史、下载、设置、钱包、VIP、通知、详情、登录、关于;播放器沉浸区保持纯黑。
|
||||||
- `flutter analyze`:No issues found。
|
- `flutter analyze`:No issues found。
|
||||||
|
|
||||||
|
## 2026-10-22 统一下拉与加载指示器
|
||||||
|
|
||||||
|
- 下拉刷新统一为 40×40、60% 黑底圆角指示器内嵌 20 白色加载圈,不再显示任何状态文字。
|
||||||
|
- 网络分页与本地分页 footer 统一仅显示白色加载圈,无更多状态完全隐藏;通知页补触底自动加载。
|
||||||
|
- 移除不再使用的刷新提示与无更多文案;`flutter analyze`:No issues found。
|
||||||
@@ -187,6 +187,7 @@ abstract final class AppColors {
|
|||||||
|
|
||||||
/// 播放器控件胶囊与圆形底色。
|
/// 播放器控件胶囊与圆形底色。
|
||||||
static const playerOverlayPill = Color(0xB3000000);
|
static const playerOverlayPill = Color(0xB3000000);
|
||||||
|
static const refreshIndicatorSurface = Color(0x99000000);
|
||||||
static const cardBottomScrimStart = Color(0x00000000);
|
static const cardBottomScrimStart = Color(0x00000000);
|
||||||
static const cardBottomScrimEnd = Color(0x40000000);
|
static const cardBottomScrimEnd = Color(0x40000000);
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,11 @@ abstract final class AppDimens {
|
|||||||
static const double progressHeight = 3;
|
static const double progressHeight = 3;
|
||||||
static const double progressRadius = 2;
|
static const double progressRadius = 2;
|
||||||
static const double progressLineHeight = 3;
|
static const double progressLineHeight = 3;
|
||||||
|
static const double refreshIndicatorSize = 40;
|
||||||
|
static const double refreshIndicatorRadius = 20;
|
||||||
|
static const double refreshSpinnerSize = 20;
|
||||||
|
static const double refreshSpinnerStroke = 2;
|
||||||
|
static const double loadMoreIndicatorHeight = 40;
|
||||||
|
|
||||||
static const double searchHeight = 40;
|
static const double searchHeight = 40;
|
||||||
static const double searchRadius = 8;
|
static const double searchRadius = 8;
|
||||||
|
|||||||
@@ -4,19 +4,18 @@ import 'dart:async';
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../../l10n/app_localizations.dart';
|
|
||||||
import '../theme/app_colors.dart';
|
import '../theme/app_colors.dart';
|
||||||
|
import '../theme/app_dimens.dart';
|
||||||
|
|
||||||
const double _maxPullDistance = 96;
|
const double _maxPullDistance = 96;
|
||||||
const double _refreshThreshold = 56;
|
const double _refreshThreshold = 56;
|
||||||
const double _indicatorHeight = 56;
|
const double _indicatorHeight = 56;
|
||||||
const double _indicatorDisplacement = 40;
|
const double _indicatorDisplacement = 40;
|
||||||
const Duration _arrowTurnDuration = Duration(milliseconds: 160);
|
|
||||||
const Duration _settleDuration = Duration(milliseconds: 200);
|
const Duration _settleDuration = Duration(milliseconds: 200);
|
||||||
|
|
||||||
enum _PullState { idle, pull, armed, refreshing }
|
enum _PullState { idle, pull, armed, refreshing }
|
||||||
|
|
||||||
/// 带文字状态提示的下拉刷新容器,指示区悬浮在内容上方。
|
/// 下拉刷新容器,指示区只显示统一的白色加载圈。
|
||||||
class AppPullToRefresh extends StatefulWidget {
|
class AppPullToRefresh extends StatefulWidget {
|
||||||
const AppPullToRefresh({
|
const AppPullToRefresh({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -172,7 +171,7 @@ class _AppPullToRefreshState extends State<AppPullToRefresh>
|
|||||||
top: widget.edgeOffset,
|
top: widget.edgeOffset,
|
||||||
left: 0,
|
left: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
child: IgnorePointer(child: _indicatorLayer(context, offset)),
|
child: IgnorePointer(child: _indicatorLayer(offset)),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@@ -181,7 +180,7 @@ class _AppPullToRefreshState extends State<AppPullToRefresh>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _indicatorLayer(BuildContext context, double offset) {
|
Widget _indicatorLayer(double offset) {
|
||||||
final progress = (offset / _refreshThreshold).clamp(0.0, 1.0);
|
final progress = (offset / _refreshThreshold).clamp(0.0, 1.0);
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
height: _indicatorHeight,
|
height: _indicatorHeight,
|
||||||
@@ -193,7 +192,7 @@ class _AppPullToRefreshState extends State<AppPullToRefresh>
|
|||||||
alignment: Alignment.topCenter,
|
alignment: Alignment.topCenter,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.only(top: 8),
|
padding: const EdgeInsets.only(top: 8),
|
||||||
child: _indicator(context),
|
child: _indicator(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -201,50 +200,25 @@ class _AppPullToRefreshState extends State<AppPullToRefresh>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _indicator(BuildContext context) {
|
Widget _indicator() {
|
||||||
final l10n = AppLocalizations.of(context)!;
|
return Container(
|
||||||
if (_state == _PullState.refreshing) {
|
key: const Key('pull-refresh-indicator'),
|
||||||
return _label(
|
width: AppDimens.refreshIndicatorSize,
|
||||||
const SizedBox.square(
|
height: AppDimens.refreshIndicatorSize,
|
||||||
dimension: 18,
|
padding: const EdgeInsets.all(
|
||||||
child: CircularProgressIndicator(
|
(AppDimens.refreshIndicatorSize - AppDimens.refreshSpinnerSize) / 2,
|
||||||
strokeWidth: 2,
|
),
|
||||||
color: AppColors.navSelected,
|
decoration: BoxDecoration(
|
||||||
),
|
color: AppColors.refreshIndicatorSurface,
|
||||||
),
|
borderRadius: BorderRadius.circular(AppDimens.refreshIndicatorRadius),
|
||||||
l10n.refreshingLabel,
|
),
|
||||||
);
|
child: const SizedBox.square(
|
||||||
}
|
dimension: AppDimens.refreshSpinnerSize,
|
||||||
final armed = _state == _PullState.armed;
|
child: CircularProgressIndicator(
|
||||||
return _label(
|
strokeWidth: AppDimens.refreshSpinnerStroke,
|
||||||
AnimatedRotation(
|
color: AppColors.textPrimary,
|
||||||
turns: armed ? 0.5 : 0,
|
|
||||||
duration: _arrowTurnDuration,
|
|
||||||
child: Icon(
|
|
||||||
Icons.arrow_downward_rounded,
|
|
||||||
size: 18,
|
|
||||||
color: AppColors.navSelected,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
armed ? l10n.releaseToRefresh : l10n.pullToRefresh,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _label(Widget icon, String text) {
|
|
||||||
return Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
icon,
|
|
||||||
const SizedBox(width: 6),
|
|
||||||
Text(
|
|
||||||
text,
|
|
||||||
style: const TextStyle(
|
|
||||||
color: AppColors.navSelected,
|
|
||||||
fontSize: 13,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,22 +5,19 @@ import 'dart:async';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../theme/app_colors.dart';
|
import '../theme/app_colors.dart';
|
||||||
|
import '../theme/app_dimens.dart';
|
||||||
import '../../l10n/app_localizations.dart';
|
import '../../l10n/app_localizations.dart';
|
||||||
|
|
||||||
/// 网络分页列表底部状态:加载、重试、手动加载与无更多。
|
/// 网络分页列表底部状态:仅保留加载圈与错误重试。
|
||||||
class PagedListFooter extends StatelessWidget {
|
class PagedListFooter extends StatelessWidget {
|
||||||
const PagedListFooter({
|
const PagedListFooter({
|
||||||
super.key,
|
super.key,
|
||||||
required this.loading,
|
required this.loading,
|
||||||
required this.hasMore,
|
|
||||||
required this.hasItems,
|
|
||||||
required this.onRetry,
|
required this.onRetry,
|
||||||
this.errorMessage,
|
this.errorMessage,
|
||||||
});
|
});
|
||||||
|
|
||||||
final bool loading;
|
final bool loading;
|
||||||
final bool hasMore;
|
|
||||||
final bool hasItems;
|
|
||||||
final String? errorMessage;
|
final String? errorMessage;
|
||||||
final Future<void> Function() onRetry;
|
final Future<void> Function() onRetry;
|
||||||
|
|
||||||
@@ -49,38 +46,18 @@ class PagedListFooter extends StatelessWidget {
|
|||||||
if (loading) {
|
if (loading) {
|
||||||
return const SizedBox(
|
return const SizedBox(
|
||||||
key: Key('paged-list-loading'),
|
key: Key('paged-list-loading'),
|
||||||
height: 56,
|
height: AppDimens.loadMoreIndicatorHeight,
|
||||||
child: Center(
|
child: Center(
|
||||||
child: SizedBox.square(
|
child: SizedBox.square(
|
||||||
dimension: 20,
|
dimension: AppDimens.refreshSpinnerSize,
|
||||||
child: CircularProgressIndicator(
|
child: CircularProgressIndicator(
|
||||||
strokeWidth: 2,
|
strokeWidth: AppDimens.refreshSpinnerStroke,
|
||||||
color: AppColors.blue,
|
color: AppColors.textPrimary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (hasMore) {
|
return const SizedBox.shrink();
|
||||||
return Center(
|
|
||||||
child: TextButton(
|
|
||||||
key: const Key('paged-list-load-more'),
|
|
||||||
onPressed: () => unawaited(onRetry()),
|
|
||||||
child: Text(l10n.loadMore),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (hasItems) {
|
|
||||||
return Padding(
|
|
||||||
key: const Key('paged-list-no-more'),
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
|
||||||
child: Text(
|
|
||||||
l10n.noMore,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: const TextStyle(color: AppColors.muted, fontSize: 12),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return const SizedBox(height: 16);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../theme/app_colors.dart';
|
import '../theme/app_colors.dart';
|
||||||
|
import '../theme/app_dimens.dart';
|
||||||
|
|
||||||
const int _defaultPageSize = 20;
|
const int _defaultPageSize = 20;
|
||||||
const Duration _defaultLoadDelay = Duration(milliseconds: 300);
|
const Duration _defaultLoadDelay = Duration(milliseconds: 300);
|
||||||
@@ -64,53 +65,34 @@ class PagedLocalListController<T> extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 分页列表底部加载态与到底提示。
|
/// 分页列表底部加载态。
|
||||||
class PagedLoadFooter extends StatelessWidget {
|
class PagedLoadFooter extends StatelessWidget {
|
||||||
const PagedLoadFooter({
|
const PagedLoadFooter({
|
||||||
super.key,
|
super.key,
|
||||||
required this.loading,
|
required this.loading,
|
||||||
required this.hasMore,
|
|
||||||
required this.hasItems,
|
|
||||||
required this.loadMoreKey,
|
required this.loadMoreKey,
|
||||||
required this.noMoreKey,
|
|
||||||
required this.noMoreLabel,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
final bool loading;
|
final bool loading;
|
||||||
final bool hasMore;
|
|
||||||
final bool hasItems;
|
|
||||||
final Key loadMoreKey;
|
final Key loadMoreKey;
|
||||||
final Key noMoreKey;
|
|
||||||
final String noMoreLabel;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
key: loadMoreKey,
|
key: loadMoreKey,
|
||||||
height: 56,
|
height: AppDimens.loadMoreIndicatorHeight,
|
||||||
child: const Center(
|
child: const Center(
|
||||||
child: SizedBox.square(
|
child: SizedBox.square(
|
||||||
dimension: 20,
|
dimension: AppDimens.refreshSpinnerSize,
|
||||||
child: CircularProgressIndicator(
|
child: CircularProgressIndicator(
|
||||||
strokeWidth: 2,
|
strokeWidth: AppDimens.refreshSpinnerStroke,
|
||||||
color: AppColors.blue,
|
color: AppColors.textPrimary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (hasItems && !hasMore) {
|
return const SizedBox.shrink();
|
||||||
return Padding(
|
|
||||||
key: noMoreKey,
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
|
||||||
child: Text(
|
|
||||||
noMoreLabel,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: const TextStyle(color: AppColors.muted, fontSize: 12),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return const SizedBox(height: 16);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -344,10 +344,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"retry": "Retry",
|
"retry": "Retry",
|
||||||
"pullToRefresh": "Pull to refresh",
|
|
||||||
"releaseToRefresh": "Release to refresh",
|
|
||||||
"refreshingLabel": "Refreshing…",
|
|
||||||
"noMore": "No more",
|
|
||||||
"backToSeries": "Back to series",
|
"backToSeries": "Back to series",
|
||||||
"nextEpisode": "Next episode",
|
"nextEpisode": "Next episode",
|
||||||
"pause": "Pause",
|
"pause": "Pause",
|
||||||
|
|||||||
@@ -318,10 +318,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"retry": "Coba lagi",
|
"retry": "Coba lagi",
|
||||||
"pullToRefresh": "Tarik untuk menyegarkan",
|
|
||||||
"releaseToRefresh": "Lepaskan untuk menyegarkan",
|
|
||||||
"refreshingLabel": "Menyegarkan…",
|
|
||||||
"noMore": "Tidak ada lagi",
|
|
||||||
"backToSeries": "Kembali ke serial",
|
"backToSeries": "Kembali ke serial",
|
||||||
"nextEpisode": "Episode berikutnya",
|
"nextEpisode": "Episode berikutnya",
|
||||||
"pause": "Jeda",
|
"pause": "Jeda",
|
||||||
|
|||||||
@@ -1342,30 +1342,6 @@ abstract class AppLocalizations {
|
|||||||
/// **'Retry'**
|
/// **'Retry'**
|
||||||
String get retry;
|
String get retry;
|
||||||
|
|
||||||
/// No description provided for @pullToRefresh.
|
|
||||||
///
|
|
||||||
/// In en, this message translates to:
|
|
||||||
/// **'Pull to refresh'**
|
|
||||||
String get pullToRefresh;
|
|
||||||
|
|
||||||
/// No description provided for @releaseToRefresh.
|
|
||||||
///
|
|
||||||
/// In en, this message translates to:
|
|
||||||
/// **'Release to refresh'**
|
|
||||||
String get releaseToRefresh;
|
|
||||||
|
|
||||||
/// No description provided for @refreshingLabel.
|
|
||||||
///
|
|
||||||
/// In en, this message translates to:
|
|
||||||
/// **'Refreshing…'**
|
|
||||||
String get refreshingLabel;
|
|
||||||
|
|
||||||
/// No description provided for @noMore.
|
|
||||||
///
|
|
||||||
/// In en, this message translates to:
|
|
||||||
/// **'No more'**
|
|
||||||
String get noMore;
|
|
||||||
|
|
||||||
/// No description provided for @backToSeries.
|
/// No description provided for @backToSeries.
|
||||||
///
|
///
|
||||||
/// In en, this message translates to:
|
/// In en, this message translates to:
|
||||||
|
|||||||
@@ -681,18 +681,6 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get retry => 'Retry';
|
String get retry => 'Retry';
|
||||||
|
|
||||||
@override
|
|
||||||
String get pullToRefresh => 'Pull to refresh';
|
|
||||||
|
|
||||||
@override
|
|
||||||
String get releaseToRefresh => 'Release to refresh';
|
|
||||||
|
|
||||||
@override
|
|
||||||
String get refreshingLabel => 'Refreshing…';
|
|
||||||
|
|
||||||
@override
|
|
||||||
String get noMore => 'No more';
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get backToSeries => 'Back to series';
|
String get backToSeries => 'Back to series';
|
||||||
|
|
||||||
|
|||||||
@@ -684,18 +684,6 @@ class AppLocalizationsId extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get retry => 'Coba lagi';
|
String get retry => 'Coba lagi';
|
||||||
|
|
||||||
@override
|
|
||||||
String get pullToRefresh => 'Tarik untuk menyegarkan';
|
|
||||||
|
|
||||||
@override
|
|
||||||
String get releaseToRefresh => 'Lepaskan untuk menyegarkan';
|
|
||||||
|
|
||||||
@override
|
|
||||||
String get refreshingLabel => 'Menyegarkan…';
|
|
||||||
|
|
||||||
@override
|
|
||||||
String get noMore => 'Tidak ada lagi';
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get backToSeries => 'Kembali ke serial';
|
String get backToSeries => 'Kembali ke serial';
|
||||||
|
|
||||||
|
|||||||
@@ -673,18 +673,6 @@ class AppLocalizationsZh extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get retry => '重试';
|
String get retry => '重试';
|
||||||
|
|
||||||
@override
|
|
||||||
String get pullToRefresh => '下拉刷新';
|
|
||||||
|
|
||||||
@override
|
|
||||||
String get releaseToRefresh => '松手刷新';
|
|
||||||
|
|
||||||
@override
|
|
||||||
String get refreshingLabel => '正在刷新…';
|
|
||||||
|
|
||||||
@override
|
|
||||||
String get noMore => '没有更多了';
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get backToSeries => '返回剧集详情';
|
String get backToSeries => '返回剧集详情';
|
||||||
|
|
||||||
|
|||||||
@@ -280,10 +280,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"retry": "重试",
|
"retry": "重试",
|
||||||
"pullToRefresh": "下拉刷新",
|
|
||||||
"releaseToRefresh": "松手刷新",
|
|
||||||
"refreshingLabel": "正在刷新…",
|
|
||||||
"noMore": "没有更多了",
|
|
||||||
"backToSeries": "返回剧集详情",
|
"backToSeries": "返回剧集详情",
|
||||||
"nextEpisode": "下一集",
|
"nextEpisode": "下一集",
|
||||||
"pause": "暂停",
|
"pause": "暂停",
|
||||||
|
|||||||
@@ -176,8 +176,6 @@ class _FavoritesBody extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
PagedListFooter(
|
PagedListFooter(
|
||||||
loading: favorites.loadingMore,
|
loading: favorites.loadingMore,
|
||||||
hasMore: favorites.hasMore,
|
|
||||||
hasItems: favorites.cards.isNotEmpty,
|
|
||||||
errorMessage: favorites.loadMoreError == null
|
errorMessage: favorites.loadMoreError == null
|
||||||
? null
|
? null
|
||||||
: errorText(l10n, favorites.loadMoreError, l10n.favoritesError),
|
: errorText(l10n, favorites.loadMoreError, l10n.favoritesError),
|
||||||
|
|||||||
@@ -130,8 +130,6 @@ class FollowingPagedGrid extends StatelessWidget {
|
|||||||
SliverToBoxAdapter(
|
SliverToBoxAdapter(
|
||||||
child: PagedListFooter(
|
child: PagedListFooter(
|
||||||
loading: loadingMore,
|
loading: loadingMore,
|
||||||
hasMore: hasMore,
|
|
||||||
hasItems: hasItems,
|
|
||||||
errorMessage: loadMoreError,
|
errorMessage: loadMoreError,
|
||||||
onRetry: onLoadMore,
|
onRetry: onLoadMore,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -218,8 +218,6 @@ class _HomeFeedGridState extends State<HomeFeedGrid> {
|
|||||||
padding: const EdgeInsets.only(bottom: AppDimens.spaceXl),
|
padding: const EdgeInsets.only(bottom: AppDimens.spaceXl),
|
||||||
child: PagedListFooter(
|
child: PagedListFooter(
|
||||||
loading: widget.feedController.loadingMore,
|
loading: widget.feedController.loadingMore,
|
||||||
hasMore: widget.feedController.hasMore,
|
|
||||||
hasItems: dramas.isNotEmpty,
|
|
||||||
errorMessage: widget.feedController.lastError == null
|
errorMessage: widget.feedController.lastError == null
|
||||||
? null
|
? null
|
||||||
: l10n.catalogError,
|
: l10n.catalogError,
|
||||||
|
|||||||
@@ -192,13 +192,9 @@ class _NewReleasesPageState extends State<NewReleasesPage> {
|
|||||||
),
|
),
|
||||||
PagedLoadFooter(
|
PagedLoadFooter(
|
||||||
loading: pager.loading,
|
loading: pager.loading,
|
||||||
hasMore: pager.hasMore,
|
|
||||||
hasItems: pager.items.isNotEmpty,
|
|
||||||
loadMoreKey: const Key(
|
loadMoreKey: const Key(
|
||||||
'new-releases-load-more',
|
'new-releases-load-more',
|
||||||
),
|
),
|
||||||
noMoreKey: const Key('new-releases-no-more'),
|
|
||||||
noMoreLabel: l10n.noMore,
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ import '../../core/widgets/empty_state.dart';
|
|||||||
import '../../core/widgets/plain_page_scaffold.dart';
|
import '../../core/widgets/plain_page_scaffold.dart';
|
||||||
import '../../l10n/app_localizations.dart';
|
import '../../l10n/app_localizations.dart';
|
||||||
|
|
||||||
|
const double _loadMoreThreshold = 240;
|
||||||
|
|
||||||
/// Anonymous system notice list with pagination and detail dialog.
|
/// Anonymous system notice list with pagination and detail dialog.
|
||||||
class NoticesPage extends StatefulWidget {
|
class NoticesPage extends StatefulWidget {
|
||||||
const NoticesPage({super.key});
|
const NoticesPage({super.key});
|
||||||
@@ -111,29 +113,55 @@ class _NoticesPageState extends State<NoticesPage> {
|
|||||||
}
|
}
|
||||||
return AppPullToRefresh(
|
return AppPullToRefresh(
|
||||||
onRefresh: _controller.refresh,
|
onRefresh: _controller.refresh,
|
||||||
child: ListView.separated(
|
child: NotificationListener<ScrollNotification>(
|
||||||
key: const Key('notices-list'),
|
onNotification: _onScroll,
|
||||||
physics: AppPullToRefresh.physics,
|
child: ListView.separated(
|
||||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 28),
|
key: const Key('notices-list'),
|
||||||
itemCount: _controller.notices.length + 1,
|
physics: AppPullToRefresh.physics,
|
||||||
separatorBuilder: (_, _) => const SizedBox(height: 10),
|
padding: const EdgeInsets.fromLTRB(16, 12, 16, 28),
|
||||||
itemBuilder: (context, index) {
|
itemCount: _controller.notices.length + 1,
|
||||||
if (index == _controller.notices.length) return _footer(l10n);
|
separatorBuilder: (_, _) => const SizedBox(height: 10),
|
||||||
final notice = _controller.notices[index];
|
itemBuilder: (context, index) {
|
||||||
return _NoticeTile(
|
if (index == _controller.notices.length) return _footer(l10n);
|
||||||
notice: notice,
|
final notice = _controller.notices[index];
|
||||||
onTap: () => _showDetails(notice, l10n),
|
return _NoticeTile(
|
||||||
);
|
notice: notice,
|
||||||
},
|
onTap: () => _showDetails(notice, l10n),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _onScroll(ScrollNotification notification) {
|
||||||
|
if (notification.depth != 0 ||
|
||||||
|
!_controller.hasMore ||
|
||||||
|
_controller.loadingMore) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (notification.metrics.extentAfter > _loadMoreThreshold) return false;
|
||||||
|
if (notification is ScrollUpdateNotification ||
|
||||||
|
notification is ScrollEndNotification ||
|
||||||
|
notification is OverscrollNotification) {
|
||||||
|
unawaited(_controller.loadMore());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Widget _footer(AppLocalizations l10n) {
|
Widget _footer(AppLocalizations l10n) {
|
||||||
if (_controller.loadingMore) {
|
if (_controller.loadingMore) {
|
||||||
return const Padding(
|
return const SizedBox(
|
||||||
padding: EdgeInsets.symmetric(vertical: 12),
|
height: AppDimens.loadMoreIndicatorHeight,
|
||||||
child: Center(child: CircularProgressIndicator()),
|
child: Center(
|
||||||
|
child: SizedBox.square(
|
||||||
|
dimension: AppDimens.refreshSpinnerSize,
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
strokeWidth: AppDimens.refreshSpinnerStroke,
|
||||||
|
color: AppColors.textPrimary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (_controller.loadMoreError != null) {
|
if (_controller.loadMoreError != null) {
|
||||||
@@ -143,14 +171,7 @@ class _NoticesPageState extends State<NoticesPage> {
|
|||||||
label: Text(l10n.retry),
|
label: Text(l10n.retry),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (_controller.hasMore) {
|
return const SizedBox.shrink();
|
||||||
return TextButton(
|
|
||||||
key: const Key('notices-load-more'),
|
|
||||||
onPressed: _controller.loadMore,
|
|
||||||
child: Text(l10n.loadMore),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return const SizedBox(height: 8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _showDetails(AppNotice notice, AppLocalizations l10n) {
|
Future<void> _showDetails(AppNotice notice, AppLocalizations l10n) {
|
||||||
|
|||||||
@@ -153,11 +153,7 @@ class _RankingPageState extends State<RankingPage> {
|
|||||||
],
|
],
|
||||||
PagedLoadFooter(
|
PagedLoadFooter(
|
||||||
loading: pager.loading,
|
loading: pager.loading,
|
||||||
hasMore: pager.hasMore,
|
|
||||||
hasItems: pager.items.isNotEmpty,
|
|
||||||
loadMoreKey: const Key('ranking-load-more'),
|
loadMoreKey: const Key('ranking-load-more'),
|
||||||
noMoreKey: const Key('ranking-no-more'),
|
|
||||||
noMoreLabel: l10n.noMore,
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -115,8 +115,6 @@ class _AllDramasFilterGridState extends State<AllDramasFilterGrid> {
|
|||||||
),
|
),
|
||||||
child: PagedListFooter(
|
child: PagedListFooter(
|
||||||
loading: widget.feedController.loadingMore,
|
loading: widget.feedController.loadingMore,
|
||||||
hasMore: widget.feedController.hasMore,
|
|
||||||
hasItems: dramas.isNotEmpty,
|
|
||||||
errorMessage:
|
errorMessage:
|
||||||
widget.feedController.lastError == null
|
widget.feedController.lastError == null
|
||||||
? null
|
? null
|
||||||
|
|||||||
@@ -145,8 +145,6 @@ class _WatchRecordsBodyState extends State<_WatchRecordsBody> {
|
|||||||
],
|
],
|
||||||
PagedListFooter(
|
PagedListFooter(
|
||||||
loading: controller.loadingMore,
|
loading: controller.loadingMore,
|
||||||
hasMore: controller.hasMore,
|
|
||||||
hasItems: controller.records.isNotEmpty,
|
|
||||||
errorMessage: controller.loadMoreError == null
|
errorMessage: controller.loadMoreError == null
|
||||||
? null
|
? null
|
||||||
: errorText(l10n, controller.loadMoreError, l10n.progressError),
|
: errorText(l10n, controller.loadMoreError, l10n.progressError),
|
||||||
|
|||||||
@@ -44,28 +44,32 @@ void main() {
|
|||||||
find.descendant(of: list, matching: find.byType(Scrollable)).first,
|
find.descendant(of: list, matching: find.byType(Scrollable)).first,
|
||||||
);
|
);
|
||||||
expect(scrollable.position.pixels, 0);
|
expect(scrollable.position.pixels, 0);
|
||||||
expect(find.text('Pull to refresh'), findsOneWidget);
|
final indicator = find.byKey(const Key('pull-refresh-indicator'));
|
||||||
expect(_contentOffset(tester), greaterThan(0));
|
expect(indicator, findsOneWidget);
|
||||||
expect(
|
expect(
|
||||||
tester.widget<Text>(find.text('Pull to refresh')).style?.color,
|
find.descendant(
|
||||||
AppColors.navSelected,
|
of: indicator,
|
||||||
|
matching: find.byType(CircularProgressIndicator),
|
||||||
|
),
|
||||||
|
findsOneWidget,
|
||||||
);
|
);
|
||||||
|
expect(tester.getSize(indicator), const Size(40, 40));
|
||||||
|
final background = tester.widget<Container>(indicator).decoration;
|
||||||
|
final backgroundDecoration = background! as BoxDecoration;
|
||||||
|
expect(backgroundDecoration.color, AppColors.refreshIndicatorSurface);
|
||||||
|
expect(backgroundDecoration.borderRadius, BorderRadius.circular(20));
|
||||||
|
expect(find.text('Pull to refresh'), findsNothing);
|
||||||
|
expect(_contentOffset(tester), greaterThan(0));
|
||||||
|
|
||||||
await gesture.moveBy(const Offset(0, 120));
|
await gesture.moveBy(const Offset(0, 120));
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(find.text('Release to refresh'), findsOneWidget);
|
expect(indicator, findsOneWidget);
|
||||||
expect(
|
expect(find.text('Release to refresh'), findsNothing);
|
||||||
tester.widget<Text>(find.text('Release to refresh')).style?.color,
|
|
||||||
AppColors.navSelected,
|
|
||||||
);
|
|
||||||
|
|
||||||
await gesture.up();
|
await gesture.up();
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(find.text('Refreshing…'), findsOneWidget);
|
expect(indicator, findsOneWidget);
|
||||||
expect(
|
expect(find.text('Refreshing…'), findsNothing);
|
||||||
tester.widget<Text>(find.text('Refreshing…')).style?.color,
|
|
||||||
AppColors.navSelected,
|
|
||||||
);
|
|
||||||
expect(calls, 1);
|
expect(calls, 1);
|
||||||
final releaseOffset = _contentOffset(tester);
|
final releaseOffset = _contentOffset(tester);
|
||||||
expect(releaseOffset, greaterThan(56));
|
expect(releaseOffset, greaterThan(56));
|
||||||
@@ -87,6 +91,7 @@ void main() {
|
|||||||
await tester.pump();
|
await tester.pump();
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(_contentOffset(tester), closeTo(0, 0.1));
|
expect(_contentOffset(tester), closeTo(0, 0.1));
|
||||||
|
expect(indicator, findsNothing);
|
||||||
expect(find.text('Refreshing…'), findsNothing);
|
expect(find.text('Refreshing…'), findsNothing);
|
||||||
expect(find.text('Pull to refresh'), findsNothing);
|
expect(find.text('Pull to refresh'), findsNothing);
|
||||||
});
|
});
|
||||||
@@ -122,7 +127,8 @@ void main() {
|
|||||||
final releaseOffset = _contentOffset(tester);
|
final releaseOffset = _contentOffset(tester);
|
||||||
expect(releaseOffset, greaterThan(0));
|
expect(releaseOffset, greaterThan(0));
|
||||||
expect(releaseOffset, lessThan(56));
|
expect(releaseOffset, lessThan(56));
|
||||||
expect(find.text('Pull to refresh'), findsOneWidget);
|
expect(find.byKey(const Key('pull-refresh-indicator')), findsOneWidget);
|
||||||
|
expect(find.text('Pull to refresh'), findsNothing);
|
||||||
|
|
||||||
await gesture.up();
|
await gesture.up();
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
@@ -136,6 +142,7 @@ void main() {
|
|||||||
|
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(_contentOffset(tester), closeTo(0, 0.1));
|
expect(_contentOffset(tester), closeTo(0, 0.1));
|
||||||
|
expect(find.byKey(const Key('pull-refresh-indicator')), findsNothing);
|
||||||
expect(find.text('Pull to refresh'), findsNothing);
|
expect(find.text('Pull to refresh'), findsNothing);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -388,7 +388,8 @@ void main() {
|
|||||||
);
|
);
|
||||||
await tester.drag(_verticalFeed, const Offset(0, 240));
|
await tester.drag(_verticalFeed, const Offset(0, 240));
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(find.text('Refreshing…'), findsOneWidget);
|
expect(find.byKey(const Key('pull-refresh-indicator')), findsOneWidget);
|
||||||
|
expect(find.text('Refreshing…'), findsNothing);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ void main() {
|
|||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(find.byKey(const Key('ranking-row-39')), findsOneWidget);
|
expect(find.byKey(const Key('ranking-row-39')), findsOneWidget);
|
||||||
expect(find.byKey(const Key('ranking-row-40')), findsNothing);
|
expect(find.byKey(const Key('ranking-row-40')), findsNothing);
|
||||||
expect(find.byKey(const Key('ranking-no-more')), findsOneWidget);
|
expect(find.byKey(const Key('ranking-no-more')), findsNothing);
|
||||||
|
|
||||||
position.jumpTo(0);
|
position.jumpTo(0);
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
@@ -211,7 +211,7 @@ void main() {
|
|||||||
expect(position.pixels, 0);
|
expect(position.pixels, 0);
|
||||||
position.jumpTo(position.maxScrollExtent);
|
position.jumpTo(position.maxScrollExtent);
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(find.byKey(const Key('ranking-load-more')), findsOneWidget);
|
expect(find.byKey(const Key('ranking-load-more')), findsNothing);
|
||||||
expect(find.byKey(const Key('ranking-no-more')), findsNothing);
|
expect(find.byKey(const Key('ranking-no-more')), findsNothing);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
});
|
});
|
||||||
@@ -243,7 +243,7 @@ void main() {
|
|||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
position.jumpTo(position.maxScrollExtent);
|
position.jumpTo(position.maxScrollExtent);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
expect(find.byKey(const Key('new-releases-no-more')), findsOneWidget);
|
expect(find.byKey(const Key('new-releases-no-more')), findsNothing);
|
||||||
|
|
||||||
position.jumpTo(0);
|
position.jumpTo(0);
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
|
|||||||
@@ -99,7 +99,8 @@ void main() {
|
|||||||
);
|
);
|
||||||
await tester.drag(find.byType(ListView), const Offset(0, 240));
|
await tester.drag(find.byType(ListView), const Offset(0, 240));
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(find.text('Refreshing…'), findsOneWidget);
|
expect(find.byKey(const Key('pull-refresh-indicator')), findsOneWidget);
|
||||||
|
expect(find.text('Refreshing…'), findsNothing);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
await tester.tap(find.byKey(const Key('favorite-remove-signal')));
|
await tester.tap(find.byKey(const Key('favorite-remove-signal')));
|
||||||
|
|||||||
@@ -24,9 +24,10 @@ void main() {
|
|||||||
await _pump(tester, repository);
|
await _pump(tester, repository);
|
||||||
|
|
||||||
expect(find.text('Notice 1'), findsOneWidget);
|
expect(find.text('Notice 1'), findsOneWidget);
|
||||||
expect(find.byKey(const Key('notices-load-more')), findsOneWidget);
|
await tester.drag(
|
||||||
|
find.byKey(const Key('notices-list')),
|
||||||
await tester.tap(find.byKey(const Key('notices-load-more')));
|
const Offset(0, -300),
|
||||||
|
);
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(find.text('Notice 3'), findsOneWidget);
|
expect(find.text('Notice 3'), findsOneWidget);
|
||||||
|
|||||||
Reference in new issue
Block a user