【问题标题】:Flutter Stepper horizontal type not workingFlutter Stepper 卧式不工作
【发布时间】:2019-07-18 06:13:41
【问题描述】:

我在将步进器类型从垂直更改为水平时遇到问题。

这是我的代码:

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): ══╡ 渲染库发现异常 ╞═════════════════════════════════════════════════ ════════ I/颤振 (10148):在 performLayout() 期间引发了以下断言: I/flutter (10148):RenderFlex 子节点具有非零弹性但传入 高度限制是无限的。 I/flutter (10148):当一列是 在不提供有限高度约束的父级中,对于 例如,如果它是 I/flutter (10148):在垂直滚动中,它将 尝试沿垂直轴收缩包裹它的孩子。设置一个 I/flutter (10148):在孩子身上弯曲(例如,使用 Expanded)表示 孩子要扩展以填充剩余的 I/flutter (10148): 垂直方向的空间。

【问题讨论】:

    标签: dart flutter stepper


    【解决方案1】:

    您可以使用 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,
                ),
              )),
        )
    

    【讨论】:

      【解决方案2】:

      您的ListView 具有无限高,因此它不知道每个孩子可以使用多少空间,即Stepper。 给它一些限制,例如每个的最小高度尺寸,你应该没问题。

       (...)
       ConstrainedBox(
                    constraints: BoxConstraints.tightFor(height: 200.0),
                    child: Stepper(
                      steps: my_steps(),
                      type: StepperType.horizontal,
       (...)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-09-06
        • 1970-01-01
        • 2021-11-25
        • 1970-01-01
        • 1970-01-01
        • 2023-04-11
        • 2019-07-19
        • 1970-01-01
        相关资源
        最近更新 更多