Reputation: 5
I searched a lot but couldn't find a solution. I need your help.
In my database model, I have a method like this to get the data:
Future<Map<String,dynamic>> getSystemSettings() async {
var response = await _firestore.collection("system").doc("settings").get();
return response.data();
}
Later, I want to use the data in the form of Map <String, dynamic> from the class I want to get the data from by calling the method as follows.
getValues() {
database.getSystemSettings().then((value) {
print("value");
print(value);
});
What I expect is to see my Map <String, dynamic> type data in place of value in the second code block, but I get the following error.
The method 'sistemAyarlariniAl' was called on null.
Receiver: null
Tried calling: sistemAyarlariniAl()
Can you help me with this? Where am I doing wrong?
Upvotes: 0
Views: 186
Reputation: 309
Try This
Future getPosts() async {
var firestore = Firestore.instance;
QuerySnapshot qn = await firestore.collection("system").getDocuments();
return qn.documents;
}
Or You can use Stream Builder to access data from firebase.
to do that first you need to install cloud_firestore library
dependencies:
cloud_firestore: ^0.14.4
then import it
import 'package:cloud_firestore/cloud_firestore.dart';
then need to build StreamBuilder
StreamBuilder(
stream: Firestore.instance
.collection('system')
.document(users.uid)
.snapshots(),
builder: (context, snapshot){
if (snapshot.hasData) {
return Container())
You Can access your database values like this
snapshot.data['settings'].toString()
Example in TextField
Text(
snapshot.data['settings'].toString(),
style: TextStyle(
fontSize: 20,
decorationThickness:2,
fontWeight:
FontWeight.w500,
color:Colors.black87)
),
Upvotes: 1