![](/img/trans.png)
[英]Flutter/Firestore - type 'List<dynamic>' is not a subtype of type 'Widget'
[英]Flutter type 'List<dynamic>' is not a subtype of type 'list<Widget>'
我試圖做一個列表與圖像卡,這個想法是,這些卡都是通過API請求未來動態生成的,但現在我要開始只有圖像,但是當我跑,我有以下錯誤:
類型“列表”不是類型“列表”的子類型
我該如何解決?,請您的幫助。
我的代碼在一個名為:
request.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)),
)
],
)
)
],
),
);
}
}
更改
List cards = new List.generate(20, (i)=>new CustomCard());
至
final List<Widget> cards = List<Widget>.generate(20, (i)=>new CustomCard());
孩子們期望別的什么,甚至沒有動態類型。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.