Skip to content

Commit 25f7874

Browse files
committed
增加动画路由,设置app不受系统字体大小影响
1 parent 45bcbc0 commit 25f7874

File tree

3 files changed

+64
-13
lines changed

3 files changed

+64
-13
lines changed

lib/common/router/size_route.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import 'package:flutter/material.dart';
2+
3+
///动画大小变化打开的路由
4+
class SizeRoute extends PageRouteBuilder {
5+
final Widget widget;
6+
7+
SizeRoute({this.widget})
8+
: super(
9+
pageBuilder: (
10+
BuildContext context,
11+
Animation<double> animation,
12+
Animation<double> secondaryAnimation,
13+
) =>
14+
widget,
15+
transitionsBuilder: (
16+
BuildContext context,
17+
Animation<double> animation,
18+
Animation<double> secondaryAnimation,
19+
Widget child,
20+
) =>
21+
Align(
22+
child: SizeTransition(
23+
sizeFactor: animation,
24+
child: child,
25+
),
26+
),
27+
);
28+
}

lib/common/utils/navigator_utils.dart

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:async';
22

33
import 'package:flutter/cupertino.dart';
44
import 'package:flutter/material.dart';
5+
import 'package:gsy_github_app_flutter/common/router/size_route.dart';
56
import 'package:gsy_github_app_flutter/page/code_detail_page.dart';
67
import 'package:gsy_github_app_flutter/page/code_detail_page_web.dart';
78
import 'package:gsy_github_app_flutter/page/common_list_page.dart';
@@ -52,7 +53,9 @@ class NavigatorUtils {
5253
///仓库详情
5354
static Future goReposDetail(
5455
BuildContext context, String userName, String reposName) {
55-
return NavigatorRouter(context, RepositoryDetailPage(userName, reposName));
56+
///利用 SizeRoute 动画大小打开
57+
return Navigator.push(context,
58+
new SizeRoute(widget: pageContainer(RepositoryDetailPage(userName, reposName))));
5659
}
5760

5861
///仓库版本列表
@@ -199,8 +202,18 @@ class NavigatorUtils {
199202
NavigatorRouter(context, new UserProfileInfo());
200203
}
201204

205+
///公共打开方式
202206
static NavigatorRouter(BuildContext context, Widget widget) {
203207
return Navigator.push(
204-
context, new CupertinoPageRoute(builder: (context) => widget));
208+
context, new CupertinoPageRoute(builder: (context) => pageContainer(widget)));
209+
}
210+
211+
///Page页面的容器,做一次通用自定义
212+
static Widget pageContainer(widget) {
213+
return MediaQuery(
214+
///不受系统字体缩放影响
215+
data: MediaQueryData.fromWindow(WidgetsBinding.instance.window)
216+
.copyWith(textScaleFactor: 1),
217+
child: widget);
205218
}
206219
}

lib/main.dart

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import 'package:redux/redux.dart';
1919
import 'package:gsy_github_app_flutter/common/net/code.dart';
2020

2121
import 'common/event/index.dart';
22+
import 'common/utils/navigator_utils.dart';
2223

2324
void main() {
2425
runZoned(() {
@@ -38,7 +39,10 @@ class FlutterReduxApp extends StatelessWidget {
3839
middleware: middleware,
3940

4041
///初始化数据
41-
initialState: new GSYState(userInfo: User.empty(), themeData: CommonUtils.getThemeData(GSYColors.primarySwatch), locale: Locale('zh', 'CH')),
42+
initialState: new GSYState(
43+
userInfo: User.empty(),
44+
themeData: CommonUtils.getThemeData(GSYColors.primarySwatch),
45+
locale: Locale('zh', 'CH')),
4246
);
4347

4448
FlutterReduxApp({Key key}) : super(key: key);
@@ -68,13 +72,11 @@ class FlutterReduxApp extends StatelessWidget {
6872
HomePage.sName: (context) {
6973
///通过 Localizations.override 包裹一层,
7074
return new GSYLocalizations(
71-
child: new HomePage(),
72-
);
75+
child: NavigatorUtils.pageContainer(new HomePage()));
7376
},
7477
LoginPage.sName: (context) {
7578
return new GSYLocalizations(
76-
child: new LoginPage(),
77-
);
79+
child: NavigatorUtils.pageContainer(new LoginPage()));
7880
},
7981
});
8082
}),
@@ -128,23 +130,31 @@ class _GSYLocalizations extends State<GSYLocalizations> {
128130
errorHandleFunction(int code, message) {
129131
switch (code) {
130132
case Code.NETWORK_ERROR:
131-
Fluttertoast.showToast(msg: CommonUtils.getLocale(context).network_error);
133+
Fluttertoast.showToast(
134+
msg: CommonUtils.getLocale(context).network_error);
132135
break;
133136
case 401:
134-
Fluttertoast.showToast(msg: CommonUtils.getLocale(context).network_error_401);
137+
Fluttertoast.showToast(
138+
msg: CommonUtils.getLocale(context).network_error_401);
135139
break;
136140
case 403:
137-
Fluttertoast.showToast(msg: CommonUtils.getLocale(context).network_error_403);
141+
Fluttertoast.showToast(
142+
msg: CommonUtils.getLocale(context).network_error_403);
138143
break;
139144
case 404:
140-
Fluttertoast.showToast(msg: CommonUtils.getLocale(context).network_error_404);
145+
Fluttertoast.showToast(
146+
msg: CommonUtils.getLocale(context).network_error_404);
141147
break;
142148
case Code.NETWORK_TIMEOUT:
143149
//超时
144-
Fluttertoast.showToast(msg: CommonUtils.getLocale(context).network_error_timeout);
150+
Fluttertoast.showToast(
151+
msg: CommonUtils.getLocale(context).network_error_timeout);
145152
break;
146153
default:
147-
Fluttertoast.showToast(msg: CommonUtils.getLocale(context).network_error_unknown + " " + message);
154+
Fluttertoast.showToast(
155+
msg: CommonUtils.getLocale(context).network_error_unknown +
156+
" " +
157+
message);
148158
break;
149159
}
150160
}

0 commit comments

Comments
 (0)