【问题标题】:How do you add a card in flutter?你如何在颤振中添加一张卡片?
【发布时间】:2020-08-17 00:24:56
【问题描述】:

我正在尝试添加一张卡片。我在下面有一段代码,它有一个脚手架-> 容器-> 容器。这包含渐变背景颜色。当我尝试添加卡片时,渐变背景颜色要么消失,要么被限制在页面顶部的一个小容器中。

在哪里添加卡片,这样我才能拥有全屏背景渐变色,并且卡片是屏幕顶部的小卡片?

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Container(
          child: Container(
            decoration: new BoxDecoration(
              gradient: new LinearGradient(
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
                colors: [
                  Color.fromARGB(255, 25, 178, 238),
                  Color.fromARGB(255, 21, 236, 229)
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    Scaffold(
      body: Stack(
        children: [
          Positioned.fill(
            child: Container(
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  begin: Alignment.topCenter,
                  end: Alignment.bottomCenter,
                  colors: [
                    Color.fromARGB(255, 25, 178, 238),
                    Color.fromARGB(255, 21, 236, 229)
                  ],
                ),
              ),
            ),
          ),
          Positioned(
            top: 50,
            right: 16,
            left: 16,
            child: Card(
              child: SizedBox(
                height: 100,
              ),
            ),
          )
        ],
      ),
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-02
      • 2020-05-31
      • 2021-06-05
      • 2020-12-03
      • 2020-05-14
      • 2023-03-18
      • 1970-01-01
      • 2021-07-07
      相关资源
      最近更新 更多