草庐IT

dart - 底部被 Infinity 像素溢出的 RenderFlex

coder 2023-07-24 原文

我有一个非常简单的控件,我试图在其中显示带有几个 TextFieldsDropdownButton
当应用程序在模拟器中运行时,我收到一条错误消息

BOTTOM OVERFLOWED BY Infinity PIXELS 

Stack Trace 提示了这个问题并指向了一些相关文档,但作为 Flutter 的新手,我不确定需要更改哪些内容。

我已经尝试了很多基于关于类似错误的问题的建议,但没有任何运气。

堆栈跟踪:

I/flutter (10708): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (10708): The following assertion was thrown during performLayout():
I/flutter (10708): RenderIndexedStack object was given an infinite size during layout.
I/flutter (10708): This probably means that it is a render object that tries to be as big as possible, but it was put
I/flutter (10708): inside another render object that allows its children to pick their own size.
I/flutter (10708): The nearest ancestor providing an unbounded width constraint is:
I/flutter (10708):   RenderFlex#1d3ef relayoutBoundary=up7 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (10708):   creator: Row ← Padding ← Container ← DefaultTextStyle ← Stack ← Listener ← _GestureSemantics ←
I/flutter (10708):   RawGestureDetector ← GestureDetector ← Semantics ← DropdownButton<String> ← Column ← ⋯
I/flutter (10708):   parentData: offset=Offset(0.0, 0.0) (can use size)
I/flutter (10708):   constraints: BoxConstraints(0.0<=w<=391.4, 0.0<=h<=Infinity)
I/flutter (10708):   size: MISSING
I/flutter (10708):   direction: horizontal
I/flutter (10708):   mainAxisAlignment: spaceBetween
I/flutter (10708):   mainAxisSize: min
I/flutter (10708):   crossAxisAlignment: center
I/flutter (10708):   textDirection: ltr
I/flutter (10708):   verticalDirection: down
I/flutter (10708): The nearest ancestor providing an unbounded height constraint is:
I/flutter (10708):   RenderFlex#bb3f8 relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (10708):   creator: Column ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ← CustomMultiChildLayout ←
I/flutter (10708):   AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#6a13f ink
I/flutter (10708):   renderer] ← NotificationListener<LayoutChangedNotification> ← PhysicalModel ←
I/flutter (10708):   AnimatedPhysicalModel ← Material ← ⋯
I/flutter (10708):   parentData: offset=Offset(0.0, 0.0); id=_ScaffoldSlot.body (can use size)
I/flutter (10708):   constraints: BoxConstraints(0.0<=w<=391.4, 0.0<=h<=659.9)
I/flutter (10708):   size: MISSING
I/flutter (10708):   direction: vertical
I/flutter (10708):   mainAxisAlignment: start
I/flutter (10708):   mainAxisSize: max
I/flutter (10708):   crossAxisAlignment: center
I/flutter (10708):   verticalDirection: down
I/flutter (10708): The constraints that applied to the RenderIndexedStack were:
I/flutter (10708):   BoxConstraints(unconstrained)
I/flutter (10708): The exact size it was given was:
I/flutter (10708):   Size(Infinity, Infinity)
I/flutter (10708): See https://flutter.io/layout/ for more information.

此处的代码已为简洁起见删除了 TextFields,因为有或没有它们都会发生错误。

代码

import 'package:flutter/material.dart';
import 'package:todo_app/model/todo.dart';
import 'package:todo_app/util/dbhelper.dart';
import 'package:intl/intl.dart';

class TodoDetail extends StatefulWidget {
  Todo todo;
  TodoDetail(Todo todo) {
    this.todo = todo;
    debugPrint("called ctor with " + todo.title + "!!");
  }

  @override
  State<StatefulWidget> createState() => TodoDetailState(todo);
}

class TodoDetailState extends State {
  final Todo todo;
  TodoDetailState(this.todo);

  final _priorites = ["High, Medium", "Low"];
  String _priority = "Low";
  TextEditingController titleController = TextEditingController();
  TextEditingController descriptionController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    titleController.text = todo.title;
    descriptionController.text = todo.description;
    TextStyle textStyle = Theme.of(context).textTheme.title;

