Skip to content

Commit 2524b63

Browse files
committed
修复下啦刷新问题
调整 OverScrollIndicator
1 parent 2e0503d commit 2524b63

File tree

7 files changed

+273
-101
lines changed

7 files changed

+273
-101
lines changed

lib/common/utils/navigator_utils.dart

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import 'package:gsy_github_app_flutter/page/release/release_page.dart';
2121
import 'package:gsy_github_app_flutter/page/repos/repository_detail_page.dart';
2222
import 'package:gsy_github_app_flutter/page/search/search_page.dart';
2323
import 'package:gsy_github_app_flutter/page/user_profile_page.dart';
24+
import 'package:gsy_github_app_flutter/widget/never_overscroll_indicator.dart';
2425

2526
/**
2627
* 导航栏
@@ -105,7 +106,10 @@ class NavigatorUtils {
105106
return Align(
106107
child: SizeTransition(
107108
sizeFactor: animation.drive(tween),
108-
child: child,
109+
child: NeverOverScrollIndicator(
110+
needOverload: false,
111+
child: child,
112+
),
109113
),
110114
);
111115
},
@@ -114,8 +118,31 @@ class NavigatorUtils {
114118

115119
///荣耀列表
116120
static Future goHonorListPage(BuildContext context, List? list) {
117-
return Navigator.push(context,
118-
new SizeRoute(widget: pageContainer(HonorListPage(list), context)));
121+
return Navigator.push(
122+
context,
123+
PageRouteBuilder(
124+
pageBuilder: (context, animation, secondaryAnimation) =>
125+
HonorListPage(list),
126+
transitionsBuilder: (context, animation, secondaryAnimation, child) {
127+
double begin = 0;
128+
double end = 1;
129+
var curve = Curves.ease;
130+
131+
var tween =
132+
Tween(begin: begin, end: end).chain(CurveTween(curve: curve));
133+
134+
return Align(
135+
child: SizeTransition(
136+
sizeFactor: animation.drive(tween),
137+
child: NeverOverScrollIndicator(
138+
needOverload: false,
139+
child: child,
140+
),
141+
),
142+
);
143+
},
144+
),
145+
);
119146
}
120147

121148
///仓库版本列表
@@ -281,7 +308,10 @@ class NavigatorUtils {
281308

282309
///不受系统字体缩放影响
283310
data: MediaQuery.of(context).copyWith(textScaleFactor: 1),
284-
child: widget);
311+
child: NeverOverScrollIndicator(
312+
needOverload: false,
313+
child: widget,
314+
));
285315
}
286316

287317
///弹出 dialog
@@ -299,7 +329,10 @@ class NavigatorUtils {
299329
///不受系统字体缩放影响
300330
data: MediaQueryData.fromWindow(WidgetsBinding.instance!.window)
301331
.copyWith(textScaleFactor: 1),
302-
child: new SafeArea(child: builder!(context)));
332+
child: NeverOverScrollIndicator(
333+
needOverload: false,
334+
child: new SafeArea(child: builder!(context)),
335+
));
303336
});
304337
}
305338
}

lib/page/repos/repository_detail_issue_list_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class RepositoryDetailIssuePageState extends State<RepositoryDetailIssuePage>
5858
@override
5959
showRefreshLoading() {
6060
new Future.delayed(const Duration(seconds: 0), () {
61-
refreshIKey.currentState!.show()!.then((e) {});
61+
refreshIKey.currentState!.show().then((e) {});
6262
return true;
6363
});
6464
}

lib/page/repos/repostory_detail_info_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class ReposDetailInfoPageState extends State<ReposDetailInfoPage>
6262
@override
6363
showRefreshLoading() {
6464
new Future.delayed(const Duration(seconds: 0), () {
65-
refreshIKey.currentState!.show()!.then((e) {});
65+
refreshIKey.currentState!.show().then((e) {});
6666
return true;
6767
});
6868
}

lib/page/trend/trend_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class TrendPageState extends State<TrendPage>
5757
///显示刷新
5858
_showRefreshLoading() {
5959
new Future.delayed(const Duration(seconds: 0), () {
60-
refreshIndicatorKey.currentState!.show()!.then((e) {});
60+
refreshIndicatorKey.currentState!.show().then((e) {});
6161
return true;
6262
});
6363
}

lib/page/user/base_person_state.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ abstract class BasePersonState<T extends StatefulWidget> extends State<T>
3737
@override
3838
showRefreshLoading() {
3939
new Future.delayed(const Duration(seconds: 0), () {
40-
refreshIKey.currentState!.show()!.then((e) {});
40+
refreshIKey.currentState!.show().then((e) {});
4141
return true;
4242
});
4343
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import 'package:flutter/material.dart';
2+
3+
///去除ScrollView的Material效果
4+
class NeverOverScrollIndicator extends StatelessWidget {
5+
final bool needOverload;
6+
7+
final Widget? child;
8+
9+
NeverOverScrollIndicator({this.child, this.needOverload = true});
10+
11+
@override
12+
Widget build(BuildContext context) {
13+
return ScrollConfiguration(
14+
child: child!,
15+
behavior: NeverOverScrollBehavior(needOverload: needOverload),
16+
);
17+
}
18+
}
19+
20+
class NeverOverScrollBehavior extends ScrollBehavior {
21+
final bool needOverload;
22+
23+
NeverOverScrollBehavior({this.needOverload = true});
24+
25+
@override
26+
Widget buildViewportChrome(
27+
BuildContext context, Widget child, AxisDirection axisDirection) {
28+
return child;
29+
}
30+
31+
@override
32+
ScrollPhysics getScrollPhysics(BuildContext context) {
33+
switch (getPlatform(context)) {
34+
case TargetPlatform.iOS:
35+
if (needOverload) {
36+
return const BouncingScrollPhysics();
37+
}
38+
return const ClampingScrollPhysics();
39+
case TargetPlatform.android:
40+
case TargetPlatform.fuchsia:
41+
default:
42+
return const ClampingScrollPhysics();
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)