StreamBuilder(
stream: _trip.snapshots(),
builder: (context, AsyncSnapshot<QuerySnapshot> streamSnapshot) {
if (streamSnapshot.hasData) {
return ListView.builder(
itemCount: streamSnapshot.data!.docs.length,
itemBuilder: (context, index) {
final DocumentSnapshot documentSnapshot =
streamSnapshot.data!.docs[index];
DateTime dt2 =DateFormat('dd-MM-yyyy').parse(documentSnapshot['enddate']);
if(dt2.isAfter(new DateTime.now())){
return Card(margin: const EdgeInsets.all(10),
child: ListTile(leading: Image.asset("assets/images/baggage.png"),
title: Column(crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("Trip: ${documentSnapshot['tripname']}",
style: TextStyle(fontWeight: FontWeight.bold,fontSize: 16),),
SizedBox(height: 7,),
Text("Location: ${documentSnapshot['location']} "),
SizedBox(height: 10,)],),
subtitle: Column(crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text( "Starts: ${documentSnapshot['startdate']}",
style: TextStyle(fontSize: 15.5),),
SizedBox(height: 7,),
Text("Ends: ${documentSnapshot['enddate']}",style: TextStyle(fontSize: 15.5),),],),
trailing: SizedBox(
width: 100, height: 100,
child: Row(children: [IconButton(
onPressed: () => _update(documentSnapshot),
icon: Icon(Icons.edit,),),IconButton(
onPressed: () {setState(() {Navigator.of(context).push( MaterialPageRoute(builder: (context) => ShowPlans(tripid: documentSnapshot['tripid'])));});},
icon: Icon(Icons.arrow_forward_ios,),),],), ),),elevation: 3,);}
return const SizedBox(); },);}
return const Center(child: CircularProgressIndicator(),);},),
我已经在这里存储和检索了firebase 'trip'集合中的数据。现在我想将它们存储在本地存储中并检索它们。我该怎么做呢?请帮助..
1条答案
按热度按时间w8f9ii691#
你可以使用本地的No-SQL数据库比如hive来保存本地存储的数据。不过Firebase插件已经在本地缓存了数据,所以问题是你想达到什么样的效果,也许Firebase插件就足够了?
PS:对于简单的键值存储,你也可以使用localstorage插件来实现flutter,或者你可以使用path_provider来直接存储文件,但是这很可能不是你想要的,这取决于你想要的结果。