【问题标题】:How to wrap flutter text widget inside a stepper?如何将颤动文本小部件包装在步进器中?
【发布时间】:2019-05-07 03:38:01
【问题描述】:

如何将文本小部件包装在步进小部件字幕中?,这些是我所做的一些尝试,但没有成功:

return Scaffold(
    body: Stepper(
    steps: [
      Step(
          title: Text("fake title"),
          subtitle: Text(
            "This text should be only one line, if flutter is showing an error and you are tired of trying to find a solution, start praying.",
            overflow: TextOverflow.ellipsis,
            maxLines: 1,
            softWrap: true,
          ),
          content: Text("fake content")),
    ],
));

并带有可扩展或灵活的小部件:

return Scaffold(
    body: Stepper(
  steps: [
    Step(
        title: Text("fake title"),
        subtitle: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Expanded(
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: <Widget>[
                  Text(
                    "This text should be only one line, if flutter is showing an error and you are tired of trying to find a solution, start praying.",
                    overflow: TextOverflow.ellipsis,
                    maxLines: 1,
                    softWrap: true,
                  ),
                ],
              ),
            )
          ],
        ),
        content: Text("fake content")),
  ],
));

我实现的唯一方法是使用 Container 小部件,但我必须指定固定宽度,所以它没有响应。

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    我发现有 84.0 之类的边距/填充(不完全是),您可以使用该代码设置宽度:

            @override
              Widget build(BuildContext context) {
                return Scaffold(body: LayoutBuilder(
                  builder: (context, constraints) {
                    return Stepper(
                      steps: [
                        Step(
                          title: Text("fake title"),
                          subtitle: SizedBox(
                            width: constraints.maxWidth - 84,
                            child: Text(
                              "This text should be only one line, if flutter is showing an error and you are tired of trying to find a solution, start praying.",
                              overflow: TextOverflow.ellipsis,
                              maxLines: 2,
                            ),
                          ),
                          content: Text("fake content"),
                        ),
                      ],
                    );
                  },
                ));
              }
    

    【讨论】:

      猜你喜欢
      • 2018-12-31
      • 2019-03-10
      • 2020-08-24
      • 2018-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      相关资源
      最近更新 更多