【问题标题】:Adding two column of text on Flutter在 Flutter 上添加两列文本
【发布时间】:2020-11-01 06:41:02
【问题描述】:

我想在我的主页中添加两行不同类型的文本。但是当我添加另一个文本小部件时,什么也没有发生。这是我的代码;

class Body extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Center(
          child: Text(
            "Hello",
            style: TextStyle(fontSize: 28, color: Colors.white),
          ),
        ),
      ],
    );
  }
}

我想准确地得到这个输出。 非常感谢!

see input

【问题讨论】:

    标签: flutter text widget


    【解决方案1】:

    您需要使用容器提供蓝色背景,然后使用 Column 和 Text 小部件。您正在使用文本颜色为白色,背景颜色也为白色,这将如何显示...

    class Body extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Container(
          color: Colors.blue,
          child: Column(
          children: <Widget>[
            Center(
              child: Text(
                "Hello",
                style: TextStyle(fontSize: 28, color: Colors.white),
              ),
            ),
           Center(
              child: Text(
                "Izabella",
                style: TextStyle(fontSize: 38, color: Colors.white),
              ),
            ),
          ],
        ),
    
    );
      }
    
    }
    

    【讨论】:

    • Container 没有 Child 命名参数。
    【解决方案2】:

    这就像你的形象......

    class Body extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Center(
          child: Text(
            "Hello",
            style: TextStyle(fontSize: 14, color: Colors.white),
          ),
        ),
        
        Center(
          child: Text(
            "Izabella",
            style: TextStyle(fontSize: 38, color: Colors.white),
          ),
        ),
      ],
    );
    }
    }
    

    希望对你有帮助...

    【讨论】:

      【解决方案3】:

      我希望这能回答你的问题

      class Body extends StatelessWidget {
        @override
        Widget build(BuildContext context) {
          return Scaffold(
            backgroundColor: Colors.blue,
            body: Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                 // first text
                  Text('Hello', style: TextStyle(fontSize: 15, color: Colors.white)),
                 // second text
                  Text('Izabella',
                      style: TextStyle(fontSize: 25, color: Colors.white)),
                ],
              ),
            ),
          );
        }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-26
        • 2022-01-16
        • 1970-01-01
        • 2021-01-12
        • 2021-06-09
        • 2020-02-12
        • 1970-01-01
        • 2020-01-13
        相关资源
        最近更新 更多