繁体   English   中英

Flutter dropdownbutton引发异常

Flutter dropdownbutton raises exception

提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供   中文繁体   英文版本   中英对照 版本,有任何建议请联系yoyou2525@163.com。

我正在尝试将DropdownButton添加到我的应用程序但它没有呈现,出现消息“底部溢出无限像素”,我尝试将它放在SizeBox,Paddign,ConstrainedBox,Row中,但没有任何效果,请参阅代码:

@override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(
          'Configurações',
          style: TextStyle(color: Colors.white),
        ),
        actions: <Widget>[new IconButton(icon: new Icon(Icons.check), onPressed: _salvar)],
      ),
      body: new Container(
        color: Colors.orange[50],
        padding: EdgeInsets.all(16.0),
        child: new Form(
          child: new Column(
            children: <Widget>[
              new TextFormField(
                decoration: new InputDecoration(labelText: 'Código da empresa'),
                //border: OutlineInputBorder()
                autofocus: true,
                controller: _edCodigoEmpresa,
                keyboardType: TextInputType.numberWithOptions(),
              ),
              new TextFormField(
                decoration: new InputDecoration(labelText: 'Código do funcionário'),
                controller: _edCodigoFuncionario,
                keyboardType: TextInputType.numberWithOptions(),
              ),
              new DropdownButton(
                value: _baseSelecionada,
                items: _basesCliente,
                onChanged: _baseChange,
              )
            ],
          ),
        ),
      ),
    );
  }
}

但是当您运行该应用程序时,会出现以下错误消息:

