Flutter类型“ List <dynamic>”不是类型“ list <widget>”的子类型

时间:2019-03-20 14:09:58

标签: listview dart flutter statelesswidget

我正在尝试列出一张带有图片的卡片,其想法是这些卡片将来会通过API请求动态生成,但是现在我只想从一张图片开始,但是当我运行时有以下错误:

类型'列表'不是类型'列表'

的子类型

我该如何解决?请您帮忙。

我的代码在一个名为:

的文件中

requests.dart

这是我的代码:

import 'package:flutter/material.dart';

  class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
        home:new MyCard()
    );
  }
}

class MyCard extends StatelessWidget{
  List cards = new List.generate(20, (i)=>new CustomCard());
  @override
  Widget build(BuildContext context) {
      return new Scaffold(
            appBar: new AppBar(
              title: new Text('Car Results'),
              backgroundColor:new Color(0xFF673AB7),
            ),
            body: new Container(
              child: new ListView(
                children: cards,
              )
            )
        );

    }
}

class CustomCard extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
              return  new Card(
                    child: new Column(
                      children: <Widget>[
                        new Image.network('https://matwrites.com/wp-content/uploads/2018/03/Flutter.png'),
                        new Padding(
                          padding: new EdgeInsets.all(7.0),
                          child: new Row(
                            children: <Widget>[
                             new Padding(
                               padding: new EdgeInsets.all(7.0),
                               child: new Icon(Icons.thumb_up),
                             ),
                             new Padding(
                               padding: new EdgeInsets.all(7.0),
                               child: new Text('Like',style: new TextStyle(fontSize: 18.0),),
                             ),
                             new Padding(
                               padding: new EdgeInsets.all(7.0),
                               child: new Icon(Icons.comment),
                             ),
                             new Padding(
                               padding: new EdgeInsets.all(7.0),
                               child: new Text('Comments',style: new TextStyle(fontSize: 18.0)),
                             )

                            ],
                          )
                        )
                      ],
                    ),
                  );
  }
}

1 个答案:

答案 0 :(得分:2)

更改

for(var j=1;j<=i;j++)
{
    var table = document.getElementById("ing");
    var row = table.insertRow(-1);
    //var cell8=row.incertCell(0);
    var cell1 = row.insertCell(0);
    var cell2 = row.insertCell(1);
    var cell3 = row.insertCell(2);
    var cell4 = row.insertCell(3);
    var cell5 = row.insertCell(4);
    var cell6 = row.insertCell(5);    

    var name='ingname'+j;
    var code='ingcode'+j;
    var cur='ingcur'+j;
    var req='ingreq'+j;
    var cost='ingcost'+j;
    var date='ingdate'+j;

    cell1.innerHTML = "<input type='text' name=name>";
    cell2.innerHTML = "<input type='text' name=code>";
    cell3.innerHTML = "<input type='number' name='ingcur+i'>";
    cell4.innerHTML = "<input type='number' name='ingreq+i'>";
    cell5.innerHTML="<input type='number' name='ingcost+i'>";
    cell6.innerHTML="<input type='date' name='ingdate+i'>";
}

List cards = new List.generate(20, (i)=>new CustomCard());

孩子们希望没有列出任何东西,甚至没有动态类型。