运行此页面时出现渲染问题。当我启动页面时,在我添加更多小部件之前,它工作正常,问题似乎出在页面中的小部件太多时。我试图将电子邮件文本字段和flatbutton放在一行中,所以我用Row()覆盖了两个小部件。但是随后我收到了有关文本字段宽度的错误,因此我在行内创建了一个列,但仍然收到错误。我将所有东西都包裹在一个容器中。我是个新手,这是我的代码和错误日志。
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Profile Page'),
),
body: Container(
child: Center(
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
TextFormField(
// initialValue: widget.customerInfo.firstName,
readOnly: _editText,
decoration: const InputDecoration(
labelText: 'First Name *',
),
validator: (value) {
if (value.isEmpty) {
return 'Please enter your first name';
}
return null;
},
controller: _firstnameController,
),
TextFormField(
// initialValue: widget.customerInfo.lastName,
readOnly: _editText,
decoration: const InputDecoration(
labelText: 'Last Name *',
),
validator: (value) {
if (value.isEmpty) {
return 'Please enter your last name';
}
return null;
},
controller: _lastnameController,
),
Row(children: <Widget>[
Column(children: [
new FlatButton(
onPressed: _toggleEditName,
child: new Text(_editText ? "Edit Name" : "Done")),
new FlatButton(
onPressed: (!_editText ? initState : null),
child: new Text('Cancel')),
])
]),
Row(children: <Widget>[
Column(children: [
TextFormField(
// initialValue: widget.customerInfo.email,
readOnly: _editText,
decoration: const InputDecoration(
labelText: 'Email *',
),
validator: (value) {
if (value.isEmpty) {
return 'Please enter your email';
}
return null;
},
controller: _emailController,
),
new FlatButton(onPressed: (null), child: new Text('>')),
])
]),
Row(children: <Widget>[
Column(children: [
TextFormField(
// initialValue: widget.customerInfo.phoneNum,
readOnly: _editText,
decoration: const InputDecoration(
labelText: 'Phone Number *',
),
validator: (value) {
if (value.isEmpty) {
return 'Please enter your phone number';
}
return null;
},
controller: _phoneNumController,
keyboardType: TextInputType.number,
),
new FlatButton(onPressed: (null), child: new Text('>')),
])
])
],
),
),
),
));
}
I/flutter (18667): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (18667): The following assertion was thrown during performLayout():
I/flutter (18667): An InputDecorator, which is typically created by a TextField, cannot have an unbounded width.
I/flutter (18667): This happens when the parent widget does not provide a finite width constraint. For example, if the
I/flutter (18667): InputDecorator is contained by a Row, then its width must be constrained. An Expanded widget or a
I/flutter (18667): SizedBox can be used to constrain the width of the InputDecorator or the TextField that contains it.
I/flutter (18667): 'package:flutter/src/material/input_decorator.dart':
I/flutter (18667): Failed assertion: line 910 pos 7: 'layoutConstraints.maxWidth < double.infinity'
I/flutter (18667):
I/flutter (18667): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (18667): more information in this error message to help you determine and fix the underlying cause.
I/flutter (18667): In either case, please report this assertion by filing a bug on GitHub:
I/flutter (18667): https://github.com/flutter/flutter/issues/new?template=BUG.md
I/flutter (18667):
I/flutter (18667): Widget creation tracking is currently disabled. Enabling it enables improved error messages. It can
I/flutter (18667): be enabled by passing `--track-widget-creation` to `flutter run` or `flutter test`.
I/flutter (18667):
I/flutter (18667): When the exception was thrown, this was the stack:
I/flutter (18667): #2 _RenderDecoration._layout (package:flutter/src/material/input_decorator.dart:910:7)
I/flutter (18667): #3 _RenderDecoration.performLayout (package:flutter/src/material/input_decorator.dart:1214:44)
I/flutter (18667): #4 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #5 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (18667): #6 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #7 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (18667): #8 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #9 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (18667): #10 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #11 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (18667): #12 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #13 RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:744:15)
I/flutter (18667): #14 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #15 RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:744:15)
I/flutter (18667): #16 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #17 RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:744:15)
I/flutter (18667): #18 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #19 RenderPositionedBox.performLayout (package:flutter/src/rendering/shifted_box.dart:392:13)
I/flutter (18667): #20 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #21 MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:142:11)
I/flutter (18667): #22 _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:444:7)
I/flutter (18667): #23 MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:212:7)
I/flutter (18667): #24 RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:356:14)
I/flutter (18667): #25 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #26 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (18667): #27 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #28 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (18667): #29 _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1232:11)
I/flutter (18667): #30 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #31 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (18667): #32 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #33 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (18667): #34 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #35 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (18667): #36 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #37 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (18667): #38 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #39 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (18667): #40 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #41 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (18667): #42 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #43 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (18667): #44 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #45 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (18667): #46 RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:3140:13)
I/flutter (18667): #47 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #48 RenderStack.performLayout (package:flutter/src/rendering/stack.dart:510:15)
I/flutter (18667): #49 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #50 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (18667): #51 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #52 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (18667): #53 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #54 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (18667): #55 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #56 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (18667): #57 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #58 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (18667): #59 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #60 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (18667): #61 RenderObject.layout (package:flutter/src/rendering/object.dart:1701:7)
I/flutter (18667): #62 RenderView.performLayout (package:flutter/src/rendering/view.dart:152:13)
I/flutter (18667): #63 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1578:7)
I/flutter (18667): #64 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:844:18)
I/flutter (18667): #65 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:341:19)
I/flutter (18667): #66 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:761:13)
I/flutter (18667): #67 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:280:5)
I/flutter (18667): #68 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1033:15)
I/flutter (18667): #69 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:975:9)
I/flutter (18667): #70 SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:784:7)
I/flutter (18667): #72 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:382:19)
I/flutter (18667): #73 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:416:5)
I/flutter (18667): #74 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
I/flutter (18667): (elided 3 frames from class _AssertionError and package dart:async-patch)
I/flutter (18667):
I/flutter (18667): The following RenderObject was being processed when the exception was fired: _RenderDecoration#ca773 relayoutBoundary=up9 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE:
I/flutter (18667): needs compositing
I/flutter (18667): creator: _Decorator ← InputDecorator ← AnimatedBuilder ← _PointerListener ← Listener ←
I/flutter (18667): RawGestureDetector ← TextSelectionGestureDetector ← IgnorePointer ← MouseRegion ← Semantics ←
I/flutter (18667): TextField ← TextFormField ← ⋯
I/flutter (18667): parentData: <none> (can use size)
I/flutter (18667): constraints: BoxConstraints(unconstrained)
I/flutter (18667): size: MISSING
I/flutter (18667): This RenderObject had the following descendants (showing up to depth 5):
I/flutter (18667): input: RenderRepaintBoundary#b5169 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter (18667): child: RenderRepaintBoundary#9b420 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter (18667): child: RenderCustomPaint#5923d NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter (18667): child: RenderRepaintBoundary#18532 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter (18667): child: RenderPointerListener#1ff64 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter (18667): label: RenderTransform#b9bc3 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter (18667): child: RenderAnimatedOpacity#67b74 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter (18667): child: RenderParagraph#2d556 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter (18667): text: TextSpan
I/flutter (18667): helperError: RenderConstrainedBox#e5505 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter (18667): container: RenderCustomPaint#333c9 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter (18667): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (18667): Another exception was thrown: RenderBox was not laid out: _RenderDecoration#ca773 relayoutBoundary=up9 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter (18667): Another exception was thrown: RenderBox was not laid out: RenderPointerListener#87013 relayoutBoundary=up8 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter (18667): Another exception was thrown: RenderBox was not laid out: RenderIgnorePointer#25faf relayoutBoundary=up7 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter (18667): Another exception was thrown: RenderBox was not laid out: RenderMouseRegion#de7bf relayoutBoundary=up6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter (18667): Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#7d5d1 relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter (18667): Another exception was thrown: RenderBox was not laid out: RenderFlex#9ae89 relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter (18667): Another exception was thrown: RenderBox was not laid out: RenderFlex#13e43 relayoutBoundary=up3 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter (18667): Another exception was thrown: 'package:flutter/src/rendering/shifted_box.dart': Failed assertion: line 321 pos 12: 'child.hasSize': is not true.
I/flutter (18667): Another exception was thrown: NoSuchMethodError: The method '>' was called on null.
Reloaded 0 of 582 libraries in 330ms.
答案 0 :(得分:1)
位于column
内的row
必须具有宽度,将其包裹在container
内
Row(
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width,
child: Column(
children: [
TextFormField(
// initialValue: widget.customerInfo.email,
readOnly: _editText,
decoration: const InputDecoration(
labelText: 'Email *',
),
validator: (value) {
if (value.isEmpty) {
return 'Please enter your email';
}
return null;
},
controller: _emailController,
),
new FlatButton(
onPressed: (null), child: new Text('>')),
],
),
),
],
),