I/flutter (16684): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (16684): The following assertion was thrown during performLayout():
I/flutter (16684): RenderIndexedStack object was given an infinite size during layout.
I/flutter (16684): This probably means that it is a render object that tries to be as big as possible, but it was put
I/flutter (16684): inside another render object that allows its children to pick their own size.
I/flutter (16684): The nearest ancestor providing an unbounded width constraint is:
I/flutter (16684):   RenderFlex#b60e0 relayoutBoundary=up9 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (16684):   creator: Row ← Padding ← Container ← DefaultTextStyle ← Stack ← Listener ← _GestureSemantics ←
I/flutter (16684):   RawGestureDetector ← GestureDetector ← Semantics ← DropdownButton<String> ← Column ← ⋯
I/flutter (16684):   parentData: offset=Offset(0.0, 0.0) (can use size)
I/flutter (16684):   constraints: BoxConstraints(0.0<=w<=328.0, 0.0<=h<=Infinity)
I/flutter (16684):   size: Size(328.0, Infinity)
I/flutter (16684):   direction: horizontal
I/flutter (16684):   mainAxisAlignment: spaceBetween
I/flutter (16684):   mainAxisSize: min
I/flutter (16684):   crossAxisAlignment: center
I/flutter (16684):   textDirection: ltr
I/flutter (16684):   verticalDirection: down
I/flutter (16684): The nearest ancestor providing an unbounded height constraint is:
I/flutter (16684):   RenderFlex#783bc relayoutBoundary=up3 NEEDS-LAYOUT NEEDS-PAINT OVERFLOWING
I/flutter (16684):   creator: Column ← _FormScope ← WillPopScope ← Form ← Padding ← DecoratedBox ← Container ←
I/flutter (16684):   MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ← CustomMultiChildLayout ← AnimatedBuilder ←
I/flutter (16684):   DefaultTextStyle ← ⋯
I/flutter (16684):   parentData: offset=Offset(16.0, 16.0) (can use size)
I/flutter (16684):   constraints: BoxConstraints(0.0<=w<=328.0, 0.0<=h<=528.0)
I/flutter (16684):   size: Size(328.0, 528.0)
I/flutter (16684):   direction: vertical
I/flutter (16684):   mainAxisAlignment: start
I/flutter (16684):   mainAxisSize: max
I/flutter (16684):   crossAxisAlignment: center
I/flutter (16684):   verticalDirection: down
I/flutter (16684): The constraints that applied to the RenderIndexedStack were:
I/flutter (16684):   BoxConstraints(unconstrained)
I/flutter (16684): The exact size it was given was:
I/flutter (16684):   Size(Infinity, Infinity)
I/flutter (16684): See https://flutter.io/layout/ for more information.
I/flutter (16684): 
I/flutter (16684): When the exception was thrown, this was the stack:
I/flutter (16684): #0      RenderBox.debugAssertDoesMeetConstraints.<anonymous closure> (package:flutter/src/rendering/box.dart:1749:9)
I/flutter (16684): #1      RenderBox.debugAssertDoesMeetConstraints (package:flutter/src/rendering/box.dart:1823:6)
I/flutter (16684): #2      RenderBox.size=.<anonymous closure> (package:flutter/src/rendering/box.dart:1543:17)
I/flutter (16684): #3      RenderBox.size= (package:flutter/src/rendering/box.dart:1543:65)
I/flutter (16684): #4      RenderStack.performLayout (package:flutter/src/rendering/stack.dart:480:7)
I/flutter (16684): #5      RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #6      RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:738:15)
I/flutter (16684): #7      RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #8      RenderPadding.performLayout (package:flutter/src/rendering/shifted_box.dart:199:11)
I/flutter (16684): #9      RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #10     RenderStack.performLayout (package:flutter/src/rendering/stack.dart:510:15)
I/flutter (16684): #11     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #12     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16684): #13     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #14     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16684): #15     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #16     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16684): #17     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #18     RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:738:15)
I/flutter (16684): #19     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #20     RenderPadding.performLayout (package:flutter/src/rendering/shifted_box.dart:199:11)
I/flutter (16684): #21     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #22     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16684): #23     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #24     MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:141:11)
I/flutter (16684): #25     _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:339:7)
I/flutter (16684): #26     MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:211:7)
I/flutter (16684): #27     RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:355:14)
I/flutter (16684): #28     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #29     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16684): #30     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #31     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16684): #32     _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1188:11)
I/flutter (16684): #33     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #34     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16684): #35     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #36     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16684): #37     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #38     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16684): #39     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #40     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16684): #41     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #42     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16684): #43     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #44     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16684): #45     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #46     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16684): #47     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #48     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16684): #49     RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:2880:13)
I/flutter (16684): #50     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #51     RenderStack.performLayout (package:flutter/src/rendering/stack.dart:510:15)
I/flutter (16684): #52     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #53     __RenderTheatre&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16684): #54     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #55     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16684): #56     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #57     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16684): #58     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #59     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16684): #60     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #61     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (16684): #62     RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (16684): #63     RenderView.performLayout (package:flutter/src/rendering/view.dart:147:13)
I/flutter (16684): #64     RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1507:7)
I/flutter (16684): #65     PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:766:18)
I/flutter (16684): #66     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:281:19)
I/flutter (16684): #67     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:674:13)
I/flutter (16684): #68     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:219:5)
I/flutter (16684): #69     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
I/flutter (16684): #70     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
I/flutter (16684): #71     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:751:7)
I/flutter (16684): #73     _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:382:19)
I/flutter (16684): #74     _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
I/flutter (16684): #75     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
I/flutter (16684): (elided one frame from package dart:async)
I/flutter (16684): 
I/flutter (16684): The following RenderObject was being processed when the exception was fired:
I/flutter (16684):   RenderIndexedStack#b8a3e relayoutBoundary=up10 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (16684):   creator: IndexedStack ← Row ← Padding ← Container ← DefaultTextStyle ← Stack ← Listener ←
I/flutter (16684):   _GestureSemantics ← RawGestureDetector ← GestureDetector ← Semantics ← DropdownButton<String> ← ⋯
I/flutter (16684):   parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
I/flutter (16684):   constraints: BoxConstraints(unconstrained)
I/flutter (16684):   size: Size(Infinity, Infinity)
I/flutter (16684):   alignment: AlignmentDirectional.centerStart
I/flutter (16684):   textDirection: ltr
I/flutter (16684):   fit: loose
I/flutter (16684):   overflow: clip
I/flutter (16684):   index: null
I/flutter (16684): This RenderObject has no descendants.
I/flutter (16684): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (16684): Another exception was thrown: RenderFlex object was given an infinite size during layout.
I/flutter (16684): Another exception was thrown: RenderPadding object was given an infinite size during layout.
I/flutter (16684): Another exception was thrown: RenderStack object was given an infinite size during layout.
I/flutter (16684): Another exception was thrown: RenderPointerListener object was given an infinite size during layout.
I/flutter (16684): Another exception was thrown: RenderSemanticsGestureHandler object was given an infinite size during layout.
I/flutter (16684): Another exception was thrown: RenderSemanticsAnnotations object was given an infinite size during layout.
I/flutter (16684): Another exception was thrown: NoSuchMethodError: The method '<=' was called on null.
I/flutter (16684): Another exception was thrown: A RenderFlex overflowed by Infinity pixels on the bottom.

