簡體   English   中英

如何將顫動文本小部件包裝在步進器中?

[英]How to wrap flutter text widget inside a stepper?

我如何將文本小部件包裝在步進小部件副標題中?,這些是我沒有成功的一些嘗試:

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 小部件,但我必須指定固定寬度,因此它沒有響應。

我發現有像 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"),
                    ),
                  ],
                );
              },
            ));
          }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM