【发布时间】:2021-11-25 08:33:15
【问题描述】:
目前我正在实施一个应用程序,我试图从实时 Firebase 存储中获取与当前日期和时间相比较的特定值,或者我的意思是,我想获取与今天的日期和时间相匹配的数据。请帮帮我。 例如:
您可以在屏幕截图中看到实时 fireabase 数据。我想获取与当前日期或指定日期匹配的数据。
import 'package:firebase_database/firebase_database.dart';
import 'package:firebase_database/ui/firebase_animated_list.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
class ReadPromise extends StatefulWidget {
@override
_ReadPromiseState createState() => _ReadPromiseState();
}
class _ReadPromiseState extends State<ReadPromise> {
Query _ref;
DatabaseReference reference =
FirebaseDatabase.instance.reference().child('Daily Verse');
final DateTime now = DateTime.now();
final DateFormat formatter = DateFormat("dd MMMM yyyy");
@override
void initState() {
// TODO: implement initState
super.initState();
String today = formatter.format(now);
_ref = FirebaseDatabase.instance
.reference()
.child('Daily Verse')
.orderByChild('date');
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.indigo[900],
title: Text('Daily Promise Archive', textAlign: TextAlign.center,),
),
body:Container(
height: double.infinity,
child: FirebaseAnimatedList(
query: _ref,
itemBuilder: (BuildContext context, DataSnapshot snapshot,
Animation<double> animation, int index) {
Map readVerse = snapshot.value;
readVerse['key'] = snapshot.key;
return _buildContactItem(readPromise: readVerse);
})
)
);
}
}
Widget _buildContactItem({readPromise}) {
return Container(
margin: EdgeInsets.symmetric(vertical: 10),
padding: EdgeInsets.all(10),
height: 130,
color: Colors.white,
child: Container(
child: Card(
color: Colors.indigo,
shadowColor: Colors.black,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
SizedBox(
width: 6,
),
Text(
readPromise['data'],
style: TextStyle(
fontSize: 16,
color: Colors.white,
fontWeight: FontWeight.bold),
),
],
),
SizedBox(
height: 20,
),
Row(
children: [
SizedBox(
width: 6,
),
Text(
readPromise['verse'],
style: TextStyle(
fontSize: 16,
color: Colors.white,
fontWeight: FontWeight.bold),
),
SizedBox(
width: 140,
),
Text(
readPromise['date'],
style: TextStyle(
fontSize: 16,
color: Colors.white,
fontWeight: FontWeight.bold),
),
],
)
]
)
)));
}
【问题讨论】:
标签: flutter firebase-realtime-database