    return Padding(
        padding: EdgeInsets.only(top: 35, right: 10, left: 10),
        child: Scaffold(
            appBar: AppBar(
              automaticallyImplyLeading: false,
              title: Text('Add New'), //todo.title
            ),
            body: Column(children: <Widget>[
              DropdownButton<String>(
                  isExpanded: true,
                  items: _priorites.map((String value) {
                    return DropdownMenuItem<String>(
                        value: value, child: Text(value));
                  }).toList(),
                  style: textStyle,
                  value: "Low",
                  onChanged: null)
            ])));
    //);
  }
}

最佳答案

尝试在 DropdownButton 周围用固定宽度包裹 Container。

@override
Widget build(BuildContext context) {
  titleController.text = todo.title;
  descriptionController.text = todo.description;
  TextStyle textStyle = Theme.of(context).textTheme.title;

  return Padding(
    padding: EdgeInsets.only(top: 35, right: 10, left: 10),
    child: Scaffold(
      appBar: AppBar(
        automaticallyImplyLeading: false,
        title: Text('Add New'), //todo.title
      ),
      body: Container(
        height: 200,
        child: Column(
          children: <Widget>[
            Container(
              // don't forget about height
              height: 200,
              child: DropdownButton<String>(
                isExpanded: true,
                items: _priorites.map((String value) {
                  return DropdownMenuItem<String>(
                      value: value, child: Text(value));
                }).toList(),
                style: textStyle,
                value: "Low",
                onChanged: null,
              ),
            )
          ],
        ),
      ),
    ),
  );
}

关于dart - 底部被 Infinity 像素溢出的 RenderFlex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54621388/

有关dart - 底部被 Infinity 像素溢出的 RenderFlex的更多相关文章

  1. ruby - Infinity 和 NaN 的类型是什么? - 2

    我可以得到Infinity和NaNn=9.0/0#=>Infinityn.class#=>Floatm=0/0.0#=>NaNm.class#=>Float但是当我想直接访问Infinity或NaN时:Infinity#=>uninitializedconstantInfinity(NameError)NaN#=>uninitializedconstantNaN(NameError)什么是Infinity和NaN?它们是对象、关键字还是其他东西? 最佳答案 您看到打印为Infinity和NaN的只是Float类的两个特殊实例的字符串

  2. ruby-on-rails - 如何在 Rails Controller Action 上触发 Facebook 像素 - 2

    我有一个ruby​​onrails应用程序。我按照facebook的说明添加了一个像素。但是,要跟踪转化,Facebook要求您将页面置于达到预期结果时出现的转化中。即,如果我想显示客户已注册,我会将您注册后转到的页面作为成功对象进行跟踪。我的问题是,当客户注册时,在我的应用程序中没有登陆页面。该应用程序将用户带回主页。它在主页上显示了一条消息,所以我想看看是否有一种方法可以跟踪来自Controller操作而不是实际页面的转化。我需要计数的Action没有页面,它们是ControllerAction。是否有任何人都知道的关于如何执行此操作的gem、文档或最佳实践?这是进入布局文件的像素

  3. ruby - 为什么在 Ruby 中是 Float::INFINITY == Float::INFINITY? - 2

    在数学中,2个无穷大既不等于,也不大于或小于then。那么是什么给了?在irb中,Float::INFINITY==Float::INFINITY(在ruby​​1.9.3中测试) 最佳答案 用更专业的术语来说,这一切都归结为浮点运算的IEEE754标准。TheIEEE754standarddoesimplicitlydefineInfinity==Infinitytobetrue.Therelevantpartofthestandardissection5.7:"Fourmutuallyexclusiverelationsarep

  4. ruby - 如何模拟 Fixnum 变量的整数溢出? - 2

    我目前正在将一种算法从Java转换为Ruby,但由于Ruby中缺少整数溢出,我遇到了一些障碍。假设我的值为2663860877,它大于最大整数2147483648。在Java中,它环绕,我应该得到-1631106419。我找到了这段代码,但它似乎不起作用:defforce_overflow(i)ifi2147483647i&0xffffffffelseiendend并且'ing变量不会像您期望的那样强制它为负。 最佳答案 假设32位整数具有二进制补码负数,这应该可行:defforce_overflow_signed(i)force_

  5. ruby-on-rails - 在页面的最底部包含 javascript 文件 - 2

    我有一个Rails应用程序。还有一个javascript(javascript1.js)文件必须包含在每个View的最底部。我把它放在/assets/javascripts文件夹中。Application.js包含以下代码//=requirejquery//=requirejquery_ujs//=someotherfiles//=require_directory.即使Application.js中不包含javascript1.js,它也会自动包含,不是吗?那么我怎样才能做我想做的事呢? 最佳答案 单独定义、包含和执行您的java

  6. ruby-on-rails - 在服务器端检测屏幕尺寸和像素密度? - 2

    我一直在做一些研究,我想我已经知道答案了,但我想知道是否有任何方法可以在不使用javascript或依赖CSS3媒体的情况下获得设备的屏幕尺寸和像素密度查询。本质上,我正在研究如何获取屏幕分辨率和像素密度,以便服务器可以决定在URI请求中为服务器提供哪个图像。到目前为止,我还没有发现任何证据表明这是可能的,但我想嘿,为什么不问问呢? 最佳答案 我不完全同意上面的正确答案。实际上,这个答案在很多情况下都是正确的……但理论上并非如此。通常向Web服务器发出的请求包含一个User-Agent字段,从理论上讲,该字段可用于识别有关设备屏幕分

  7. 脚本底部的 Ruby 方法? - 2

    我使用的是ruby​​1.8.7。我可以发誓我之前已经在脚本底部编写了我的函数并且运行良好。我必须将它们放在顶部吗?这似乎是他们现在唯一的工作方式。没什么大不了的。我只是更喜欢将它们放在底部,所以我想我会问。 最佳答案 您可以在一个或多个BEGINblock中执行初始化代码(继承自Perl,后者继承自awk)。can_i_do_this?#=>yesBEGIN{defcan_i_do_this?puts"yes"end}为了完整起见,还有ENDblock:END{can_i_do_this?#=>yes}defcan_i_do_th

  8. ruby - 为什么 10^9942066 是我可以计算而不会溢出的最大功率? - 2

    在ruby​​中,一些大数大于无穷大。通过二分查找,我发现:(1.0/0)>10**9942066.000000001#=>false(1.0/0)>10**9942066#=>trueRUBY_VERSION#=>"2.3.0"为什么是这样?109942066有什么特别之处?它似乎不是像9999999这样的任意数字,它不接近任何2的幂(它大约等于233026828.36662442)。为什么ruby的无穷大不是无穷大?109942066是怎么参与的?我现在意识到,任何大于109942066的数字都会溢出到无穷大:10**9942066.000000001#=>Infinity10**

  9. ruby - 在 Ruby 中逐像素读取图像 - 2

    我正在尝试打开一个图像文件并按颜色将像素列表存储在变量/数组中,以便我可以一个一个地输出它们。图像类型:可以是BMP、JPG、GIF或PNG。任何一个都可以,只需要支持一个。颜色输出:RGB或Hex。我查看了几个库(RMagick、Quick_Magick、Mini_Magick等),它们看起来都太过分了。Heroku在使用ImageMagick时也有一些困难,我的测试无法运行。我的应用程序在Sinatra中。有什么建议吗? 最佳答案 您可以使用Rmagick的each_pixel为此的方法。each_pixel接收一个block。

  10. ruby - RMagick - 如何找出图像的像素尺寸 - 2

    如何找到以像素为单位的图像宽度和高度?image.x_resolution和image.y_resolution由于某种原因都返回0。 最佳答案 require'rmagick'img=Magick::Image.ping('demo.png').firstwidth=img.columnsheight=img.rows注意从注释导入的.ping方法。如果你需要读取图像来处理它,然后使用Magick::Image.read('demo.png').first-ping的使用在这个工作独立代码并加快某些图像类型的处理速度,其中IM只能

随机推荐