构建卡片小部件[Flutter]

时间:2018-03-12 17:38:23

标签: dart flutter

我正在尝试在颤振中建立自己的卡片,但是我一直没有定义孩子的错误。

我正在尝试构建的卡片类型here

是否也可以将我链接到正确解释何时使用儿童和儿童的教程,因为这似乎是我目前的问题。

我的代码如下所示:

    List<Widget> cardlist = <Widget>[
  new Card(
    child: new Column(
      children: <Widget>[
        new Row(
          child: new CircleAvatar(
            backgroundImage: new AssetImage('images/pic.jpg'),
            radius: 100.0,
          ),
        )
      ],
      child: new Row(
        child: new CircleAvatar(
          backgroundImage: new AssetImage('images/pic.jpg'),
          radius: 100.0,
        ),
        child: new Text(
          'News Location',
          style: new TextStyle(
            fontSize: 20.0,
            fontWeight: FontWeight.bold,
            color: Colors.black,
          ),
        ),
      ),
      child: new Image.asset(
        'images/lake.jpg',
        height: 240.0,
        fit: BoxFit.cover,
      ),
      child: new Text(
        'News Headline',
        style: new TextStyle(
          fontSize: 20.0,
          fontWeight: FontWeight.bold,
          color: Colors.black,
        ),
      ),
      child: new Text(
        'News Summary',
        style: new TextStyle(
          fontSize: 20.0,
          fontWeight: FontWeight.bold,
          color: Colors.black,
        ),
      ),
      child: new Row(
        child: new CircleAvatar(
          backgroundImage: new AssetImage('images/pic.jpg'),
          radius: 100.0,
        ),
        child: new Text(
          'News Source',
          style: new TextStyle(
            fontSize: 20.0,
            fontWeight: FontWeight.bold,
            color: Colors.black,
          ),
        ),
        child: new Text(
          '12 hours ago',
          style: new TextStyle(
            fontSize: 20.0,
            fontWeight: FontWeight.bold,
            color: Colors.black,
          ),
        ),

      ),
    ),
  )
];

1 个答案:

答案 0 :(得分:1)

我认为你想要的东西就像我下面的东西,不确定它是完全正确但它应该给你一个起点。基本上你需要了解什么时候使用孩子和什么时候孩子,以及正确的语法。只考虑您正在使用的小部件,以及它是否可以包含一个(子)或多个(子)子小部件,或查看文档以查看它需要:)

body: new Center(
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            new Card(
              child: new Column(                
                children: [
                  new Row(
                    children: [
                      new CircleAvatar(
                        backgroundImage: new AssetImage('images/pic.jpg'),
                        radius: 100.0,
                      ),
                    ]
                  ),
                ]
              ),
            ),
            new Card(
              child : new Row(
                children : [
                  new CircleAvatar(
                    backgroundImage: new AssetImage('images/pic.jpg'),
                    radius: 100.0,
                  ),
                  new Text(
                    'News Location',
                    style: new TextStyle(
                      fontSize: 20.0,
                      fontWeight: FontWeight.bold,
                      color: Colors.black,
                    ),
                  ),
                ]
              ),
            ),
            new Card(
              child: new Column(                
                children: [
                  new Image.asset(
                    'images/lake.jpg',
                    height: 240.0,
                    fit: BoxFit.cover,
                  ),
                  new Text(
                    'News Headline',
                    style: new TextStyle(
                      fontSize: 20.0,
                      fontWeight: FontWeight.bold,
                      color: Colors.black,
                    ),
                  ),
                  new Text(
                    'News Summary',
                    style: new TextStyle(
                      fontSize: 20.0,
                      fontWeight: FontWeight.bold,
                      color: Colors.black,
                    ),
                  ),
                  new Row(
                    children : [
                      new CircleAvatar(
                        backgroundImage: new AssetImage('images/pic.jpg'),
                        radius: 100.0,
                      ),
                      new Text(
                        'News Source',
                        style: new TextStyle(
                          fontSize: 20.0,
                          fontWeight: FontWeight.bold,
                          color: Colors.black,
                        ),
                      ),
                      new Text(
                        '12 hours ago',
                        style: new TextStyle(
                          fontSize: 20.0,
                          fontWeight: FontWeight.bold,
                          color: Colors.black,
                        ),
                      ),
                    ]
                  ),
                ]
              ),
            ),
          ],
        ),
      ),