'Could not find the correct Provider<List<Userprofiles>> above this finaldashboard Widget
I am trying to display the name and email of the logged in user on the dashboard screen of my app but, while returning the provider package I am facing the following error. I am just not able to understand how to use the providerpackage to achieve this task. Please help me resolve the issue as I am new to flutter.
Here is the code of my Dashboard screen
class _NavigationDrawerWidgetState extends State<NavigationDrawerWidget> {
final padding = const EdgeInsets.symmetric(horizontal: 20);
final AuthService _auth = AuthService();
@override
Widget build(BuildContext context) {
//final usersData = Provider.of<List<Userprofiles>>(context);
const name = 'name';
const email = 'email';
return StreamProvider<List<Userprofiles>>.value(
value: DatabaseService().profiles,
initialData: [],
child: Drawer(
child: Material(
color: Colors.deepOrange,
child: ListView(
padding: padding,
children: <Widget>[
buildHeader(
name: name,
email: email,
onClicked: (){}
),
Here is the Database.dart file code:
class DatabaseService {
final String? uid;
DatabaseService({this.uid});
final CollectionReference UserProfile = FirebaseFirestore.instance.collection(
"Users");
Future UpdateUserData(String firstname, String lastname, int contactno,
String city, String address) async {
return await UserProfile.doc(uid).set({
'First name': firstname,
'Last name': lastname,
'Contact no': contactno,
'city': city,
'Address': address,
});
}
// user profile list from snapshot
List<Userprofiles> _userProfileListFromSnapShot(QuerySnapshot snapshot) {
return snapshot.docs.map((doc) {
return Userprofiles(
uid: doc.get('uid'),
firstname: doc.get('First name') ?? '',
lastname: doc.get('Last name') ?? '',
contact: doc.get('Contact') ?? '',
address: doc.get('Address') ?? '',
city: doc.get('City') ?? '');
}).toList();
}
Stream<List<Userprofiles>> get profiles {
return UserProfile.snapshots().map(_userProfileListFromSnapShot);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
