I would like to understand how to use Firebase with Flutter as of February 2021. My tutorial refers to Firestore.instance
but it doesn't work. Eventually I muddled into FirebaseFirestore.instance
, are these the same libraries?
My code block I am working with is below. However, I am stuck at this compiler error:
The argument type 'Future<GridView>' can't be assigned to the parameter type 'Widget'.
How can I get rid of this error?
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class MyFavorites extends StatelessWidget {
@override
Widget build(BuildContext ctx) {
return Scaffold(
appBar: MainAppBar(),
body: displayFavorites();
);
}
Future<DocumentSnapshot> _userName() async {
FirebaseFirestore firestore = FirebaseFirestore.instance;
final user = await FirebaseAuth.instance.currentUser;
final userData = await firestore.collection('AppUser').doc(user.uid).get();
return userData;
}
Future<GridView> displayFavorites() async {
DocumentSnapshot userName = await _userName();
return GridView.count(
crossAxisCount: 2,
// Generate 4 widgets that display their index in the List.
children: List.generate(6, (index) {
return Center(
//child: Text(favorites.elementAt(index)),
child: Text(userName["firstName"]),
);
}),
);
}
}