本文介绍了使用DropdownButton小部件时,RenderFlex在右侧被无穷大像素溢出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我创建一个下拉按钮小部件时,出现此错误,提示RenderFlex被右侧的Infinity像素溢出。
的源代码为:

  import‘package:flutter / material.dart’; 

类测试扩展了StatefulWidget {
@override
_testState createState()=> _testState();
}

class _testState扩展State< test> {

//性别
List< DropdownMenuItem< int>> sexList = [];
void femaleLoad(){
sexList.add(new DropdownMenuItem(child:new Text( Male),value:1,));
femaleList.add(new DropdownMenuItem(child:new Text( Female),value:2,));
}
//性别结束


@override
小部件build(BuildContext context){
sexLoad();
return Scaffold(
body:new Container(
child:new Center(

child:new DropdownButton(items:sexList,onChanged:null),$ b $) b),
),
);
}
}

构建程序后,我没有看到任何应用程序上的DropDownButton而不是控制台上的错误消息。
以下是错误消息:



执行热重启...
正在将文件同步到为x86构建的设备Android SDK ...
在5558毫秒内重新启动应用程序。

  I / flutter(15333):渲染库导致的异常╞═══ ══════════════════════════════════════════════════ ════
I / flutter(15333):在performLayout()期间引发了以下断言:
I / flutter(15333):RenderIndexedStack对象在布局期间被赋予了无限大小。
I / flutter(15333):这可能意味着它是一个试图尽可能大的渲染对象,但是它被放置在
I / flutter(15333):另一个允许渲染的对象内它的孩子可以自己选择大小。
I / flutter(15333):提供无限宽度约束的最接近祖先是:
I / flutter(15333):RenderFlex#9b57d relayoutBoundary = up7 NEEDS-LAYOUT NEEDS-PAINT
I / flutter(15333):创建者:行←填充←容器←DefaultTextStyle←堆栈←侦听器←_GestureSemantics←
I / flutter(15333):RawGestureDetector←GestureDetector←语义←DropdownButton< int> ←中心←⋯
I / flutter(15333):parentData:offset = Offset(0.0,0.0)(可以使用大小)
I / flutter(15333):约束:BoxConstraints(0.0< = w< ; = 411.4,0.0 I /颤振(15333):大小:MISSING
I /颤振(15333):方向:水平
I /颤振(15333) ):mainAxisAlignment:spaceBetween
I / flutter(15333):mainAxisSize:min
I / flutter(15333):crossAxisAlignment:center
I / flutter(15333):textDirection:ltr
I / flutter(15333):verticalDirection:下降
I / flutter(15333):应用于RenderIndexedStack的约束为:
I / flutter(15333):BoxConstraints(0.0< = w< =无穷大,0.0 I /颤振(15333):给出的确切大小为:
I / flutter(15333):大小(Infinity,683.4)
I / flutter(15333):有关更多信息,请参见https://flutter.io/layout/。
I / flutter(15333):
I / flutter(15333):引发异常时,堆栈为:
I / flutter(15333):#0 RenderBox.debugAssertDoesMeetConstraints。 <匿名闭包> (软件包:flutter / src / rendering / box.dart:1749:9)
I / flutter(15333):#1 RenderBox.debugAssertDoesMeetConstraints(软件包:flutter / src / rendering / box.dart:1823:6)
I / flutter(15333):#2 RenderBox.size =。<匿名闭包> (package:flutter / src / rendering / box.dart:1543:17)
I / flutter(15333):#3 RenderBox.size =(package:flutter / src / rendering / box.dart:1543:65 )
I / flutter(15333):#4 RenderStack.performLayout(package:flutter / src / rendering / stack.dart:480:7)
I / flutter(15333):#5 RenderObject.layout (package:flutter / src / rendering / object.dart:1634:7)
I / flutter(15333):#6 RenderFlex.performLayout(package:flutter / src / rendering / flex.dart:738:15)
I / flutter(15333):#7 RenderObject.layout(package:flutter / src / rendering / object.dart:1634:7)
I / flutter(15333):#8 RenderPadding.performLayout(包:flutter / src / rendering / shifted_box.dart:199:11)
I / flutter(15333):#9 RenderObject.layout(包:flutter / src / rendering / object.dart:1634:7)
I / flutter(15333):#10 RenderStack.performLayout(package:flutter / src / rendering / stack.dart:510:15)
I / flutter(15333):#11 RenderObject.layout(package :flutter / src / rendering / object.dart:1634:7)
I / flutter(15333):#12 _RenderProxyBox& RenderBox& RenderObjectWithChildMixin& RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box.dart:104:13)
I / flutter(15333):#13 RenderObject。布局(package:flutter / src / rendering / object.dart:1634:7)
I / flutter(15333):#14 _RenderProxyBox& RenderBox& RenderObjectWithChildMixin& RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box .dart:104:13)
I / flutter(15333):#15 RenderObject.layout(package:flutter / src / rendering / object.dart:1634:7)
I / flutter(15333) :#16 _RenderProxyBox& RenderBox& RenderObjectWithChildMixin& RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box.dart:104:13)
I / flutter(15333):#17 RenderObject.layout(package:flutter / src / rendering / object.dart:1634:7)
I / flutter(15333):#18 RenderPositionedBox.performLayout(package:flutter / src / rendering / shifted_box.dart:385:13)
I /颤振(153 33):#19 RenderObject.layout(package:flutter / src / rendering / object.dart:1634:7)
I / flutter(15333):#20 MultiChildLayoutDelegate.layoutChild(package:flutter / src / rendering / custom_layout.dart:142:11)
I / flutter(15333):#21 _ScaffoldLayout.performLayout(package:flutter / src / material / scaffold.dart:339:7)
I / flutter(15333 ):#22 MultiChildLayoutDelegate._callPerformLayout(package:flutter / src / rendering / custom_layout.dart:212:7)
I / flutter(15333):#23 RenderCustomMultiChildLayoutBox.performLayout(package:flutter / src / rendering / custom_layout .dart:356:14)
I / flutter(15333):#24 RenderObject.layout(package:flutter / src / rendering / object.dart:1634:7)
I / flutter(15333) :#25 _RenderProxyBox& RenderBox& RenderObjectWithChildMixin& RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box.dart:104:13)
I / flutter(15333):#26 RenderObject.layout(package:flutter / src / rendering / object.dart:1634:7)
I / flutter( 15333):#27 _RenderProxyBox& RenderBox& RenderObjectWithChildMixin& RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box.dart:104:13)
I / flutter(15333):#28 _RenderCustomClip.performLayout(package: flutter / src / rendering / proxy_box.dart:1188:11)
I / flutter(15333):#29 RenderObject.layout(包:flutter / src / rendering / object.dart:1634:7)
I / flutter(15333):#30 _RenderProxyBox& RenderBox& RenderObjectWithChildMixin& RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box.dart:104:13)
I / flutter(15333):#31 RenderObject .layout(package:flutter / src / rendering / object.dart:1634:7)
I / flutter(15333):#32 _RenderProxyBox& RenderBox& RenderObjectWithChildMixin& RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box.dart:104:13)
I / flutter(15333):#33 RenderObject.layout(package:flutter / src / rendering / object.dart:1634:7)
I / flutter(15333 ):#34 _ RenderProxyBox& RenderBox& RenderObjectWithChildMixin& RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box.dart:104:13)
I / flutter(15333):#35 RenderObject.layout(package:flutter / src / renderinging /object.dart:1634:7)
I / flutter(15333):#36 _RenderProxyBox& RenderBox& RenderObjectWithChildMixin& RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box.dart:104:13)
I / flutter(15333):#37 RenderObject.layout(package:flutter / src / rendering / object.dart:1634:7)
I / flutter(15333):#38 _RenderProxyBox& RenderBox& RenderObjectWithChildMixin& RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box.dart:104:13)
I / flutter(15333):#39 RenderObject.layout(package:flutter / src / rendering / object.dart:1634) :7)
I / flutter(15333):#40 _RenderProxyBox& RenderBox& RenderObjectWithChildMixin& RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_b ox.dart:104:13)
I / flutter(15333):#41 RenderObject.layout(package:flutter / src / rendering / object.dart:1634:7)
I / flutter(15333 ):#42 _RenderProxyBox& RenderBox& RenderObjectWithChildMixin& RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box.dart:104:13)
I / flutter(15333):#43 RenderObject.layout(package:flutter /src/rendering/object.dart:1634:7)
I / flutter(15333):#44 _RenderProxyBox& RenderBox& RenderObjectWithChildMixin& RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box.dart:104: 13)
I / flutter(15333):#45 RenderOffstage.performLayout(package:flutter / src / rendering / proxy_box.dart:2881:13)
I / flutter(15333):#46 RenderObject。布局(package:flutter / src / rendering / object.dart:1634:7)
I / flutter(15333):#47 RenderStack.performLayout(package:flutter / src / rendering / stack.dart:510:15 )
I / flutter(15333):#48 RenderObject.layout(package:flutter / src / renderin g / object.dart:1634:7)
I / flutter(15333):#49 __RenderTheatre& RenderBox& RenderObjectWithChildMixin& RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box.dart:104:13)
I / flutter(15333):#50 RenderObject.layout(package:flutter / src / rendering / object.dart:1634:7)
I / flutter(15333):#51 _RenderProxyBox& RenderBox& RenderObjectWithChildMixin& ; RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box.dart:104:13)
I / flutter(15333):#52 RenderObject.layout(package:flutter / src / rendering / object.dart: 1634:7)
I / flutter(15333):#53 _RenderProxyBox& RenderBox& RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box.dart:104:13)
I / flutter (15333):#54 RenderObject.layout(package:flutter / src / rendering / object.dart:1634:7)
I / flutter(15333):#55 _RenderProxyBox& RenderBox& RenderObjectWithChildMixin& RenderProxyBoxMix in.performLayout(package:flutter / src / rendering / proxy_box.dart:104:13)
I / flutter(15333):#56 RenderObject.layout(package:flutter / src / rendering / object.dart:1634 :7)
I / flutter(15333):#57 _RenderProxyBox& RenderBox& RenderObjectWithChildMixin& RenderProxyBoxMixin.performLayout(package:flutter / src / rendering / proxy_box.dart:104:13)
I / flutter( 15333):#58 RenderObject.layout(package:flutter / src / rendering / object.dart:1634:7)
I / flutter(15333):#59 _RenderProxyBox& RenderBox& RenderObjectWithChildMixin& RenderProxyBoxMixin.performLayout(package: flutter / src / rendering / proxy_box.dart:104:13)
I / flutter(15333):#60 RenderObject.layout(package:flutter / src / rendering / object.dart:1634:7)
I / flutter(15333):#61 RenderView.performLayout(package:flutter / src / rendering / view.dart:147:13)
I / flutter(15333):#62 RenderObject._layoutWithoutResize(package:flutter /src/rendering/object.dart:1509:7)
I / flutter(15333):#63 PipelineOwner.flushLayout(package:flutter / src / rendering / object.dart:768:18)
I / flutter(15333):#64 _WidgetsFlutterBinding& BindingBase& GestureBinding& ServicesBinding& SchedulerBinding& PaintingBinding& SemanticsBinding& Renderer。 (包:flutter / src / rendering / binding.dart:281:19)
I / flutter(15333):#65 _WidgetsFlutterBinding& BindingBase& GestureBinding& ServicesBinding& SchedulerBinding& PaintingBinding& SemanticsBinding& RendererBinding& WidgetsBinding。包:flutter / src / widgets / binding.dart:677:13)
I / flutter(15333):#66 _WidgetsFlutterBinding& BindingBase& GestureBinding& ServicesBinding& SchedulerBinding& PaintingBinding& SemanticsBinding& RendererBindingFrame._handlePersistent /src/rendering/binding.dart:219:5)
I / flutter(15333):#67 _WidgetsFlutterBinding& BindingBase& GestureBinding& ServicesBinding& Sched ulerBinding._invokeFrameCallback(包:flutter / src / scheduler / binding.dart:990:15)
I / flutter(15333):#68 _WidgetsFlutterBinding& BindingBase& GestureBinding& ServicesBinding& SchedulerBinding.handleDrawFrame(包:flutter / src /scheduler/binding.dart:930:9)
I / flutter(15333):#69 _WidgetsFlutterBinding& BindingBase& GestureBinding& ServicesBinding& SchedulerBinding.scheduleWarmUpFrame。<匿名闭包> (包:flutter / src / scheduler / binding.dart:751:7)
I / flutter(15333):#71 _Timer._runTimers(dart:isolate / runtime / libtimer_impl.dart:382:19)
I / flutter(15333):#72 _Timer._handleMessage(dart:isolate / runtime / libtimer_impl.dart:416:5)
I / flutter(15333):#73 _RawReceivePortImpl._handleMessage(dart:isolate / runtime / libisolate_patch.dart:171:12)
I / flutter(15333):(从dart:async包中删除了一帧)
I / flutter(15333):
I / flutter( 15333):触发异常时正在处理以下RenderObject:
I / flutter(15333):RenderIndexedStack#d77d9 relayoutBoundary = up8 NEEDS-LAYOUT NEEDS-PAINT
I / flutter(15333):创建者:IndexedStack←行←填充←容器←DefaultTextStyle←堆栈←侦听器←
I / flutter(15333):_GestureSemantics←RawGestureDetector←GestureDetector←语义←DropdownButton< int> ←⋯
I / flutter(15333):parentData:offset = Offset(0.0,0.0); flex = null; fit = null(可以使用大小)
I / flutter(15333):约束条件:BoxConstraints(0.0 I / flutter(15333) ):size:Size(Infinity,683.4)
I / flutter(15333):对齐方式:AlignmentDirectional.centerStart
I / flutter(15333):textDirection:ltr
I / flutter(15333) :适合:松散
I / flutter(15333):溢出:剪辑
I / flutter(15333):索引:null
I / flutter(15333):此RenderObject没有子孙。
I / flutter(15333):═══════════════════════════════════════ ══════════════════════════════════════════════════ ═══════════
I / flutter(15333):引发了另一个异常:RenderFlex被右侧的Infinity像素溢出。
解决方案

设置



有一个打开的


When I created a drop-down button widget I got this error saying RenderFlex overflowed by Infinity pixels on the right.The source code is:

    import 'package:flutter/material.dart';

class test extends StatefulWidget {
  @override
  _testState createState() => _testState();
}

class _testState extends State<test> {

//gender
  List<DropdownMenuItem<int>> genderList = [];
  void genderLoad(){
    genderList.add(new DropdownMenuItem(child: new Text("Male"),value: 1,));
    genderList.add(new DropdownMenuItem(child: new Text("Female"),value: 2,));
  }
//end of gender


  @override
  Widget build(BuildContext context) {
    genderLoad();
    return Scaffold(
      body: new Container(
        child: new Center(

          child: new DropdownButton(items: genderList, onChanged: null),
        ),
      ),
    );
  }
}

After I build the program I didn't see any DropDownButton on the app rather I got error message on the console.Below is the Error message:

Performing hot restart...Syncing files to device Android SDK built for x86...Restarted application in 5,558ms.

I/flutter (15333): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (15333): The following assertion was thrown during performLayout():
I/flutter (15333): RenderIndexedStack object was given an infinite size during layout.
I/flutter (15333): This probably means that it is a render object that tries to be as big as possible, but it was put
I/flutter (15333): inside another render object that allows its children to pick their own size.
I/flutter (15333): The nearest ancestor providing an unbounded width constraint is:
I/flutter (15333):   RenderFlex#9b57d relayoutBoundary=up7 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (15333):   creator: Row ← Padding ← Container ← DefaultTextStyle ← Stack ← Listener ← _GestureSemantics ←
I/flutter (15333):   RawGestureDetector ← GestureDetector ← Semantics ← DropdownButton<int> ← Center ← ⋯
I/flutter (15333):   parentData: offset=Offset(0.0, 0.0) (can use size)
I/flutter (15333):   constraints: BoxConstraints(0.0<=w<=411.4, 0.0<=h<=683.4)
I/flutter (15333):   size: MISSING
I/flutter (15333):   direction: horizontal
I/flutter (15333):   mainAxisAlignment: spaceBetween
I/flutter (15333):   mainAxisSize: min
I/flutter (15333):   crossAxisAlignment: center
I/flutter (15333):   textDirection: ltr
I/flutter (15333):   verticalDirection: down
I/flutter (15333): The constraints that applied to the RenderIndexedStack were:
I/flutter (15333):   BoxConstraints(0.0<=w<=Infinity, 0.0<=h<=683.4)
I/flutter (15333): The exact size it was given was:
I/flutter (15333):   Size(Infinity, 683.4)
I/flutter (15333): See https://flutter.io/layout/ for more information.
I/flutter (15333): 
I/flutter (15333): When the exception was thrown, this was the stack:
I/flutter (15333): #0      RenderBox.debugAssertDoesMeetConstraints.<anonymous closure> (package:flutter/src/rendering/box.dart:1749:9)
I/flutter (15333): #1      RenderBox.debugAssertDoesMeetConstraints (package:flutter/src/rendering/box.dart:1823:6)
I/flutter (15333): #2      RenderBox.size=.<anonymous closure> (package:flutter/src/rendering/box.dart:1543:17)
I/flutter (15333): #3      RenderBox.size= (package:flutter/src/rendering/box.dart:1543:65)
I/flutter (15333): #4      RenderStack.performLayout (package:flutter/src/rendering/stack.dart:480:7)
I/flutter (15333): #5      RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #6      RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:738:15)
I/flutter (15333): #7      RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #8      RenderPadding.performLayout (package:flutter/src/rendering/shifted_box.dart:199:11)
I/flutter (15333): #9      RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #10     RenderStack.performLayout (package:flutter/src/rendering/stack.dart:510:15)
I/flutter (15333): #11     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #12     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (15333): #13     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #14     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (15333): #15     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #16     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (15333): #17     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #18     RenderPositionedBox.performLayout (package:flutter/src/rendering/shifted_box.dart:385:13)
I/flutter (15333): #19     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #20     MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:142:11)
I/flutter (15333): #21     _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:339:7)
I/flutter (15333): #22     MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:212:7)
I/flutter (15333): #23     RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:356:14)
I/flutter (15333): #24     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #25     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (15333): #26     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #27     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (15333): #28     _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1188:11)
I/flutter (15333): #29     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #30     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (15333): #31     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #32     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (15333): #33     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #34     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (15333): #35     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #36     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (15333): #37     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #38     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (15333): #39     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #40     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (15333): #41     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #42     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (15333): #43     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #44     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (15333): #45     RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:2881:13)
I/flutter (15333): #46     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #47     RenderStack.performLayout (package:flutter/src/rendering/stack.dart:510:15)
I/flutter (15333): #48     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #49     __RenderTheatre&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (15333): #50     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #51     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (15333): #52     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #53     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (15333): #54     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #55     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (15333): #56     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #57     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (15333): #58     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #59     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter (15333): #60     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter (15333): #61     RenderView.performLayout (package:flutter/src/rendering/view.dart:147:13)
I/flutter (15333): #62     RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1509:7)
I/flutter (15333): #63     PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:768:18)
I/flutter (15333): #64     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:281:19)
I/flutter (15333): #65     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:677:13)
I/flutter (15333): #66     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:219:5)
I/flutter (15333): #67     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
I/flutter (15333): #68     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
I/flutter (15333): #69     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:751:7)
I/flutter (15333): #71     _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:382:19)
I/flutter (15333): #72     _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
I/flutter (15333): #73     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
I/flutter (15333): (elided one frame from package dart:async)
I/flutter (15333): 
I/flutter (15333): The following RenderObject was being processed when the exception was fired:
I/flutter (15333):   RenderIndexedStack#d77d9 relayoutBoundary=up8 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (15333):   creator: IndexedStack ← Row ← Padding ← Container ← DefaultTextStyle ← Stack ← Listener ←
I/flutter (15333):   _GestureSemantics ← RawGestureDetector ← GestureDetector ← Semantics ← DropdownButton<int> ← ⋯
I/flutter (15333):   parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
I/flutter (15333):   constraints: BoxConstraints(0.0<=w<=Infinity, 0.0<=h<=683.4)
I/flutter (15333):   size: Size(Infinity, 683.4)
I/flutter (15333):   alignment: AlignmentDirectional.centerStart
I/flutter (15333):   textDirection: ltr
I/flutter (15333):   fit: loose
I/flutter (15333):   overflow: clip
I/flutter (15333):   index: null
I/flutter (15333): This RenderObject has no descendants.
I/flutter (15333): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (15333): Another exception was thrown: A RenderFlex overflowed by Infinity pixels on the right.
解决方案

set isExpanded: true. And give its Container a proper height (e.g. 48), or set isDense: true or do not pass a null onChanged event or a null list of items, but if you want to disable the widget for any reason (user have not to click on it) I guess that setting the former conditions allow to do all you want.

class _testState extends State<test> {
//gender
  List<DropdownMenuItem<int>> genderList = [];
  void genderLoad() {
    genderList.clear();
    genderList.add(new DropdownMenuItem(
      child: new Text("Male"),
      value: 1,
    ));
    genderList.add(new DropdownMenuItem(
      child: new Text("Female"),
      value: 2,
    ));
  }
//end of gender

  @override
  Widget build(BuildContext context) {
    genderLoad();
    return Scaffold(
        appBar: AppBar(
          // Here we take the value from the MyHomePage object that was created by
          // the App.build method, and use it to set our appbar title.
          title: Text('hello'),
        ),
        body: Container(
          height: 48,
            color: Colors.lightGreenAccent,
            child: DropdownButton(
                isDense: false,
                isExpanded: true,
                items: genderList,
                onChanged: (selected){
                  print(selected);
                })));
  }
}

There is this open issue that makes DropDownButton widget not rendering when you pass empty values on required fields.

So that all these:

  • DropdownButton(items: [], onChanged: (int) {})
  • DropdownButton(items: genderList, onChanged: null)
  • DropdownButton(items: [], onChanged: null)

Have problems. A workaround is the one shown in this post.

return Scaffold(
  body: new Container(
    width: 48,
    child: new Center(
      child: new DropdownButton (
          isExpanded: true,
          items: [],
          onChanged: null
      ),
    ),
  ),
);

这篇关于使用DropdownButton小部件时,RenderFlex在右侧被无穷大像素溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 02:45