Santos-Enoque / complete_flutter_ecommerce

This repo will contain the backend code and the Ui of the flutter ecommerce app
676 stars 423 forks source link

Login Error: Unhandled Exception: NoSuchMethodError #16

Closed reznov11 closed 3 years ago

reznov11 commented 3 years ago

If I attempted to login it throws errors in console:

D/FirebaseAuth(14569): Notifying auth state listeners about user ( SnJ6QLfJRpRs6rCB2H05Eclsrtr2 ). E/flutter (14569): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The method '[]' was called on null. E/flutter (14569): Receiver: null E/flutter (14569): Tried calling: []("name") E/flutter (14569): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)

divyekhanna commented 3 years ago

Hey I debugged through this issue, looks like there's a problem with the code. You need to change the createUser method of UserServices class in lib/services/users.dart file like so:

void createUser(Map<String, dynamic> data) async {
    await _firestore.collection(collection).doc(data["uid"]).set(data)
    .then((value) => print("User Added"))
    .catchError((error) => print("Failed to add user: $error"));
  }

Notice Map<String, dynamic> instead of Map and async await pair.

reznov11 commented 3 years ago

Solved