Showing
6 changed files
with
87 additions
and
12 deletions
@@ -58,13 +58,11 @@ class MyApp extends StatelessWidget { | @@ -58,13 +58,11 @@ class MyApp extends StatelessWidget { | ||
58 | } | 58 | } |
59 | } | 59 | } |
60 | ``` | 60 | ``` |
61 | -The second way: | 61 | +The second way:Does not support the use of font adaptation in the App |
62 | ``` | 62 | ``` |
63 | class MyApp extends StatelessWidget { | 63 | class MyApp extends StatelessWidget { |
64 | @override | 64 | @override |
65 | Widget build(BuildContext context) { | 65 | Widget build(BuildContext context) { |
66 | - //Set the fit size (fill in the screen size of the device in the design) If the design is based on the size of the 360*690 | ||
67 | - ScreenUtil.init(BoxConstraints(maxWidth: 360, maxHeight: 690)); | ||
68 | return MaterialApp( | 66 | return MaterialApp( |
69 | debugShowCheckedModeBanner: false, | 67 | debugShowCheckedModeBanner: false, |
70 | title: 'Flutter_ScreenUtil', | 68 | title: 'Flutter_ScreenUtil', |
@@ -75,6 +73,30 @@ class MyApp extends StatelessWidget { | @@ -75,6 +73,30 @@ class MyApp extends StatelessWidget { | ||
75 | ); | 73 | ); |
76 | } | 74 | } |
77 | } | 75 | } |
76 | + | ||
77 | +class HomePage extends StatefulWidget { | ||
78 | + const HomePage({Key key, this.title}) : super(key: key); | ||
79 | + | ||
80 | + final String title; | ||
81 | + | ||
82 | + @override | ||
83 | + _HomePageState createState() => _HomePageState(); | ||
84 | +} | ||
85 | + | ||
86 | +class _HomePageState extends State<HomePage> { | ||
87 | + @override | ||
88 | + Widget build(BuildContext context) { | ||
89 | + //Set the fit size (fill in the screen size of the device in the design) If the design is based on the size of the 360*690(dp) | ||
90 | + ScreenUtil.init( | ||
91 | + BoxConstraints( | ||
92 | + maxWidth: MediaQuery.of(context).size.width, | ||
93 | + maxHeight: MediaQuery.of(context).size.height), | ||
94 | + designSize: Size(360, 690), | ||
95 | + allowFontScaling: false, | ||
96 | + orientation: Orientation.portrait); | ||
97 | + return Scaffold(); | ||
98 | + } | ||
99 | +} | ||
78 | ``` | 100 | ``` |
79 | 101 | ||
80 | ### Use: | 102 | ### Use: |
@@ -69,13 +69,11 @@ class MyApp extends StatelessWidget { | @@ -69,13 +69,11 @@ class MyApp extends StatelessWidget { | ||
69 | } | 69 | } |
70 | } | 70 | } |
71 | ``` | 71 | ``` |
72 | -方式二: | 72 | +方式二: 不支持在App中使用字体适配 |
73 | ``` | 73 | ``` |
74 | class MyApp extends StatelessWidget { | 74 | class MyApp extends StatelessWidget { |
75 | @override | 75 | @override |
76 | Widget build(BuildContext context) { | 76 | Widget build(BuildContext context) { |
77 | - //填入设计稿中设备的屏幕尺寸 (例如:360*690) , 单位dp | ||
78 | - ScreenUtil.init(BoxConstraints(maxWidth: 360, maxHeight: 690)); | ||
79 | return MaterialApp( | 77 | return MaterialApp( |
80 | debugShowCheckedModeBanner: false, | 78 | debugShowCheckedModeBanner: false, |
81 | title: 'Flutter_ScreenUtil', | 79 | title: 'Flutter_ScreenUtil', |
@@ -86,6 +84,30 @@ class MyApp extends StatelessWidget { | @@ -86,6 +84,30 @@ class MyApp extends StatelessWidget { | ||
86 | ); | 84 | ); |
87 | } | 85 | } |
88 | } | 86 | } |
87 | + | ||
88 | +class HomePage extends StatefulWidget { | ||
89 | + const HomePage({Key key, this.title}) : super(key: key); | ||
90 | + | ||
91 | + final String title; | ||
92 | + | ||
93 | + @override | ||
94 | + _HomePageState createState() => _HomePageState(); | ||
95 | +} | ||
96 | + | ||
97 | +class _HomePageState extends State<HomePage> { | ||
98 | + @override | ||
99 | + Widget build(BuildContext context) { | ||
100 | + //设置尺寸(填写设计中设备的屏幕尺寸)如果设计基于360dp * 690dp的屏幕 | ||
101 | + ScreenUtil.init( | ||
102 | + BoxConstraints( | ||
103 | + maxWidth: MediaQuery.of(context).size.width, | ||
104 | + maxHeight: MediaQuery.of(context).size.height), | ||
105 | + designSize: Size(360, 690), | ||
106 | + allowFontScaling: false, | ||
107 | + orientation: Orientation.portrait); | ||
108 | + return Scaffold(); | ||
109 | + } | ||
110 | +} | ||
89 | ``` | 111 | ``` |
90 | 112 | ||
91 | ### 使用 | 113 | ### 使用 |
@@ -62,13 +62,11 @@ class MyApp extends StatelessWidget { | @@ -62,13 +62,11 @@ class MyApp extends StatelessWidget { | ||
62 | } | 62 | } |
63 | } | 63 | } |
64 | ``` | 64 | ``` |
65 | -The second way: | 65 | +The second way:Does not support the use of font adaptation in the App |
66 | ``` | 66 | ``` |
67 | class MyApp extends StatelessWidget { | 67 | class MyApp extends StatelessWidget { |
68 | @override | 68 | @override |
69 | Widget build(BuildContext context) { | 69 | Widget build(BuildContext context) { |
70 | - //Set the fit size (fill in the screen size of the device in the design) If the design is based on the size of the 360*690 | ||
71 | - ScreenUtil.init(BoxConstraints(maxWidth: 360, maxHeight: 690)); | ||
72 | return MaterialApp( | 70 | return MaterialApp( |
73 | debugShowCheckedModeBanner: false, | 71 | debugShowCheckedModeBanner: false, |
74 | title: 'Flutter_ScreenUtil', | 72 | title: 'Flutter_ScreenUtil', |
@@ -79,6 +77,30 @@ class MyApp extends StatelessWidget { | @@ -79,6 +77,30 @@ class MyApp extends StatelessWidget { | ||
79 | ); | 77 | ); |
80 | } | 78 | } |
81 | } | 79 | } |
80 | + | ||
81 | +class HomePage extends StatefulWidget { | ||
82 | + const HomePage({Key key, this.title}) : super(key: key); | ||
83 | + | ||
84 | + final String title; | ||
85 | + | ||
86 | + @override | ||
87 | + _HomePageState createState() => _HomePageState(); | ||
88 | +} | ||
89 | + | ||
90 | +class _HomePageState extends State<HomePage> { | ||
91 | + @override | ||
92 | + Widget build(BuildContext context) { | ||
93 | + //Set the fit size (fill in the screen size of the device in the design) If the design is based on the size of the 360*690(dp) | ||
94 | + ScreenUtil.init( | ||
95 | + BoxConstraints( | ||
96 | + maxWidth: MediaQuery.of(context).size.width, | ||
97 | + maxHeight: MediaQuery.of(context).size.height), | ||
98 | + designSize: Size(360, 690), | ||
99 | + allowFontScaling: false, | ||
100 | + orientation: Orientation.portrait); | ||
101 | + return Scaffold(); | ||
102 | + } | ||
103 | +} | ||
82 | ``` | 104 | ``` |
83 | 105 | ||
84 | ### Uso: | 106 | ### Uso: |
@@ -6,8 +6,6 @@ void main() => runApp(MyApp()); | @@ -6,8 +6,6 @@ void main() => runApp(MyApp()); | ||
6 | class MyApp extends StatelessWidget { | 6 | class MyApp extends StatelessWidget { |
7 | @override | 7 | @override |
8 | Widget build(BuildContext context) { | 8 | Widget build(BuildContext context) { |
9 | - //Set the fit size (fill in the screen size of the device in the design) If the design is based on the size of the iPhone6 360*690 | ||
10 | - ScreenUtil.init(BoxConstraints(maxWidth: 360, maxHeight: 690)); | ||
11 | return MaterialApp( | 9 | return MaterialApp( |
12 | debugShowCheckedModeBanner: false, | 10 | debugShowCheckedModeBanner: false, |
13 | title: 'Flutter_ScreenUtil', | 11 | title: 'Flutter_ScreenUtil', |
@@ -31,6 +29,14 @@ class HomePage extends StatefulWidget { | @@ -31,6 +29,14 @@ class HomePage extends StatefulWidget { | ||
31 | class _HomePageState extends State<HomePage> { | 29 | class _HomePageState extends State<HomePage> { |
32 | @override | 30 | @override |
33 | Widget build(BuildContext context) { | 31 | Widget build(BuildContext context) { |
32 | + //Set the fit size (fill in the screen size of the device in the design) If the design is based on the size of the 360*690 | ||
33 | + ScreenUtil.init( | ||
34 | + BoxConstraints( | ||
35 | + maxWidth: MediaQuery.of(context).size.width, | ||
36 | + maxHeight: MediaQuery.of(context).size.height), | ||
37 | + designSize: Size(360, 690), | ||
38 | + allowFontScaling: false, | ||
39 | + orientation: Orientation.portrait); | ||
34 | printScreenInformation(); | 40 | printScreenInformation(); |
35 | return Scaffold( | 41 | return Scaffold( |
36 | appBar: AppBar( | 42 | appBar: AppBar( |
1 | name: flutter_screenutil | 1 | name: flutter_screenutil |
2 | description: A flutter plugin for adapting screen and font size.Guaranteed to look good on different models | 2 | description: A flutter plugin for adapting screen and font size.Guaranteed to look good on different models |
3 | -version: 5.0.0-nullsafety.8 | 3 | +version: 5.0.0-nullsafety.9 |
4 | homepage: https://github.com/OpenFlutter/flutter_screenutil | 4 | homepage: https://github.com/OpenFlutter/flutter_screenutil |
5 | 5 | ||
6 | environment: | 6 | environment: |
-
Please register or login to post a comment