Flutter Stepper 卧式不工作
Flutter Stepper horizontal type not working
我在将步进器类型从垂直更改为水平时遇到问题。
这是我的代码:
body: new ListView.builder(
itemCount: data == null ? 0 : 5,
itemBuilder: (BuildContext context, int index) {
return new Card(
//child: new Text(data[index]["title"]),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Stepper(
steps: my_steps,
type: StepperType.horizontal,
controlsBuilder: (BuildContext context,
{VoidCallback onStepContinue, VoidCallback onStepCancel}) {
return Row(
children: <Widget>[
Container(
child: null,
),
Container(
child: null,
),
],
);
},
//type: StepperType.horizontal,
),
));
},
),
在取消对类型的注释后,出现此错误:
I/flutter (10148): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY
╞═════════════════════════════════════════════════════════ I/flutter
(10148): The following assertion was thrown during performLayout():
I/flutter (10148): RenderFlex children have non-zero flex but incoming
height constraints are unbounded. I/flutter (10148): When a column is
in a parent that does not provide a finite height constraint, for
example if it is I/flutter (10148): in a vertical scrollable, it will
try to shrink-wrap its children along the vertical axis. Setting a
I/flutter (10148): flex on a child (e.g. using Expanded) indicates
that the child is to expand to fill the remaining I/flutter (10148):
space in the vertical direction.
您可以使用 SizedBox() 或 Container() 小部件并设置它的高度
SizedBox(
height: 200,
child: Card(
//child: new Text(data[index]["title"]),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Stepper(
steps: my_steps(),
type: StepperType.horizontal,
controlsBuilder: (BuildContext context,
{VoidCallback onStepContinue, VoidCallback onStepCancel}) {
return Row(
children: <Widget>[
Container(
child: null,
),
Container(
child: null,
),
],
);
},
//type: StepperType.horizontal,
),
)),
)
您的 ListView
的高度没有限制,因此它不知道每个 child 要使用多少 space,这是一个 Stepper
。
给它一些限制,例如每个限制的最小高度,你应该没问题。
(...)
ConstrainedBox(
constraints: BoxConstraints.tightFor(height: 200.0),
child: Stepper(
steps: my_steps(),
type: StepperType.horizontal,
(...)
我在将步进器类型从垂直更改为水平时遇到问题。
这是我的代码:
body: new ListView.builder(
itemCount: data == null ? 0 : 5,
itemBuilder: (BuildContext context, int index) {
return new Card(
//child: new Text(data[index]["title"]),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Stepper(
steps: my_steps,
type: StepperType.horizontal,
controlsBuilder: (BuildContext context,
{VoidCallback onStepContinue, VoidCallback onStepCancel}) {
return Row(
children: <Widget>[
Container(
child: null,
),
Container(
child: null,
),
],
);
},
//type: StepperType.horizontal,
),
));
},
),
在取消对类型的注释后,出现此错误:
I/flutter (10148): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════ I/flutter (10148): The following assertion was thrown during performLayout(): I/flutter (10148): RenderFlex children have non-zero flex but incoming height constraints are unbounded. I/flutter (10148): When a column is in a parent that does not provide a finite height constraint, for example if it is I/flutter (10148): in a vertical scrollable, it will try to shrink-wrap its children along the vertical axis. Setting a I/flutter (10148): flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining I/flutter (10148): space in the vertical direction.
您可以使用 SizedBox() 或 Container() 小部件并设置它的高度
SizedBox(
height: 200,
child: Card(
//child: new Text(data[index]["title"]),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Stepper(
steps: my_steps(),
type: StepperType.horizontal,
controlsBuilder: (BuildContext context,
{VoidCallback onStepContinue, VoidCallback onStepCancel}) {
return Row(
children: <Widget>[
Container(
child: null,
),
Container(
child: null,
),
],
);
},
//type: StepperType.horizontal,
),
)),
)
您的 ListView
的高度没有限制,因此它不知道每个 child 要使用多少 space,这是一个 Stepper
。
给它一些限制,例如每个限制的最小高度,你应该没问题。
(...)
ConstrainedBox(
constraints: BoxConstraints.tightFor(height: 200.0),
child: Stepper(
steps: my_steps(),
type: StepperType.horizontal,
(...)