style: 统一下拉与加载指示器
This commit is contained in:
1 parent
397483d339
commit
6f1da5aa39
26 files changed
+127
-241
No files matched your search
@@ -18,6 +18,8 @@ import '../../core/widgets/empty_state.dart';
|
||||
import '../../core/widgets/plain_page_scaffold.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
|
||||
const double _loadMoreThreshold = 240;
|
||||
|
||||
/// Anonymous system notice list with pagination and detail dialog.
|
||||
class NoticesPage extends StatefulWidget {
|
||||
const NoticesPage({super.key});
|
||||
@@ -111,29 +113,55 @@ class _NoticesPageState extends State<NoticesPage> {
|
||||
}
|
||||
return AppPullToRefresh(
|
||||
onRefresh: _controller.refresh,
|
||||
child: ListView.separated(
|
||||
key: const Key('notices-list'),
|
||||
physics: AppPullToRefresh.physics,
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 28),
|
||||
itemCount: _controller.notices.length + 1,
|
||||
separatorBuilder: (_, _) => const SizedBox(height: 10),
|
||||
itemBuilder: (context, index) {
|
||||
if (index == _controller.notices.length) return _footer(l10n);
|
||||
final notice = _controller.notices[index];
|
||||
return _NoticeTile(
|
||||
notice: notice,
|
||||
onTap: () => _showDetails(notice, l10n),
|
||||
);
|
||||
},
|
||||
child: NotificationListener<ScrollNotification>(
|
||||
onNotification: _onScroll,
|
||||
child: ListView.separated(
|
||||
key: const Key('notices-list'),
|
||||
physics: AppPullToRefresh.physics,
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 28),
|
||||
itemCount: _controller.notices.length + 1,
|
||||
separatorBuilder: (_, _) => const SizedBox(height: 10),
|
||||
itemBuilder: (context, index) {
|
||||
if (index == _controller.notices.length) return _footer(l10n);
|
||||
final notice = _controller.notices[index];
|
||||
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) {
|
||||
if (_controller.loadingMore) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 12),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
return const SizedBox(
|
||||
height: AppDimens.loadMoreIndicatorHeight,
|
||||
child: Center(
|
||||
child: SizedBox.square(
|
||||
dimension: AppDimens.refreshSpinnerSize,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: AppDimens.refreshSpinnerStroke,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (_controller.loadMoreError != null) {
|
||||
@@ -143,14 +171,7 @@ class _NoticesPageState extends State<NoticesPage> {
|
||||
label: Text(l10n.retry),
|
||||
);
|
||||
}
|
||||
if (_controller.hasMore) {
|
||||
return TextButton(
|
||||
key: const Key('notices-load-more'),
|
||||
onPressed: _controller.loadMore,
|
||||
child: Text(l10n.loadMore),
|
||||
);
|
||||
}
|
||||
return const SizedBox(height: 8);
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
Future<void> _showDetails(AppNotice notice, AppLocalizations l10n) {
|
||||
|
||||
Reference in new issue
Block a user