我在cloud_firestore中存储了一组网址,但无法显示从检索到的DocumentSnapshot中获取的图片。 当我使用pics:ds [“ pics”]。toSring时,我得到一张只用逗号分隔的照片列表,这使得指向该列表中的字符串很困难,但我想单独显示这些列表。
new Expanded(child: StreamBuilder(
stream: Firestore.instance.collection('dimandPosts').snapshots(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (!snapshot.hasData) {
return Center(child: const Text('Loading events...'));
}
return GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
itemBuilder: (BuildContext context, int index) {
DocumentSnapshot ds = snapshot.data.documents[index];
return new Lost_Card(pics : ds["pics"]);
},
itemCount: snapshot.data.documents.length,
);
},
))
class Lost_Card extends StatelessWidget {
//All the card variables
final String cName, id, photoUrl, nickName, country, phoneNumber, address,
cQuantity, cPrice, cLocation, cLead, cDescribe, sex, pics;
final IconData icon;
final Color iconBackgroundColor;
final ShapeBorder shape;
Lost_Card({
this.icon,
this.iconBackgroundColor,
this.shape, this.cName, this.id, this.photoUrl, this.nickName, this.country, this.phoneNumber, this.address, this.cQuantity, this.cPrice, this.cLocation, this.cLead, this.cDescribe, this.sex, this.pics,
});
void pop() {
print(cName);
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return GridView.count(
shrinkWrap: true,
crossAxisCount: 2,
children: <Widget>[
Card(
child: Column(
// mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: Stack(
fit: StackFit.expand,
children: <Widget>[
Container(
height: MediaQuery
.of(context)
.size
.height / 4,
width: MediaQuery
.of(context)
.size
.height / 2.5,
child: DecoratedBox(
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
pics),
fit: BoxFit.scaleDown),
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Align(
alignment: FractionalOffset.topLeft,
child: CircleAvatar(
backgroundColor: Colors.redAccent,
radius: 15.0,
child: Text(
cName ?? '',
textScaleFactor: 0.5,
),
),
),
),
Align(
alignment: FractionalOffset.topRight,
child: Container(
color: Colors.blueAccent,
height: 65.0,
width: 35.0,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.account_circle),
Text(
"1P",
textScaleFactor: 0.5,
),
],
),
),
),
),
],
),
),
Center(
child: Container(
padding: const EdgeInsets.all(8.0),
alignment: FractionalOffset.bottomCenter,
child: Text(
cPrice ?? '',
style: TextStyle(
fontWeight: FontWeight.w700,
),
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
FlatButton(
child: Text(
"Add To Cart",
style: TextStyle(color: Colors.grey[500]),
),
onPressed: pop,
),
Text(
"\$5",
style: TextStyle(color: Colors.grey[500]),
)
],
)
],
),
),
],
);
}
}