feat(flutter): 统一文字下拉刷新

This commit is contained in:
Zhou Weidong committed 2026-10-20 16:47:13 +08:00
1 parent 0ad2cd5e95
commit 5bdcb989bb
19 files changed
+320 -38

No files matched your search

+68
View File
@@ -0,0 +1,68 @@
// Author: fruit.com.cn
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:fruitshorts/core/widgets/app_pull_to_refresh.dart';
import 'package:fruitshorts/l10n/app_localizations.dart';
void main() {
testWidgets(
'should_show_pull_release_and_refreshing_states_and_refresh_once',
(tester) async {
final refresh = Completer<void>();
var calls = 0;
await tester.pumpWidget(
MaterialApp(
locale: const Locale('en'),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
body: AppPullToRefresh(
onRefresh: () {
calls++;
return refresh.future;
},
child: ListView(
key: const Key('pull-refresh-list'),
physics: const AlwaysScrollableScrollPhysics(),
children: const [SizedBox(height: 1200)],
),
),
),
),
);
final gesture = await tester.startGesture(
tester.getCenter(find.byKey(const Key('pull-refresh-list'))),
);
await gesture.moveBy(const Offset(0, 30));
await tester.pump();
expect(find.text('Pull to refresh'), findsOneWidget);
await gesture.moveBy(const Offset(0, 40));
await tester.pump();
expect(find.text('Release to refresh'), findsOneWidget);
await gesture.up();
await tester.pump();
expect(find.text('Refreshing…'), findsOneWidget);
expect(calls, 1);
final duplicate = await tester.startGesture(
tester.getCenter(find.byKey(const Key('pull-refresh-list'))),
);
await duplicate.moveBy(const Offset(0, 70));
await duplicate.up();
await tester.pump();
expect(calls, 1);
refresh.complete();
await tester.pump();
await tester.pump(const Duration(milliseconds: 200));
expect(find.text('Refreshing…'), findsNothing);
expect(find.text('Pull to refresh'), findsNothing);
},
);
}