Created
January 21, 2021 12:20
-
-
Save littleironical/4f4ec36a2e564299183104ae07cb0ab5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Initialising as 'loading..' because text widget (where you'll be using these variables) can't be null | |
String firstName = 'loading...' | |
String lastName = 'loading...' | |
String title = 'loading...' | |
class Screen extends StatefulWidget { | |
@override | |
_ScreenState createState() => _ScreenState(); | |
} | |
class _ScreenState extends State<Screen> { | |
//Creating a reference to the collection 'users' | |
CollectionReference collectionReference = | |
FirebaseFirestore.instance.collection('users'); | |
//This function will set the values to firstName, lastName and title from the data fetched from firestore | |
void getUsersData() { | |
collectionReferenceToOrderacWeb.doc('user1').get().then((value) { | |
//'value' is the instance of 'DocumentSnapshot' | |
//'value.data()' contains all the data inside a document in the form of 'dictionary' | |
var fields = value.data(); | |
//Using 'setState' to update the user's data inside the app | |
//firstName, lastName and title are 'initialised variables' | |
setState(() { | |
firstName = fields['firstName']; | |
lastName = fields['lastName']; | |
title = fields['title']; | |
}); | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Container(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment