【问题标题】:Create a widget that will display a very long paragraph创建一个显示很长段落的小部件
【发布时间】:2021-01-11 03:43:10
【问题描述】:

我想在屏幕上创建一个很长的段落。 小部件必须是可滚动的,因为它的末尾会有一个按钮。

class CloseForm extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      extendBody: true,
      backgroundColor: Colors.black,
      body: SingleChildScrollView(
        child: SafeArea(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              SizedBox(height: 20.0),
              Text("TEXT 1"),
              Text("TEXT 2"),
              Text("TEXT 3"),
              Text("TEXT 4"),
              SizedBox(height: 250.0),
              Center(
                child: ButtonTheme(
                  child: RaisedButton(
                    onPressed: () => print("Connect"),
                    elevation: 2.0,
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(10.0),
                    ),
                    child: Text(
                      "Accepter",
                      style: TextStyle(
                          color: Colors.white,
                          fontSize: 20.0,
                          fontWeight: FontWeight.w600),
                    ),
                    color: Color(0xFF5ABA9F),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

}

如果继续使用 TEXT 小部件插入每一行,这将非常累我只想知道是否有可能一步插入整个段落,谢谢

【问题讨论】:

    标签: flutter mobile widget


    【解决方案1】:

    对于 Text 小部件,您可以指定 maxLines 属性。

    像这样:

                Text(longParagraphTextContent,
                    maxLines: 10,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                        fontSize: 12,
                        color: Color(0xdddddd),
                        fontWeight: FontWeight.bold)),
              ],
    

    【讨论】:

      【解决方案2】:

      您可以只使用一个文本小部件并使用“\n”换行,而不是使用太多文本小部件。

      最好的方法是像 Didier 所说的那样使用 maxlines 属性

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-13
        • 1970-01-01
        • 2021-03-11
        • 2016-12-17
        • 2012-03-04
        • 2012-10-09
        相关资源
        最近更新 更多