Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter dropdownbutton raises exception

Tags:

flutter

dart

I'm trying to add a DropdownButton to my application but it is not rendered, the message "Bottom overflowed by infinity pixels" appears, I tried putting it in a SizeBox, Paddign, ConstrainedBox, Row, but nothing works, see the code:

@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,
              )
            ],
          ),
        ),
      ),
    );
  }
}

But when you run the app, the following error message appears:

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.

can anybody help me?

like image 466
Luiz Avatar asked Nov 15 '18 01:11

Luiz


1 Answers

I used a ConstrainedBox to set a maxHeight but then it still overflowed to the right by infinity. I had to set isExpanded: true and then wrap the ConstrainedBox inside of Row -> Expanded.

Column(
  children: <Widget>[
    Row(
      children: <Widget>[
        Expanded(
          child: ConstrainedBox(
            constraints: const BoxConstraints(maxHeight: 48.0),
            child: DropdownButton<String>(
              isExpanded: true, ...
            )
          )
        )
      ]
    )
  ]
)
like image 69
Eric Parshall Avatar answered Nov 03 '22 09:11

Eric Parshall