[英]Flutter app renders fine on the emulator (Pixel 4) but overflows on physical device
I'm having a problem with my flutter app.我的颤振应用程序有问题。 When I run it on the emulator, everything works fine and it renders exactly how I want it to.当我在模拟器上运行它时,一切正常,它完全按照我想要的方式呈现。 However, when I attempt to run it on my physical device (Samsung S4 Mini), the bottom of the app says "bottom overflowed by 97 pixels".但是,当我尝试在我的物理设备(Samsung S4 Mini)上运行它时,应用程序底部显示“底部溢出 97 像素”。
The part that is overflowing is a "Get Started" button, which is supposed to open up the login screen.溢出的部分是“开始”按钮,它应该打开登录屏幕。
Everything works, but the only problem is that it overflows on the physical device.一切正常,但唯一的问题是它在物理设备上溢出。
This is a picture of the bottom of my emulator.这是我的模拟器底部的图片。 The blue is just there so I can see where the container ends.蓝色就在那里,所以我可以看到容器的尽头。
Here is the code for the Get Started Button:以下是“入门”按钮的代码:
Container(
child: GestureDetector(
onTap: () {
setState(() {
if(_pageState!= 1)
_pageState = 1;
else
_pageState = 0;
});
},
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [ Container(
color: Colors.blue,
margin: EdgeInsets.symmetric(horizontal: 0, vertical: 0),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 50),
child: Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black26,
blurRadius: 4.0,
spreadRadius: 2.0,
offset: Offset(2.0, 2.0), // shadow direction: bottom right
)
],
color: colorScheme[2],
border: Border.all(
color: colorScheme[2],
width: 2
),
borderRadius: BorderRadius.circular(50),
),
child: Container(
padding: EdgeInsets.symmetric(vertical: 10, horizontal: 80),
child: Text(
"Get Started",
style: TextStyle(
color: colorScheme[3],
fontFamily: "Nunita",
fontSize: 16.0,
fontWeight: FontWeight.bold
),
)
)
),
),
),
]
),
),
),
I'm new to flutter and I'm not really sure how to fix this issue.我是新手,我不确定如何解决这个问题。 All of the button code works, but the only problem is that the button isn't rendering on the actual device.所有按钮代码都可以工作,但唯一的问题是按钮没有在实际设备上呈现。 How can you fix this?你怎么能解决这个问题?
Using MediaQuery, we can design our apps to render all type of screens.使用 MediaQuery,我们可以设计我们的应用程序来呈现所有类型的屏幕。
You can get the screen width and height with MediaQuery
and fix the overflowing using it.您可以使用MediaQuery
获取屏幕宽度和高度,并使用它修复溢出。
First, define the screenHeight
and screenWidth
with MediaQuery
:首先,定义screenHeight
和screenWidth
与MediaQuery
:
screenHeight = MediaQuery.of(context).size.height;
screenWidth = MediaQuery.of(context).size.width;
Then, give your margin and padding values like in example below:然后,给出您的边距和填充值,如下例所示:
// example
padding: EdgeInsets.symmetric(vertical: screenHeight * 0.1, horizontal: screenWidth * 0.8),
// this means give 10% of screen height as vertical value and 80% of screen width as horizontal value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.