我收到此错误: 类型“列表>”不是类型“列表”的子类型
这是触发错误的代码。
@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!');
}
}
}
我该如何解决?
答案 0 :(得分:1)
您应该首先使用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();
}