【问题标题】:Is it possible to make two cards one below the other?有没有可能让两张卡一张低于另一张?
【发布时间】:2020-07-30 02:51:30
【问题描述】:

我有一个问题:我需要两张一张低于另一张的卡片。我已经用下面的代码试过了,但是容器中的第二个“孩子”是红色的,我作为一个初学者不知道为什么。是的,我知道,孩子只是一个,孩子不止一个,但我不知道它应该如何与孩子一起工作。如果有人可以帮助我解决这个(可能很容易解决)问题,我会很高兴。提前致谢!

Container(
  child: Card(
    child: InkWell(
      splashColor: Colors.blue.withAlpha(30),
      onTap: () {
        print Text("Got it");
      },
      child: Container(
        child: Text("title", style: TextStyle(fontSize: 20)),
        //width: 300,
        height: 100,
        color: Colors.blue,
      ),
    ),
  ),
  child: Card(
    child: InkWell(
      splashColor: Colors.blue.withAlpha(30),
      onTap: () {
        print Text("Got it");
      },
      child: Container(
        child: Text("title", style: TextStyle(fontSize: 20)),
        //width: 300,
        height: 100,
        color: Colors.blue,
      ),
    ),
  ),
),

【问题讨论】:

  • 代替Container,使用Column小部件,您可以将多个子级添加到一个列中

标签: flutter dart containers flutter-container flutter-card


【解决方案1】:

您需要使用Column 小部件来显示多个小部件,一个接一个,如下所示:

Column(
  children: <Widget>[
    Card(
      child: InkWell(
        splashColor: Colors.blue.withAlpha(30),
        onTap: () {
          print("Got it");
        },
        child: Container(
          child: Text("title", style: TextStyle(fontSize: 20)),
          //width: 300,
          height: 100,
          color: Colors.blue,
        ),
      ),
    ),
    Card(
      child: InkWell(
        splashColor: Colors.blue.withAlpha(30),
        onTap: () {
          print("Got it");
        },
        child: Container(
          child: Text("title", style: TextStyle(fontSize: 20)),
          //width: 300,
          height: 100,
          color: Colors.blue,
        ),
      ),
    ),
  ]
),

【讨论】:

    猜你喜欢
    • 2012-09-21
    • 2016-08-29
    • 2021-09-16
    • 2018-08-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多