zhuoyuan

修正宽度和高度为无视屏幕的方向

example添加textfield方便测试
@@ -31,6 +31,7 @@ class HomePageScaffold extends StatelessWidget { @@ -31,6 +31,7 @@ class HomePageScaffold extends StatelessWidget {
31 child: Column( 31 child: Column(
32 crossAxisAlignment: CrossAxisAlignment.start, 32 crossAxisAlignment: CrossAxisAlignment.start,
33 children: <Widget>[ 33 children: <Widget>[
  34 + TextField(),
34 Row( 35 Row(
35 children: <Widget>[ 36 children: <Widget>[
36 // Using Extensions 37 // Using Extensions
@@ -121,13 +121,43 @@ class ScreenUtil { @@ -121,13 +121,43 @@ class ScreenUtil {
121 121
122 /// 当前设备宽度 dp 122 /// 当前设备宽度 dp
123 /// The horizontal extent of this size. 123 /// The horizontal extent of this size.
124 - double get screenWidth =>  
125 - context != null ? MediaQuery.of(context!).size.width : _screenWidth; 124 + double get screenWidth {
  125 + if (_orientation == Orientation.landscape) {
  126 + return (context != null
  127 + ? MediaQuery.of(context!).size.height
  128 + : _screenHeight);
  129 + }
  130 + return context != null ? MediaQuery.of(context!).size.width : _screenWidth;
  131 + }
126 132
127 ///当前设备高度 dp 133 ///当前设备高度 dp
128 ///The vertical extent of this size. dp 134 ///The vertical extent of this size. dp
129 - double get screenHeight =>  
130 - context != null ? MediaQuery.of(context!).size.height : _screenHeight; 135 + double get screenHeight {
  136 + if (_orientation == Orientation.landscape) {
  137 + return context != null
  138 + ? MediaQuery.of(context!).size.width
  139 + : _screenWidth;
  140 + }
  141 + return context != null
  142 + ? MediaQuery.of(context!).size.height
  143 + : _screenHeight;
  144 + }
  145 +
  146 + Size get screenSize {
  147 + if (_orientation == Orientation.landscape) {
  148 + double width = (context != null
  149 + ? MediaQuery.of(context!).size.height
  150 + : _screenHeight) +
  151 + bottomBarHeight;
  152 + double height =
  153 + (context != null ? MediaQuery.of(context!).size.width : _screenWidth);
  154 +
  155 + return Size(width, height);
  156 + }
  157 + return Size(
  158 + context != null ? MediaQuery.of(context!).size.width : _screenWidth,
  159 + context != null ? MediaQuery.of(context!).size.height : _screenHeight);
  160 + }
131 161
132 /// 状态栏高度 dp 刘海屏会更高 162 /// 状态栏高度 dp 刘海屏会更高
133 /// The offset from the top, in dp 163 /// The offset from the top, in dp