【发布时间】:2019-06-08 06:44:38
【问题描述】:
我正在尝试通过其“id”获取特定文档的信息以显示该文档的信息。
我用于服务的代码是这样的:
class SentenciasFireBase {
//This is a class where I have all the services of firebase
...
obtenerVacaciones(String empleado) async {
//empleado is the document id
return await Firestore.instance.document('Vacaciones/$empleado');
}
...
}
显示信息的代码是这样的:
class TurnoActual_State extends State<TurnoActual>{
...
SentenciasFireBase objetoSentencias = new SentenciasFireBase();
//This object "metodos" is of a class that has several reusable methods:
Metodos metodos = new Metodos();
@override
void initState() {
objetoSentencias.obtenerVacaciones(_noEmpleado).then((resultados){
setState(() {
vacaciones = resultados;
});
});
}
...
@override
Widget build(BuildContext context){
...
RichText(
text: TextSpan(
//toDateTime is a method that converts a timestamp into a DateTime,
//and then converts the DateTime into a String with a specific date format.
//'Inicio' stores a timestamp (it is the date on which the holidays start):
text: metodos.toDateTime(vacaciones.documents[0].data['Inicio']),
style: TextStyle(
color: Colors.black,
fontSize: 30,
fontWeight: FontWeight.bold,
),
)
)
...
}
这是错误信息:
颤振:══╡ 小部件库发现的异常。
╞═════════════════════════════════════════════════ ══════════
颤振:在构建 StreamBuilder(脏,状态:
颤振:_StreamBuilderBaseState>#45dbd):
颤振:在 null 上调用了 getter 'documents'
颤振:接收者:空
颤振:尝试调用:文档
注意:
我把文档的引用放错了,不是“Turnos”:
return await Firestore.instance.document('Turnos/$empleado');
但是“Vacaciones”:
return await Firestore.instance.document('Vacaciones/$empleado');
(我在问题中更新了它)但无论如何它不会“影响”问题本身。
【问题讨论】:
标签: flutter google-cloud-firestore