![](/img/trans.png)
[英]Flutter: type 'List<Widget>' is not a subtype of type 'Widget'
[英]Flutter type 'List<Future<Widget>>' is not a subtype of type 'List<Widget>'
我收到此錯誤:“列表>”類型不是“列表”類型的子類型
這是觸發錯誤的代碼。
@override
Widget build(BuildContext context) {
if (widget.productId != null) {
return StreamBuilder(
stream:
Document<Product>(path: 'app-data-inventory/${widget.productId}')
.streamData(),
builder: (BuildContext context, AsyncSnapshot snap) {
if (snap.hasError) {
print(snap.error);
}
if (snap.hasData) {
Product product = snap.data;
return Scaffold(
resizeToAvoidBottomPadding: false,
backgroundColor: AppAppTheme.white,
appBar: appBarComponents,
key: _scaffoldKey,
body: Stack(
children: <Widget>[
Builder(
builder: (context) => SingleChildScrollView(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
Container(
color: AppAppTheme.primary,
height: 230,
child: _yourWidget(context, product.productStorage['paths']),
),
SizedBox(
height: 10,
),
CheckboxListTile(
title: const Text('Terms of services'),
value: _product.termsAgreed != null
? _product.termsAgreed
: false,
onChanged: (val) {
setState(
() => _product.termsAgreed = val);
}),
SwitchListTile(
title: const Text('Save as draft'),
value: _product.productStatus == 'draft'
? true
: false,
onChanged: (bool val) => setState(() {
_product.productStatus =
val ? 'draft' : 'unapproved';
})),
]),
),
)
),
],
),
),
),
);
} else {
return UIErrorsMessages.notFoundComponent(
context, 'Product not found!');
}
});
} else {
return UIErrorsMessages.somethingIsNotRightComponent(
context, 'Something went wrong. Try again!');
}
}
}
我該如何解決這個問題?
您應該首先使用FutureBuilder
獲取數據,然后將數據提供給您的小部件。
以下代碼應該適合您:
(我沒有完整的代碼,所以我沒有測試過這個,如果有任何問題,請評論)
Widget _yourWidget(BuildContext context) {
return
color: AppTheme.primary,
height: 230,
child: Wrap(
children:
paths.map<Widget>((url) {
return FutureBuilder(builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData){
file = snapshot.data;
print(file);
return Column(
children: <Widget>[
FlatButton(
child: Text(
'Delete',
style: AppTheme
.titleWhite,
),
onPressed: () {
print(url);
},
),
Container(
width: 100.0,
height: 100.0,
margin:
EdgeInsets
.all(
10),
color:
AppTheme
.warn,
child: ExtendedImage
.network(file ==
null
? '/assets/icons/icon-120x120.png'
: file),
)
],
);
}else{
return Center(child: CircularProgressIndicator());
}
},);
});
}
Future fetchDownloadURL(){
return await _storage
.ref()
.child(url)
.getDownloadURL();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.