Skip to content

Commit 25ba45d

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

File tree

5 files changed

+94
-30
lines changed

5 files changed

+94
-30
lines changed

lib/common/utils/common_utils.dart

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class CommonUtils {
4242
static double sStaticBarHeight = 0.0;
4343

4444
static void initStatusBarHeight(context) async {
45-
sStaticBarHeight = await FlutterStatusbar.height / MediaQuery.of(context).devicePixelRatio;
45+
sStaticBarHeight =
46+
await FlutterStatusbar.height / MediaQuery.of(context).devicePixelRatio;
4647
}
4748

4849
static String getDateStr(DateTime date) {
@@ -55,12 +56,16 @@ class CommonUtils {
5556
}
5657

5758
static String getUserChartAddress(String userName) {
58-
return Address.graphicHost + GSYColors.primaryValueString.replaceAll("#", "") + "/" + userName;
59+
return Address.graphicHost +
60+
GSYColors.primaryValueString.replaceAll("#", "") +
61+
"/" +
62+
userName;
5963
}
6064

6165
///日期格式转换
6266
static String getNewsTimeStr(DateTime date) {
63-
int subTime = DateTime.now().millisecondsSinceEpoch - date.millisecondsSinceEpoch;
67+
int subTime =
68+
DateTime.now().millisecondsSinceEpoch - date.millisecondsSinceEpoch;
6469

6570
if (subTime < MILLIS_LIMIT) {
6671
return "刚刚";
@@ -84,9 +89,12 @@ class CommonUtils {
8489
} else {
8590
appDir = await getExternalStorageDirectory();
8691
}
87-
PermissionStatus permission = await PermissionHandler().checkPermissionStatus(PermissionGroup.storage);
92+
PermissionStatus permission = await PermissionHandler()
93+
.checkPermissionStatus(PermissionGroup.storage);
8894
if (permission != PermissionStatus.granted) {
89-
Map<PermissionGroup, PermissionStatus> permissions = await PermissionHandler().requestPermissions([PermissionGroup.storage]);
95+
Map<PermissionGroup, PermissionStatus> permissions =
96+
await PermissionHandler()
97+
.requestPermissions([PermissionGroup.storage]);
9098
if (permissions[PermissionGroup.storage] != PermissionStatus.granted) {
9199
return null;
92100
}
@@ -120,14 +128,16 @@ class CommonUtils {
120128
}
121129

122130
static getFullName(String repository_url) {
123-
if (repository_url != null && repository_url.substring(repository_url.length - 1) == "/") {
131+
if (repository_url != null &&
132+
repository_url.substring(repository_url.length - 1) == "/") {
124133
repository_url = repository_url.substring(0, repository_url.length - 1);
125134
}
126135
String fullName = '';
127136
if (repository_url != null) {
128137
List<String> splicurl = repository_url.split("/");
129138
if (splicurl.length > 2) {
130-
fullName = splicurl[splicurl.length - 2] + "/" + splicurl[splicurl.length - 1];
139+
fullName =
140+
splicurl[splicurl.length - 2] + "/" + splicurl[splicurl.length - 1];
131141
}
132142
}
133143
return fullName;
@@ -140,7 +150,6 @@ class CommonUtils {
140150
store.dispatch(new RefreshThemeDataAction(themeData));
141151
}
142152

143-
144153
static getThemeData(Color color) {
145154
return ThemeData(primarySwatch: color, platform: TargetPlatform.android);
146155
}
@@ -191,7 +200,8 @@ class CommonUtils {
191200

192201
static copy(String data, BuildContext context) {
193202
Clipboard.setData(new ClipboardData(text: data));
194-
Fluttertoast.showToast(msg: CommonUtils.getLocale(context).option_share_copy_success);
203+
Fluttertoast.showToast(
204+
msg: CommonUtils.getLocale(context).option_share_copy_success);
195205
}
196206

197207
static launchUrl(context, String url) {
@@ -206,7 +216,9 @@ class CommonUtils {
206216
return;
207217
}
208218

209-
if (parseUrl != null && parseUrl.host == "github.com" && parseUrl.path.length > 0) {
219+
if (parseUrl != null &&
220+
parseUrl.host == "github.com" &&
221+
parseUrl.path.length > 0) {
210222
List<String> pathnames = parseUrl.path.split("/");
211223
if (pathnames.length == 2) {
212224
//解析人
@@ -232,20 +244,27 @@ class CommonUtils {
232244
NavigatorUtils.goGSYWebView(context, url, title);
233245
} else {
234246
NavigatorUtils.goGSYWebView(
235-
context, new Uri.dataFromString(url, mimeType: 'text/html', encoding: Encoding.getByName("utf-8")).toString(), title);
247+
context,
248+
new Uri.dataFromString(url,
249+
mimeType: 'text/html', encoding: Encoding.getByName("utf-8"))
250+
.toString(),
251+
title);
236252
}
237253
}
238254

239255
static launchOutURL(String url, BuildContext context) async {
240256
if (await canLaunch(url)) {
241257
await launch(url);
242258
} else {
243-
Fluttertoast.showToast(msg: CommonUtils.getLocale(context).option_web_launcher_error + ": " + url);
259+
Fluttertoast.showToast(
260+
msg: CommonUtils.getLocale(context).option_web_launcher_error +
261+
": " +
262+
url);
244263
}
245264
}
246265

247266
static Future<Null> showLoadingDialog(BuildContext context) {
248-
return showDialog(
267+
return NavigatorUtils.showGSYDialog(
249268
context: context,
250269
builder: (BuildContext context) {
251270
return new Material(
@@ -265,9 +284,14 @@ class CommonUtils {
265284
child: new Column(
266285
mainAxisAlignment: MainAxisAlignment.center,
267286
children: <Widget>[
268-
new Container(child: SpinKitCubeGrid(color: Color(GSYColors.white))),
287+
new Container(
288+
child:
289+
SpinKitCubeGrid(color: Color(GSYColors.white))),
269290
new Container(height: 10.0),
270-
new Container(child: new Text(CommonUtils.getLocale(context).loading_text, style: GSYConstant.normalTextWhite)),
291+
new Container(
292+
child: new Text(
293+
CommonUtils.getLocale(context).loading_text,
294+
style: GSYConstant.normalTextWhite)),
271295
],
272296
),
273297
),
@@ -286,7 +310,7 @@ class CommonUtils {
286310
TextEditingController valueController,
287311
bool needTitle = true,
288312
}) {
289-
return showDialog(
313+
return NavigatorUtils.showGSYDialog(
290314
context: context,
291315
builder: (BuildContext context) {
292316
return Center(
@@ -303,6 +327,7 @@ class CommonUtils {
303327
});
304328
}
305329

330+
///列表item dialog
306331
static Future<Null> showCommitOptionDialog(
307332
BuildContext context,
308333
List<String> commitMaps,
@@ -311,7 +336,7 @@ class CommonUtils {
311336
height = 400.0,
312337
List<Color> colorList,
313338
}) {
314-
return showDialog(
339+
return NavigatorUtils.showGSYDialog(
315340
context: context,
316341
builder: (BuildContext context) {
317342
return Center(
@@ -329,10 +354,12 @@ class CommonUtils {
329354
itemCount: commitMaps.length,
330355
itemBuilder: (context, index) {
331356
return GSYFlexButton(
332-
maxLines: 2,
357+
maxLines: 1,
333358
mainAxisAlignment: MainAxisAlignment.start,
334359
fontSize: 14.0,
335-
color: colorList != null ? colorList[index] : Theme.of(context).primaryColor,
360+
color: colorList != null
361+
? colorList[index]
362+
: Theme.of(context).primaryColor,
336363
text: commitMaps[index],
337364
textColor: Color(GSYColors.white),
338365
onPress: () {
@@ -347,8 +374,9 @@ class CommonUtils {
347374
}
348375

349376
///版本更新
350-
static Future<Null> showUpdateDialog(BuildContext context, String contentMsg) {
351-
return showDialog(
377+
static Future<Null> showUpdateDialog(
378+
BuildContext context, String contentMsg) {
379+
return NavigatorUtils.showGSYDialog(
352380
context: context,
353381
builder: (BuildContext context) {
354382
return AlertDialog(

lib/common/utils/navigator_utils.dart

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ class NavigatorUtils {
5454
static Future goReposDetail(
5555
BuildContext context, String userName, String reposName) {
5656
///利用 SizeRoute 动画大小打开
57-
return Navigator.push(context,
58-
new SizeRoute(widget: pageContainer(RepositoryDetailPage(userName, reposName))));
57+
return Navigator.push(
58+
context,
59+
new SizeRoute(
60+
widget: pageContainer(RepositoryDetailPage(userName, reposName))));
5961
}
6062

6163
///仓库版本列表
@@ -204,16 +206,35 @@ class NavigatorUtils {
204206

205207
///公共打开方式
206208
static NavigatorRouter(BuildContext context, Widget widget) {
207-
return Navigator.push(
208-
context, new CupertinoPageRoute(builder: (context) => pageContainer(widget)));
209+
return Navigator.push(context,
210+
new CupertinoPageRoute(builder: (context) => pageContainer(widget)));
209211
}
210212

211213
///Page页面的容器,做一次通用自定义
212214
static Widget pageContainer(widget) {
213215
return MediaQuery(
216+
214217
///不受系统字体缩放影响
215218
data: MediaQueryData.fromWindow(WidgetsBinding.instance.window)
216219
.copyWith(textScaleFactor: 1),
217220
child: widget);
218221
}
222+
223+
///弹出 dialog
224+
static Future<T> showGSYDialog<T>({
225+
@required BuildContext context,
226+
bool barrierDismissible = true,
227+
WidgetBuilder builder,
228+
}) {
229+
return showDialog<T>(
230+
context: context,
231+
barrierDismissible: barrierDismissible,
232+
builder: (context) {
233+
return MediaQuery(
234+
///不受系统字体缩放影响
235+
data: MediaQueryData.fromWindow(WidgetsBinding.instance.window)
236+
.copyWith(textScaleFactor: 1),
237+
child: new SafeArea(child: builder(context)));
238+
});
239+
}
219240
}

lib/page/issue_detail_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class _IssueDetailPageState extends State<IssueDetailPage>
6565
hideBottom: true,
6666
limitComment: false,
6767
onPressed: () {
68-
showDialog(
68+
NavigatorUtils.showGSYDialog(
6969
context: context,
7070
builder: (BuildContext context) {
7171
return new Center(

lib/widget/gsy_flex_button.dart

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,34 @@ class GSYFlexButton extends StatelessWidget {
2020
final MainAxisAlignment mainAxisAlignment;
2121

2222
GSYFlexButton(
23-
{Key key, this.text, this.color, this.textColor, this.onPress, this.fontSize = 20.0, this.mainAxisAlignment = MainAxisAlignment.center, this.maxLines = 1})
23+
{Key key,
24+
this.text,
25+
this.color,
26+
this.textColor,
27+
this.onPress,
28+
this.fontSize = 20.0,
29+
this.mainAxisAlignment = MainAxisAlignment.center,
30+
this.maxLines = 1})
2431
: super(key: key);
2532

2633
@override
2734
Widget build(BuildContext context) {
2835
return new RaisedButton(
29-
padding: new EdgeInsets.only(left: 20.0, top: 10.0, right: 20.0, bottom: 10.0),
36+
padding: new EdgeInsets.only(
37+
left: 20.0, top: 10.0, right: 20.0, bottom: 10.0),
3038
textColor: textColor,
3139
color: color,
3240
child: new Flex(
3341
mainAxisAlignment: mainAxisAlignment,
3442
direction: Axis.horizontal,
35-
children: <Widget>[new Text(text, style: new TextStyle(fontSize: fontSize), maxLines: maxLines, overflow:TextOverflow.ellipsis)],
43+
children: <Widget>[
44+
new Expanded(
45+
child: new Text(text,
46+
style: new TextStyle(fontSize: fontSize),
47+
maxLines: maxLines,
48+
overflow: TextOverflow.ellipsis),
49+
)
50+
],
3651
),
3752
onPressed: () {
3853
this.onPress?.call();

lib/widget/home_drawer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import 'package:redux/redux.dart';
2424
class HomeDrawer extends StatelessWidget {
2525
showAboutDialog(BuildContext context, String versionName) {
2626
versionName ??= "Null";
27-
showDialog(
27+
NavigatorUtils.showGSYDialog(
2828
context: context,
2929
builder: (BuildContext context) => AboutDialog(
3030
applicationName: CommonUtils.getLocale(context).app_name,

0 commit comments

Comments
 (0)