在抖动中水平对齐文本字段旁边的下拉按钮

时间:2019-08-31 06:37:54

标签: layout flutter textfield dropdownbutton

我一直在尝试解决此问题,但是经过我的所有努力,我只得到了错误。经历了Align TextField with Dropdownbutton

的问题

我曾尝试为TextFieldDropDownButton制作不同的卡片,但同样遇到了同样的问题。

代码:

Column(
 crossAxisAlignment: CrossAxisAlignment.stretch,
 children: <Widget>[
   Container(
     margin: EdgeInsets.only(top: 40.0, left: 16.0, right: 16.0),
     child: Card(
        color: Colors.white,
        child: Row(
           crossAxisAlignment: CrossAxisAlignment.center,
           children: <Widget>[
             DropdownButtonHideUnderline(
                child: DropdownButton(
                  value: _dropDownValue,
                  onChanged: (newValue){setState(() => _dropDownValue = newValue);},
                  items: _countryCode.map((value){
                     return DropdownMenuItem(
                         value: value,
                         child: Text(value)
                     );
                  }).toList()
                )
             ),
             Flexible(
               child: TextEditorForPhoneNumber(this.phoneNum),
             )
          ]
        )
     ),
  decoration: BoxDecoration(boxShadow: [
    new BoxShadow(color: Color.fromRGBO(173, 179, 191, 0.3), blurRadius: 20.0, offset: new Offset(0, 12))
  ])
 )
 ]
)

TextEditorForPhoneNumber

class TextEditorForPhoneNumber extends StatelessWidget {
  final TextEditingController phoneNum;

  TextEditorForPhoneNumber(this.phoneNum);

  @override
  Widget build(BuildContext context) {
    return TextField(
      autofocus: true,
      cursorColor: Theme.of(context).primaryColor,
      keyboardType: TextInputType.number,
      controller: this.phoneNum,
      decoration: InputDecoration(
        hintText: 'Your Phone number'
      )
    );
  }
}

错误:

flutter: ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
flutter: The following assertion was thrown during performLayout():
flutter: RenderIndexedStack object was given an infinite size during layout.
flutter: This probably means that it is a render object that tries to be as big as possible, but it was put
flutter: inside another render object that allows its children to pick their own size.
flutter: The nearest ancestor providing an unbounded width constraint is:
flutter:   RenderFlex#c6ec2 relayoutBoundary=up9 NEEDS-LAYOUT NEEDS-PAINT
flutter:   creator: Row ← DefaultTextStyle ← AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#ed2b5 ink
flutter:   renderer] ← NotificationListener<LayoutChangedNotification> ← CustomPaint ← _ShapeBorderPaint ←
flutter:   PhysicalShape ← _MaterialInterior ← Material ← Padding ← Container ← ⋯
flutter:   parentData: <none> (can use size)
flutter:   constraints: BoxConstraints(w=335.0, 0.0<=h<=Infinity)
flutter:   size: MISSING
flutter:   direction: horizontal
flutter:   mainAxisAlignment: start
flutter:   mainAxisSize: max
flutter:   crossAxisAlignment: center
flutter:   textDirection: ltr
flutter:   verticalDirection: down
flutter: The nearest ancestor providing an unbounded height constraint is:
flutter:   RenderFlex#6f9ef relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-PAINT
flutter:   creator: Column ← Builder ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ← CustomMultiChildLayout
flutter:   ← AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#29d80
flutter:   ink renderer] ← NotificationListener<LayoutChangedNotification> ← PhysicalModel ←
flutter:   AnimatedPhysicalModel ← ⋯
flutter:   parentData: offset=Offset(0.0, 0.0); id=_ScaffoldSlot.body (can use size)
flutter:   constraints: BoxConstraints(0.0<=w<=375.0, 0.0<=h<=591.0)
flutter:   size: MISSING
flutter:   direction: vertical
flutter:   mainAxisAlignment: start
flutter:   mainAxisSize: max
flutter:   crossAxisAlignment: stretch
flutter:   verticalDirection: down
flutter: The constraints that applied to the RenderIndexedStack were:
flutter:   BoxConstraints(unconstrained)
flutter: The exact size it was given was:
flutter:   Size(Infinity, Infinity)
flutter: See https://flutter.io/layout/ for more information.
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0      RenderBox.debugAssertDoesMeetConstraints.<anonymous closure> (package:flutter/src/rendering/box.dart:1749:9)
flutter: #1      RenderBox.debugAssertDoesMeetConstraints (package:flutter/src/rendering/box.dart:1823:6)
flutter: #2      RenderBox.size=.<anonymous closure> (package:flutter/src/rendering/box.dart:1543:17)
flutter: #3      RenderBox.size= (package:flutter/src/rendering/box.dart:1543:65)
flutter: #4      RenderStack.performLayout (package:flutter/src/rendering/stack.dart:480:7)
flutter: #5      RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #6      RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:738:15)
flutter: #7      RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #8      RenderPadding.performLayout (package:flutter/src/rendering/shifted_box.dart:199:11)
flutter: #9      RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #10     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #11     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #12     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #13     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #14     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #15     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #16     RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:738:15)
flutter: #17     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #18     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #19     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #20     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #21     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #22     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #23     _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1188:11)
flutter: #24     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #25     RenderPadding.performLayout (package:flutter/src/rendering/shifted_box.dart:199:11)
flutter: #26     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #27     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #28     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #29     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #30     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #31     RenderPadding.performLayout (package:flutter/src/rendering/shifted_box.dart:199:11)
flutter: #32     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #33     RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:738:15)
flutter: #34     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #35     MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:142:11)
flutter: #36     _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:339:7)
flutter: #37     MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:212:7)
flutter: #38     RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:356:14)
flutter: #39     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #40     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #41     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #42     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #43     _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1188:11)
flutter: #44     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #45     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #46     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #47     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #48     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #49     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #50     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #51     RenderStack.performLayout (package:flutter/src/rendering/stack.dart:510:15)
flutter: #52     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #53     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #54     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #55     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #56     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #57     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #58     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #59     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #60     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #61     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #62     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #63     RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:2879:14)
flutter: #64     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #65     RenderStack.performLayout (package:flutter/src/rendering/stack.dart:510:15)
flutter: #66     RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1509:7)
flutter: #67     PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:768:18)
flutter: #68     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:281:19)
flutter: #69     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:677:13)
flutter: #70     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:219:5)
flutter: #71     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
flutter: #72     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
flutter: #73     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
flutter: #74     _invoke (dart:ui/hooks.dart:154:13)
flutter: #75     _drawFrame (dart:ui/hooks.dart:143:3)
flutter:
flutter: The following RenderObject was being processed when the exception was fired:
flutter:   RenderIndexedStack#29331 relayoutBoundary=up15 NEEDS-LAYOUT NEEDS-PAINT
flutter:   creator: IndexedStack ← Row ← Padding ← Container ← DefaultTextStyle ← Listener ←
flutter:   _GestureSemantics ← RawGestureDetector ← GestureDetector ← Semantics ← DropdownButton<String> ←
flutter:   DropdownButtonHideUnderline ← ⋯
flutter:   parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
flutter:   constraints: BoxConstraints(unconstrained)
flutter:   size: Size(Infinity, Infinity)
flutter:   alignment: AlignmentDirectional.centerStart
flutter:   textDirection: ltr
flutter:   fit: loose
flutter:   overflow: clip
flutter:   index: null
flutter: This RenderObject has no descendants.
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
flutter: Another exception was thrown: RenderFlex object was given an infinite size during layout.
flutter: Another exception was thrown: RenderPadding object was given an infinite size during layout.
flutter: Another exception was thrown: RenderPointerListener object was given an infinite size during layout.
flutter: Another exception was thrown: RenderSemanticsGestureHandler object was given an infinite size during layout.
flutter: Another exception was thrown: RenderSemanticsAnnotations object was given an infinite size during layout.
flutter: Another exception was thrown: RenderFlex object was given an infinite size during layout.
flutter: Another exception was thrown: _RenderInkFeatures object was given an infinite size during layout.
flutter: Another exception was thrown: RenderCustomPaint object was given an infinite size during layout.
flutter: Another exception was thrown: RenderPhysicalShape object was given an infinite size during layout.
flutter: Another exception was thrown: RenderPadding object was given an infinite size during layout.
flutter: Another exception was thrown: RenderSemanticsAnnotations object was given an infinite size during layout.
flutter: Another exception was thrown: RenderDecoratedBox object was given an infinite size during layout.
flutter: Another exception was thrown: RenderPadding object was given an infinite size during layout.
flutter: Another exception was thrown: RenderSemanticsAnnotations object was given an infinite size during layout.
flutter: Another exception was thrown: _RenderInkFeatures object was given an infinite size during layout.
flutter: Another exception was thrown: RenderCustomPaint object was given an infinite size during layout.
flutter: Another exception was thrown: RenderPhysicalShape object was given an infinite size during layout.
flutter: Another exception was thrown: RenderPadding object was given an infinite size during layout.
flutter: Another exception was thrown: RenderSemanticsAnnotations object was given an infinite size during layout.
flutter: Another exception was thrown: RenderDecoratedBox object was given an infinite size during layout.
flutter: Another exception was thrown: RenderPadding object was given an infinite size during layout.
flutter: Another exception was thrown: NoSuchMethodError: The method '<=' was called on null.
flutter: Another exception was thrown: A RenderFlex overflowed by Infinity pixels on the bottom.
flutter: Another exception was thrown: Unsupported operation: Infinity or NaN toInt
flutter: Another exception was thrown: 'package:flutter/src/rendering/object.dart': Failed assertion: line 1411 pos 14: '_debugSubtreeRelayoutRootAlreadyMarkedNeedsLayout()': is not true.
flutter: Another exception was thrown: 'package:flutter/src/rendering/object.dart': Failed assertion: line 1411 pos 14: '_debugSubtreeRelayoutRootAlreadyMarkedNeedsLayout()': is not true.

扑扑医生

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel unknown, v1.0.0, on Mac OS X 10.14.5 18F132, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.3)
[✓] Android Studio (version 3.4)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] Connected device (1 available)

• No issues found!

尝试过:将globalKey赋予Container(),但没有成功。

请帮助。谢谢

解决方案:

找到了解决方案,因此上面的代码就UI而言是正确的,不幸的是,当API数据时,Flutter没有给我选项来将数据集从null更改为DropDownButton()项中的数据进来。我的_countryCode正在从API中获取价值,并在几秒钟内保持为空,由于这个原因,它没有得到更新并给了我空值。 因此请注意项目数据,它不能为空

有关此问题的更多信息,请访问以下答案:A RenderFlex overflowed by Infinity pixels on the right when using DropdownButton widget

0 个答案:

没有答案