docでuidを指定した後に、mapで取得する。その際に、Map
String? msg = '';
FirebaseFirestore firestore = FirebaseFirestore.instance;
final snapshot = await firestore.collection('mydata').doc('12345678').get();
final Map<String, dynamic>? mydata = snapshot.data();
msg = mydata?['name'];
_controller.text = msg!;
firestoreではなく、flutterの中でmap型を指定する場合は以下のように書いてOK
final Map<String, String> frameworks = {
'Flutter' : 'Dart',
'Rails' : 'Ruby',
};
コレクションを複数指定する場合とは書き方が大分異なる
var msg = '';
FirebaseFirestore firestore = FirebaseFirestore.instance;
final snapshot = await firestore.collection('mydata').orderBy('name', descending: false).get();
snapshot.docChanges.forEach((element) {
final name = element.doc.get('name');
final mail = element.doc.get('mail');
final age = element.doc.get('age');
msg += "${name} (${age}) <${mail}>\n";
});
_controller.text = msg;