fix(flutter): 修复下拉刷新页面跟随
This commit is contained in:
1 parent
c4dcb714ab
commit
69eaacd74f
16 files changed
+85
-34
No files matched your search
@@ -26,7 +26,7 @@ void main() {
|
||||
},
|
||||
child: ListView(
|
||||
key: const Key('pull-refresh-list'),
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
physics: AppPullToRefresh.physics,
|
||||
children: const [SizedBox(height: 1200)],
|
||||
),
|
||||
),
|
||||
@@ -34,14 +34,17 @@ void main() {
|
||||
),
|
||||
);
|
||||
|
||||
final gesture = await tester.startGesture(
|
||||
tester.getCenter(find.byKey(const Key('pull-refresh-list'))),
|
||||
);
|
||||
final list = find.byKey(const Key('pull-refresh-list'));
|
||||
final gesture = await tester.startGesture(tester.getCenter(list));
|
||||
await gesture.moveBy(const Offset(0, 30));
|
||||
await tester.pump();
|
||||
final scrollable = tester.state<ScrollableState>(
|
||||
find.descendant(of: list, matching: find.byType(Scrollable)).first,
|
||||
);
|
||||
expect(scrollable.position.pixels, lessThan(0));
|
||||
expect(find.text('Pull to refresh'), findsOneWidget);
|
||||
|
||||
await gesture.moveBy(const Offset(0, 40));
|
||||
await gesture.moveBy(const Offset(0, 120));
|
||||
await tester.pump();
|
||||
expect(find.text('Release to refresh'), findsOneWidget);
|
||||
|
||||
|
||||
@@ -300,7 +300,11 @@ void main() {
|
||||
);
|
||||
|
||||
expect(refresh.edgeOffset, 52);
|
||||
await tester.drag(_verticalFeed, const Offset(0, 120));
|
||||
expect(
|
||||
tester.widget<ListView>(_verticalFeed).physics,
|
||||
AppPullToRefresh.physics,
|
||||
);
|
||||
await tester.drag(_verticalFeed, const Offset(0, 240));
|
||||
await tester.pump();
|
||||
expect(find.text('Refreshing…'), findsOneWidget);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:fruitshorts/app.dart';
|
||||
import 'package:fruitshorts/core/data/models/drama.dart';
|
||||
import 'package:fruitshorts/core/data/models/home_feed.dart';
|
||||
import 'package:fruitshorts/core/theme/app_colors.dart';
|
||||
import 'package:fruitshorts/core/widgets/app_pull_to_refresh.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/favorite_repository.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/playback_repository.dart';
|
||||
import 'package:fruitshorts/core/data/repositories/watch_history_repository.dart';
|
||||
@@ -181,7 +182,9 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final list = find.byKey(const Key('ranking-list'));
|
||||
await tester.drag(list, const Offset(0, -8000));
|
||||
expect(tester.widget<ListView>(list).physics, AppPullToRefresh.physics);
|
||||
final position = _scrollPosition(tester, const Key('ranking-list'));
|
||||
position.jumpTo(position.maxScrollExtent);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byKey(const Key('ranking-row-19')), findsOneWidget);
|
||||
@@ -191,23 +194,22 @@ void main() {
|
||||
expect(find.byKey(const Key('ranking-load-more')), findsOneWidget);
|
||||
await tester.pump(const Duration(milliseconds: 1));
|
||||
|
||||
await tester.drag(list, const Offset(0, -8000));
|
||||
position.jumpTo(position.maxScrollExtent);
|
||||
await tester.pump();
|
||||
expect(find.byKey(const Key('ranking-row-39')), findsOneWidget);
|
||||
expect(find.byKey(const Key('ranking-row-40')), findsNothing);
|
||||
expect(find.byKey(const Key('ranking-no-more')), findsOneWidget);
|
||||
|
||||
final position = _scrollPosition(tester, const Key('ranking-list'));
|
||||
position.jumpTo(0);
|
||||
await tester.pump();
|
||||
final beforeRefresh = repository.fetchCalls;
|
||||
await tester.drag(list, const Offset(0, 120));
|
||||
await tester.drag(list, const Offset(0, 240));
|
||||
await tester.pump();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(repository.fetchCalls, beforeRefresh + 1);
|
||||
expect(position.pixels, 0);
|
||||
await tester.drag(list, const Offset(0, -8000));
|
||||
position.jumpTo(position.maxScrollExtent);
|
||||
await tester.pump();
|
||||
expect(find.byKey(const Key('ranking-load-more')), findsOneWidget);
|
||||
expect(find.byKey(const Key('ranking-no-more')), findsNothing);
|
||||
@@ -223,11 +225,13 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final list = find.byKey(const Key('new-releases-list'));
|
||||
expect(tester.widget<ListView>(list).physics, AppPullToRefresh.physics);
|
||||
await tester.drag(list, const Offset(0, -400));
|
||||
await tester.pump();
|
||||
expect(_countKeys('home-drama-card-'), 20);
|
||||
|
||||
await tester.drag(list, const Offset(0, -8000));
|
||||
final position = _scrollPosition(tester, const Key('new-releases-list'));
|
||||
position.jumpTo(position.maxScrollExtent);
|
||||
await tester.pump();
|
||||
expect(find.byKey(const Key('new-releases-load-more')), findsOneWidget);
|
||||
await tester.pump(const Duration(milliseconds: 299));
|
||||
@@ -237,7 +241,6 @@ void main() {
|
||||
expect(_countKeys('home-drama-card-'), 40);
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
final position = _scrollPosition(tester, const Key('new-releases-list'));
|
||||
position.jumpTo(position.maxScrollExtent);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('new-releases-no-more')), findsOneWidget);
|
||||
@@ -245,7 +248,7 @@ void main() {
|
||||
position.jumpTo(0);
|
||||
await tester.pump();
|
||||
final beforeRefresh = repository.fetchCalls;
|
||||
await tester.drag(list, const Offset(0, 120));
|
||||
await tester.drag(list, const Offset(0, 240));
|
||||
await tester.pump();
|
||||
await tester.pumpAndSettle();
|
||||
expect(repository.fetchCalls, beforeRefresh + 1);
|
||||
@@ -263,10 +266,9 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final beforeRefresh = repository.fetchCalls;
|
||||
await tester.drag(
|
||||
find.byKey(const Key('reserve-list')),
|
||||
const Offset(0, 120),
|
||||
);
|
||||
final list = find.byKey(const Key('reserve-list'));
|
||||
expect(tester.widget<ListView>(list).physics, AppPullToRefresh.physics);
|
||||
await tester.drag(list, const Offset(0, 240));
|
||||
await tester.pump();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
|
||||
@@ -75,7 +75,11 @@ void main() {
|
||||
expect(find.byIcon(Icons.star_rounded), findsNWidgets(2));
|
||||
expect(find.byIcon(Icons.favorite_rounded), findsNothing);
|
||||
expect(find.byType(AppPullToRefresh), findsOneWidget);
|
||||
await tester.drag(find.byType(ListView), const Offset(0, 120));
|
||||
expect(
|
||||
tester.widget<ListView>(find.byType(ListView)).physics,
|
||||
AppPullToRefresh.physics,
|
||||
);
|
||||
await tester.drag(find.byType(ListView), const Offset(0, 240));
|
||||
await tester.pump();
|
||||
expect(find.text('Refreshing…'), findsOneWidget);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
@@ -85,7 +85,7 @@ void main() {
|
||||
matching: find.byType(ListView),
|
||||
),
|
||||
);
|
||||
expect(list.physics, isA<AlwaysScrollableScrollPhysics>());
|
||||
expect(list.physics, AppPullToRefresh.physics);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
|
||||
Reference in new issue
Block a user