简体   繁体   English

Flutter 应用程序在模拟器(Pixel 4)上呈现良好,但在物理设备上溢出

[英]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 :首先,定义screenHeightscreenWidthMediaQuery

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.

相关问题 无法在 iOS 仿真器或物理设备上构建 Flutter 应用程序 - 虽然在 Android 上工作正常 - Cannot build Flutter app on iOS emulator or physical device - works fine on Android though Flutter 应用程序在 Android 模拟器上运行,但不在物理设备上(OnePlus 7T) - Flutter app is running on Android Emulator but not on Physical Device (OnePlus 7T) Flutter 无法在物理设备上加载图像资产(但在模拟器上加载它就好了) - Flutter unable to load image asset on physical device (but loading it just fine on the emulator) 在物理设备上启动时,Android App卡在启动屏幕上,但在模拟器上运行良好 - Android App gets stuck on splashscreen when launched on physical device but works fine when on an emulator 仅在物理设备而非模拟器上运行 Android 应用 - Run Android app Only on Physical Device not Emulator 在物理设备和模拟器上显示应用程序的差异 - diference in showing app on physical device and emulator Flutter 应用程序在 android 工作室模拟器上完美运行,但 go 无法通过物理设备上的加载屏幕 - Flutter app runs perfectly on android studio emulator but doesn't go past the loading screen on physical device 物理设备不会显示,模拟器运行正常 - Physical device won't show up, Emulator works just fine Android系统。 模拟器突然出现问题,物理设备正常运行 - Android. Sudden problem with emulator, physical device works fine 如何检测应用程序是否安装在物理设备与虚拟设备/模拟器上? - How to detect if app is installed on a Physical Device Vs Virtual Device / Emulator?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM