如何在步进器中包装颤动文本小部件?

时间:2018-12-05 14:25:52

标签: flutter flutter-layout

我如何将文本窗口小部件包装在步进窗口小部件字幕中?,这些是我尝试不成功的尝试:

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")),
  ],
));

我实现的唯一方法是使用“容器”小部件,但是我必须指定一个固定宽度,因此它没有响应。

1 个答案:

答案 0 :(得分:0)

我发现存在像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"),
                    ),
                  ],
                );
              },
            ));
          }