Exception has occurred. _CastError (type 'Null' is not a subtype of type 'Map<dynamic, dynamic>' in type cast)
Closed this issue ยท 10 comments
Thank you for the awesome tutorial, mate. It's so well done :)
Sorry for asking you. I've decided to create a foodshare app and your code is conceptually very close what I'd like to build.
I try to run the app it stops circling around and doesn't move anywhere then I press 'Stepover' it starts endlessly circling around and drops another error. Not quite sure how to fix it. Could you pls help with this error by any chance? :)
Exception has occurred.
_CastError (type 'Null' is not a subtype of type 'Map<dynamic, dynamic>' in type cast)
When stepping over.
CategoryService.getCategoriesCollectionFromFirebase (package:foodshare/services/categoryservice.dart:21:32) <asynchronous suspension>
Running "flutter pub get" in foodshare...
Launching lib/main.dart on iPhone 12 Pro Max in debug mode...
lib/main.dart:1
Xcode build done. 784.0s
Connecting to VM Service at ws://127.0.0.1:58491/GgqClrs0f1A=/ws
[VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: type 'Null' is not a subtype of type 'Map<dynamic, dynamic>' in type cast
#0 CategoryService.getCategoriesCollectionFromFirebase (package:foodshare/services/categoryservice.dart:21:32)
<asynchronous suspension>
getting same issue, tried as per given solution . still unable to resolve
Hi Tarlan, Did you replace the files "GoogleService-Info.plist" inside ios/Runner folder? Remember you get this file from your Firebase Console, when you create the iOS app there. You get the GoogleService-Info.plist file for your project. Also for Android, you get a similar one from the Firebase Console, called "google-services.json", located on android/app. Remember, these two files are generated from Firebase Console (check one of the initial videos where I created the initial Firebase project) or you can check out the following screenshot: [image: image.png] Let me know if you replaced these files and tried again. Thanks
โฆ
On Tue, Jun 22, 2021 at 1:20 PM Tarlan Isaev @.***> wrote: Thank you for the awesome tutorial, mate. It's so well done :) Could you pls help with this error by any chance? Not quite sure how to fix :) Running "flutter pub get" in foodshare... Launching lib/main.dart on iPhone 12 Pro Max in debug mode... lib/main.dart:1 Xcode build done. 784.0s Connecting to VM Service at ws://127.0.0.1:58491/GgqClrs0f1A=/ws [VERBOSE-2:ui_dart_state.cc(199) http://127.0.0.1:58491/GgqClrs0f1A=/ws%5BVERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: type 'Null' is not a subtype of type 'Map<dynamic, dynamic>' in type cast #0 CategoryService.getCategoriesCollectionFromFirebase (package:foodshare/services/categoryservice.dart:21:32) โ You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#3>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGYVTETY4PKL7KNRXBMN3DTUDA4BANCNFSM47ED3V2Q .
Yeah, both files are on place, mate :)
getting same issue, tried as per given solution . still unable to resolve
Thanks for reproducing this issue :)
Also opened the question on StackOverflow
@devfwzone you can try out this approach. It has helped me to overcome the issue :)
Tarik Huber answered on Stackoverflow:
The DocumentSnapshot snapshot has the type of Map<String, dynamic>. Try to write your code like this. You should also check if snapshot.data() is null or not. I removed that from the code to focus on the type issue. Just updated the answer. Pls try it with the updated snipped. We can check if the documentSnapshot exists or not.
DocumentSnapshot snapshot = await categories.doc('categories').get();
if(snapshot.exists){
Map<String, dynamic> data = snapshot.data() as Map<String, dynamic>;
var categoriesData = data['categories'] as List<dynamic>;
categoriesData.forEach(
(catData) {
Category cat = Category.fromJson(catData);
_categories.add(cat);
},
);
}
}
thank you guys for the engaging and collaboration! I will definitely incorporate this into the main code. The code expected the collection to exist in Firebase for the purpose of the tutorial, but this is a good practice as well, so I'll add it. Thanks again!
@organicnz thank you for the engagement and collaboration! I will definitely incorporate this into the main code. The code expected the collection to exist in Firebase for the purpose of the tutorial, but this is a good practice as well, so I'll add it. Thanks again!
latest code has been updated to provide this check. Thank you all for the contribution!
latest code has been updated to provide this check. Thank you all for the contribution!
Thank you, man :)