I'm trying to make a list with cards with an image, the idea is that these cards are generated dynamically in the future through API requests, but for now I want to start with an image only, but when I run I have the following error :
type 'List ' is not a subtype of type 'list '
How could I solve ?, please your help.
My code is in a file called:
requests.dart
and this is my code:
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)),
)
],
)
)
],
),
);
}
}
Change
List cards = new List.generate(20, (i)=>new CustomCard());
to
final List<Widget> cards = List<Widget>.generate(20, (i)=>new CustomCard());
Children expects List nothing else, not even dynamic type.