李卓原

优化示例代码

Showing 1 changed file with 17 additions and 14 deletions
@@ -59,18 +59,11 @@ height: ScreenUtil().setHeight(200), @@ -59,18 +59,11 @@ height: ScreenUtil().setHeight(200),
59 ``` 59 ```
60 import 'package:flutter_app/ScreenUtil.dart'; //导入 60 import 'package:flutter_app/ScreenUtil.dart'; //导入
61 61
62 -@override  
63 - Widget build(BuildContext context) { 62 +...
64 63
65 - print(ScreenUtil().setWidth(180));  
66 - print('设备的像素密度:${ScreenUtil.pixelRatio}'); //设备的像素密度  
67 - print('设备宽度:${ScreenUtil.screenWidth}'); //设备宽度  
68 - print('设备高度:${ScreenUtil.screenHeight}'); //设备高度  
69 - print('底部安全区距离:${ScreenUtil.bottomBarHeight}'); //底部安全区距离,适用于全面屏下面有按键的  
70 - print('状态栏高度:${ScreenUtil.statusBarHeight}px'); //状态栏高度 刘海屏会更高  
71 64
72 - print('宽度相对于设计稿放大的倍数:${ScreenUtil().scaleWidth}'); //宽度相对于设计稿放大的倍数  
73 - print('高度相对于设计稿放大的倍数:${ScreenUtil().scaleHeight}'); //高度相对于设计稿放大的倍数 65 + @override
  66 + Widget build(BuildContext context) {
74 return new Scaffold( 67 return new Scaffold(
75 appBar: new AppBar( 68 appBar: new AppBar(
76 title: new Text(widget.title), 69 title: new Text(widget.title),
@@ -84,20 +77,30 @@ import 'package:flutter_app/ScreenUtil.dart'; //导入 @@ -84,20 +77,30 @@ import 'package:flutter_app/ScreenUtil.dart'; //导入
84 width: ScreenUtil().setWidth(375), 77 width: ScreenUtil().setWidth(375),
85 height: ScreenUtil().setHeight(200), 78 height: ScreenUtil().setHeight(200),
86 color: Colors.red, 79 color: Colors.red,
87 - child: Text(ScreenUtil().setWidth(375).toString()), 80 + child: Text(
  81 + '我的宽度${ScreenUtil().setWidth(375)}dp',
  82 + style: TextStyle(color: Colors.white),
  83 + ),
88 ), 84 ),
89 Container( 85 Container(
90 width: ScreenUtil().setWidth(375), 86 width: ScreenUtil().setWidth(375),
91 height: ScreenUtil().setHeight(200), 87 height: ScreenUtil().setHeight(200),
92 color: Colors.blue, 88 color: Colors.blue,
93 - child: Text(ScreenUtil().setWidth(375).toString()), 89 + child: Text('我的宽度${ScreenUtil().setWidth(375)}dp',
  90 + style: TextStyle(color: Colors.white)),
94 ), 91 ),
95 ], 92 ],
96 ), 93 ),
97 - Text(ScreenUtil.screenWidth.toString()),  
98 - Text(ScreenUtil.screenHeight.toString()), 94 + Text('设备的屏幕宽度:${ScreenUtil.screenWidth}px'),
  95 + Text('设备的屏幕高度:${ScreenUtil.screenHeight}px'),
  96 + Text('设备的像素密度:${ScreenUtil.pixelRatio}'),
  97 + Text('底部安全区距离:${ScreenUtil.bottomBarHeight}px'),
  98 + Text('状态栏高度:${ScreenUtil.statusBarHeight}px'),
  99 + Text('宽度相对于设计稿放大的倍数:${ScreenUtil().scaleWidth}'),
  100 + Text('高度相对于设计稿放大的倍数:${ScreenUtil().scaleHeight}'),
99 ], 101 ],
100 ), 102 ),
  103 + ),
101 ); 104 );
102 } 105 }
103 ``` 106 ```