Showing
3 changed files
with
16 additions
and
7 deletions
1 | +import 'dart:ui'; | ||
2 | + | ||
1 | import 'package:flutter/material.dart'; | 3 | import 'package:flutter/material.dart'; |
2 | import 'package:flutter_screenutil/flutter_screenutil.dart'; | 4 | import 'package:flutter_screenutil/flutter_screenutil.dart'; |
3 | 5 | ||
@@ -50,7 +52,7 @@ class _HomePageState extends State<HomePage> { | @@ -50,7 +52,7 @@ class _HomePageState extends State<HomePage> { | ||
50 | Container( | 52 | Container( |
51 | padding: EdgeInsets.all(ScreenUtil().setWidth(10)), | 53 | padding: EdgeInsets.all(ScreenUtil().setWidth(10)), |
52 | width: 180.w, | 54 | width: 180.w, |
53 | - height: 200.h, | 55 | + height: 120.h, |
54 | color: Colors.red, | 56 | color: Colors.red, |
55 | child: Text( | 57 | child: Text( |
56 | '我的实际宽度:${180.w}dp \n' | 58 | '我的实际宽度:${180.w}dp \n' |
@@ -7,6 +7,7 @@ library flutter_screenutil; | @@ -7,6 +7,7 @@ library flutter_screenutil; | ||
7 | 7 | ||
8 | import 'dart:math'; | 8 | import 'dart:math'; |
9 | import 'dart:ui' as ui; | 9 | import 'dart:ui' as ui; |
10 | +import 'dart:ui'; | ||
10 | 11 | ||
11 | import 'package:flutter/material.dart'; | 12 | import 'package:flutter/material.dart'; |
12 | 13 |
@@ -5,28 +5,34 @@ class ScreenUtilInit extends StatelessWidget { | @@ -5,28 +5,34 @@ class ScreenUtilInit extends StatelessWidget { | ||
5 | ScreenUtilInit({ | 5 | ScreenUtilInit({ |
6 | required this.builder, | 6 | required this.builder, |
7 | this.designSize = ScreenUtil.defaultSize, | 7 | this.designSize = ScreenUtil.defaultSize, |
8 | + this.splitScreenMode = true, | ||
8 | Key? key, | 9 | Key? key, |
9 | }) : super(key: key); | 10 | }) : super(key: key); |
10 | 11 | ||
11 | final Widget Function() builder; | 12 | final Widget Function() builder; |
13 | + final bool splitScreenMode; | ||
12 | 14 | ||
13 | /// The [Size] of the device in the design draft, in dp | 15 | /// The [Size] of the device in the design draft, in dp |
14 | final Size designSize; | 16 | final Size designSize; |
15 | - BoxConstraints constraints1 = BoxConstraints(maxHeight: 0.0); | ||
16 | 17 | ||
17 | @override | 18 | @override |
18 | Widget build(BuildContext context) { | 19 | Widget build(BuildContext context) { |
19 | return LayoutBuilder(builder: (_, BoxConstraints constraints) { | 20 | return LayoutBuilder(builder: (_, BoxConstraints constraints) { |
20 | - if (constraints.maxHeight > constraints1.maxHeight) { | ||
21 | - constraints1 = constraints; | 21 | + if (splitScreenMode) { |
22 | + constraints = BoxConstraints( | ||
23 | + minHeight: constraints.minHeight, | ||
24 | + maxHeight: max(constraints.maxHeight, 700), | ||
25 | + minWidth: constraints.minWidth, | ||
26 | + maxWidth: constraints.maxWidth); | ||
22 | } | 27 | } |
23 | - if (constraints1.maxWidth != 0) { | 28 | + |
29 | + if (constraints.maxWidth != 0) { | ||
24 | final Orientation orientation = | 30 | final Orientation orientation = |
25 | - constraints1.maxWidth > constraints1.maxHeight | 31 | + constraints.maxWidth > constraints.maxHeight |
26 | ? Orientation.landscape | 32 | ? Orientation.landscape |
27 | : Orientation.portrait; | 33 | : Orientation.portrait; |
28 | ScreenUtil.init( | 34 | ScreenUtil.init( |
29 | - constraints1, | 35 | + constraints, |
30 | orientation: orientation, | 36 | orientation: orientation, |
31 | designSize: designSize, | 37 | designSize: designSize, |
32 | ); | 38 | ); |
-
Please register or login to post a comment