我正在研究Google Lab示例中的Firestore。我想发生的是将_buildList()和_buildListItem()函数Widget转换为包含参数的StatelessWidget,因为我将一篇文章拆分为功能Widget是性能反模式。但是我不知道从哪里开始。任何可以阐明这个问题的人。谢谢。
class _VideoListState extends State<VideoList> {
@override
Widget build(BuildContext context) {
...
body: StreamBuilder<QuerySnapshot>(
stream: Firestore.instance.collection(widget.category).snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return LinearProgressIndicator();
// I want StatelessWidget not function widget
return _buildList(context, snapshot.data.documents);
},
),
);
}
Widget _buildList(BuildContext context, List<DocumentSnapshot> snapshot) {
return ListView(
// I want StatelessWidget not function widget
children: snapshot.map((data) => _buildListItem(context, data)).toList(),
);
}
Widget _buildListItem(BuildContext context, DocumentSnapshot data) {
final record = Record.fromSnapshot(data);
return Column(
children: <Widget>[
Text(record.title),
YoutubePlayer(
source: record.videoId.toString(),
quality: YoutubeQuality.LOW,
autoPlay: false,
context: context
);
}
}
答案 0 :(得分:1)
很简单。看一下源代码并阅读注释。来源是自动解释的。我已将您的方法名称用作类名称。
Statement statement = new SimpleStatement("select * from tablename where condition1 = ? , value1 );