有谁能够帮助我?

2 个回复

我使用ConstrainedBox来设置maxHeight但是它仍然无限地溢出到右边。 我必须设置isExpanded: true然后将ConstrainedBox包装在Row - > Expanded中。

Column(
  children: <Widget>[
    Row(
      children: <Widget>[
        Expanded(
          child: ConstrainedBox(
            constraints: const BoxConstraints(maxHeight: 48.0),
            child: DropdownButton<String>(
              isExpanded: true, ...
            )
          )
        )
      ]
    )
  ]
)

发生这种情况是因为当您切换下拉列表时,视图无法展开以适合其内容。

要么你限制它仅使用所有可用空间(即包装的儿童小工具ColumnFlexible比如部件Expanded ),或者让你的观点被滚动的,例如,包裹你的身体ContainerSingleChildScrollView部件。

Scaffold(
     body: SingleChildScrollView(
           child: Container(
                  ...
1 为什么会引发异常?

任务:从Android设备将“ Hello world”发送到MQTT服务器。 库:PahoMqtt 3.1.1 IDE:Android Studio 3.5 清单权限: Android的代码: 问题:引起MqttException。 我的观察:如果我使用 ...

2 没有引发异常

我有一个包含以下代码的存储过程: 我想在C#代码中捕获SqlException。 但是没有提出该例外。 我究竟做错了什么? 谢谢。 ...

4 引发异常而没有“线程异常…”

我想知道是否有一种简单的引发异常的方法,但是只能使用我选择的确切字符串。 我找到了摆脱堆栈跟踪的方法,但是现在我想删除每个异常的开头: “线程“主”中的异常RuntimeException ...” 我正在寻找一种简单,优雅的方法来做到这一点(不是超级简单,但也不会太复杂)。 ...

6 垂直执行Flutter Dropdownbutton

我需要Flutter上的DropDownMenu按钮的垂直版本。 与其下拉,我不希望它用垂直轴列表而不是水平轴列表“横向”“放下”。 有没有办法用DropDownMenu按钮来做到这一点,或者有替代的工具吗? 我使用了RotatedBox,但无法旋转列表。 我只能设法旋转选定的文本。 ...

7 带有 FirebaseFirestore 的 Flutter DropdownButton

有人可以帮我将“食物”集合中的“名称”字段值列表添加到 DropdownButton。 我想从我的 Firestore 后端获取 Collection 'Foods' 中的所有文档,并希望在 Flutter DropDownButton 中显示。 所以我可以从下拉按钮中选择名称。 例如,请参见下 ...

8 引发异常与自动引发异常之间的区别

当前使用wxPython框架,我的代码如下所示: 事件绑定: 处理更改的单元格的功能: 函数get_cell_value()从当前单元格中读取值,然后只需使用int()即可将其转换为整数。 如果用户在单元格中输入“ a”之类的字符,显然此功能将失败并引发异常。 在这种情 ...

9 Groovy结束异常与引发的异常不同

在Groovy中,我遇到了一种极其奇怪的行为。 当我从脚本中的闭包引发异常时,所引发的最终异常有所不同。 以下是代码和详细信息: Script.dsl: 因此计划是,当我在TestDelegate运行main()方法时,它将运行DSL脚本,该脚本需要方法method() ...

暂无
暂无

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

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