【发布时间】:2020-04-18 15:08:11
【问题描述】:
我想将详细信息显示在我的 Cloud Firestore 中显示的图像中,以显示电影颤振页面,但不知道如何从 Firestore 中检索列表以及如何在代码中实现的自定义卡片中显示该列表。 我尝试了其他方法但没有成功。 有人可以帮助实施上述内容吗? 这是我的第一个问题,非常抱歉出现错误。
class CustomCard extends StatelessWidget {
CustomCard(
{@required this.movie_name,
this.genre,
this.famous_cast,
this.rating,
this.comment,
this.free_link});
final movie_name;
final genre;
final famous_cast;
final rating;
final comment;
final free_link;
@override
Widget build(BuildContext context) {
return Card(
child: Container(
padding: const EdgeInsets.symmetric(vertical: 15.0, horizontal: 10.0),
child: Column(
children: <Widget>[
Text(movie_name),
Text(genre),
Text(famous_cast),
Text(rating),
Text(comment),
Text(free_link),
],
),
),
);
}
}
class ShowPage extends StatefulWidget {
@override
_ShowPageState createState() => _ShowPageState();
}
class _ShowPageState extends State<ShowPage> {
final db = Firestore.instance.collection('Movies');
@override
Widget build(BuildContext context) {
return new Scaffold(
resizeToAvoidBottomPadding: false,
appBar: AppBar(
title: Text('Show Movies'),
backgroundColor: Colors.blueGrey[900],
),
backgroundColor: Colors.white,
body: Container(
padding: const EdgeInsets.all(20.0),
child: StreamBuilder<QuerySnapshot>(
stream: db.snapshots(),
builder:
(BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) return new Text('Error: ${snapshot.error}');
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return new Text('Loading.....');
default:
return new ListView(children: getExpenseItems(snapshot));
}
},
),
),
);
}
getExpenseItems(AsyncSnapshot<QuerySnapshot> snapshot) {
return snapshot.data.documents
.map(
(doc) => new CustomCard(
movie_name: new Text(doc["movie_n"]),
genre: new Text(doc["genre"]),
famous_cast: new Text(doc["famous_c"]),
rating: new Text(doc["rating"].toString()),
comment: new Text(doc["comments"]),
free_link: new Text(doc["free_link"]),
),
)
.toList();
}
}
【问题讨论】:
标签: flutter dart google-cloud-firestore