我正在try 对传入的列表视图进行排序.因为这个列表视图是图像,所以我向FireStore对象添加了一个数字,这样我就可以升序排序.
我似乎不能让项目排序,我确定这是我如何构建的应用程序.
我试图将.orderBy()添加到集合中,但是它说查询不是CollectionReference的类型.
这是我的页面
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:cloud_firestore/cloud_firestore.dart';
class Events extends StatefulWidget {
@override
_EventsState createState() => _EventsState();
}
class _EventsState extends State<Events> {
StreamSubscription<QuerySnapshot> subscription;
List<DocumentSnapshot> snapshot;
CollectionReference collectionReference =
Firestore.instance.collection("Events");
@override
void initState() {
subscription = collectionReference.snapshots().listen((datasnapshot) {
setState(() {
snapshot = datasnapshot.documents;
});
});
super.initState();
}
// passData(DocumentSnapshot snap) {
// Navigator.of(context).push(
// MaterialPageRoute(builder: (context) => EventPage(snapshot: snap,)));
// }
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Column(
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width,
height: 200,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill,
image: AssetImage("assets/images/events.jpg"),
),
),
),
Divider(
color: Colors.black,
),
Expanded(
child: ListView.separated(separatorBuilder: (context, index) => Divider(color: Colors.black12,
), itemCount: snapshot.length,
itemBuilder: (context, index){
return Card(
child: Container(
width: MediaQuery.of(context).size.width,
height: 210,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill,
image: NetworkImage(snapshot[index].data["image"]),
),
),
),
);
}
))
],
),
);
}
}
我真的很想在数据库中按预定的数字对这些图像进行排序.