简体   繁体   English

Flutter Web:底部溢出问题

[英]Flutter Web: Overflow issue in bottom

Code: Basically I have a simple app with three images aligned.代码:基本上我有一个简单的应用程序,三个图像对齐。 I have 1 column and two rows.我有 1 列和 2 行。 First row has two images and second row has 1 image aligned.第一行有两个图像,第二行有一个对齐的图像。 Its the structure of the app.它的应用程序的结构。 It just aligns perfectly when run below code in device but the moment I run on WEB there is this overflow.它只是在设备中的代码下方运行时完美对齐,但是当我在 WEB 上运行时,就会出现这种溢出。 I try resizing the browser window only then it begins to become pretty again.我尝试调整浏览器 window 的大小,然后它又开始变得漂亮了。 Is there a workaround for Flutter Web please on how should I do the alignments here? Flutter Web 是否有解决方法,请问我应该如何在这里进行对齐? Below code is inside body and inside Scaffold.下面的代码在主体内部和脚手架内部。 I am attaching pics from device where there is no issue and from Flutter web where there is overflow issue.我从没有问题的设备和有溢出问题的 Flutter web 附上图片。

return Column(
  mainAxisAlignment: MainAxisAlignment.center,
  //crossAxisAlignment: CrossAxisAlignment.stretch,
  children: <Widget>[
    Row(
      children: <Widget>[
        Expanded(
          child: FlatButton(
            child: Image.asset('images/image1.png'),
          ),
        ),
        Expanded(
          child: FlatButton(

            child: Image.asset('images/image1.png'),
          ),
        ),
      ],
    ),
    Row(
      children: <Widget>[
        Expanded(
          child: Image.asset('images/image1.png'),
        ),
      ],
    ),
  ],
);

} }

Error:错误:

══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════ The following assertion was thrown during layout: A RenderFlex overflowed by 1238 pixels on the bottom. ══╡渲染图书馆捕获的例外╞═════════════════════════════════════════ ════════════════ 在布局过程中抛出了以下断言: A RenderFlex 在底部溢出了 1238 个像素。

The relevant error-causing widget was: Column file:///C:/Users/1025632/Documents/GitHub/flutter-course/diceylips/lib/main.dart:43:12相关的导致错误的小部件是:Column file:///C:/Users/1025632/Documents/GitHub/flutter-course/diceylips/lib/main.dart:43:12

The overflowing RenderFlex has an orientation of Axis.vertical.溢出的 RenderFlex 具有 Axis.vertical 的方向。 The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and black striped pattern.溢出的 RenderFlex 边缘已在渲染中用黄色和黑色条纹图案标记。 This is usually caused by the contents being too big for the RenderFlex.这通常是由于内容对于 RenderFlex 来说太大了。 Consider applying a flex factor (eg using an Expanded widget) to force the children of the RenderFlex to fit within the available space instead of being sized to their natural size.考虑应用一个弹性因子(例如使用 Expanded 小部件)来强制 RenderFlex 的子级适应可用空间,而不是调整到它们的自然大小。 This is considered an error condition because it indicates that there is content that cannot be seen.这被认为是一种错误情况,因为它表明存在看不到的内容。 If the content is legitimately bigger than the available space, consider clipping it with a ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex, like a ListView.如果内容合法地大于可用空间,请考虑在将其放入 flex 之前使用 ClipRect 小部件对其进行剪辑,或者使用可滚动容器而不是 Flex,例如 ListView。 The specific RenderFlex in question is: RenderFlex#1ad1e relayoutBoundary=up1 OVERFLOWING: creator: Column ← DicePage ← _BodyBuilder ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ← CustomMultiChildLayout ← AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#cb60e ink renderer] ← NotificationListener ← PhysicalModel ← ⋯ parentData: offset=Offset(0.0, 56.0);有问题的具体 RenderFlex 是: RenderFlex#1ad1e relayoutBoundary=up1 OVERFLOWING: creator: Column ← DicePage ← _BodyBuilder ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ← CustomMultiChildLayout ← AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#cb60e ink renderer] ← NotificationListener ← PhysicalModel ← ⋯ parentData: offset=Offset(0.0, 56.0); id=_ScaffoldSlot.body (can use size) constraints: BoxConstraints(0.0<=w<=1280.0, 0.0<=h<=554.0) size: Size(1280.0, 554.0) id=_ScaffoldSlot.body(可以使用大小)约束:BoxConstraints(0.0<=w<=1280.0, 0.0<=h<=554.0) 大小:Size(1280.0, 554.0)

direction: vertical mainAxisAlignment: center mainAxisSize: max crossAxisAlignment: center verticalDirection: down方向:垂直 mainAxisAlignment:中心 mainAxisSize:最大 crossAxisAlignment:中心verticalDirection:向下

Image with no issue in device Image with overflow issue in chrome设备中没有问题的图像 chrome 中存在溢出问题的图像

Wrap the column with a sized box or container with defined height and width用具有定义的高度和宽度的大小框或容器包裹列

SizedBox(
height:200,
width:200,
child: your column goes here,
)


Add below code inside Container在容器内添加以下代码

Container(

         width: MediaQuery.of(context).size.width,
         height: MediaQuery.of(context).size.height,
....
....
)

This is the generic way to define full width and height to your Container这是定义容器全宽和全高的通用方法

If you don't try to fit your widget in screen and scroll is an option for you, you can use listview or a similar widget.如果您不尝试将小部件放入屏幕并且滚动是您的选择,您可以使用 listview 或类似的小部件。

ListView(
     children: <Widget>[
              Column(

Otherwise, wrapping Container with MediaQuery.of(context).size.width and MediaQuery.of(context).size.height will work but there is just one catch here, if you use an appbar this height should be "MediaQuery.of(context).size.height - AppBar().preferredSize.height"否则,用 MediaQuery.of(context).size.width 和 MediaQuery.of(context).size.height 包装 Container 将起作用,但这里只有一个问题,如果你使用 appbar,这个高度应该是“MediaQuery.of(上下文).size.height - AppBar().preferredSize.height"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM