'An exception was throw by _MapStream<DocumentSnapshot<Map<String, dynamic>>, UserModel>
Helllo... I need some help with Provider. I'm getting this exception but i can't find what is causing this.. The following assertion was thrown:
An exception was throw by _MapStream<DocumentSnapshot<Map<String, dynamic>>, UserModel> listened by
StreamProvider<UserModel?>, but no `catchError` was provided.
Exception:
Bad state: cannot get a field on a DocumentSnapshotPlatform which does not exist
I dont see anything wrong with StreamProvider
return MultiProvider(
providers: [
StreamProvider<UserModel?>(
initialData: null,
lazy: false,
create: (context) => DatabaseService().userData(_userId),
),
Here is Stream data from firebase
Stream<UserModel> userData(String? user) {
return _firestore
.collection("users")
.doc(user)
.snapshots()
.map(_userDataFromSnapshot);
}
UserModel _userDataFromSnapshot(DocumentSnapshot doc) {
return UserModel(
name: doc.get("name") ?? '',
email: doc.get('email') ?? '',
isAdmin: doc.get('isAdmin') ?? '',
easypaisa: doc.get('easypaisa') ?? '',
jazzCash: doc.get('jazzCash') ?? '',
bankAccount: doc.get('bankAccount') ?? '',
phoneNumber: doc.get('phoneNumber') ?? '',
profileImage: doc.data().toString().contains('profilePic')
? doc.get('profilePic') ?? ''
: ImageConstants.noImage,
isFavorite: List.from(doc.data().toString().contains('favoritePackages')
? doc.get('favoritePackages') ?? ''
: []),
activatedPackages: doc.data().toString().contains('activatedPackages')
? (doc.get('activatedPackages') as List<dynamic>)
.map((item) => ListOfPackages(
acceptedPackage: item['acceptedPackage'] ?? '',
packageId: item['packageId'] ?? '',
packageTime: item['packageTime'] ?? '',
proofImage: item['proofImage'] ?? '',
uid: item['uid'] ?? '',
username: item['username'] ?? '',
))
.toList()
: [],
uid: doc.get('uid') ?? '');
}
And here is the UserModel class
```dart
dart class UserModel {
final String uid;
final String name;
final String email;
final bool isAdmin;
final String easypaisa;
final String jazzCash;
final String bankAccount;
final String phoneNumber;
final String profileImage;
final List<String>? isFavorite;
final List<ListOfPackages>? activatedPackages;
UserModel({
this.uid = '',
this.name = '',
this.email = '',
this.isAdmin = false,
this.easypaisa = '',
this.jazzCash = '',
this.bankAccount = '',
this.phoneNumber = '',
this.profileImage = '',
final List<String>? isFavorite,
final List<ListOfPackages>? activatedPackages,
}) : isFavorite = isFavorite ?? [],
activatedPackages = activatedPackages ?? [];
}
class ListOfPackages {
final bool acceptedPackage;
final String packageId;
final String packageTime;
final String proofImage;
final String uid;
final String username;
ListOfPackages(
{this.acceptedPackage = false,
this.packageId = '',
this.packageTime = '',
this.proofImage = '',
this.uid = '',
this.username = ''});
}```
The exception comes only when i install the app for the First Time, and then when i'm redirected to login screen i see this exception, Then the app doesn't work correctly. But when i Hot Restart then it's working fine... I'd appreciate any help.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
