I'm going to upload the user model to the database after signing up as a member through firebase Auth on the flutter web. If sign up, I can register well with Firebase Auth. However, after that, an error is output while uploading to the database.
pubspec.uaml
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
firebase_core: ^0.5.0 #웹을 위해 추가?
firebase_auth: ^0.18.0 #0.16.1
cloud_firestore: ^0.14.0 #0.13.7
firebase_storage: ^4.0.0 #3.1.6
flutter_web_frame: ^0.0.2 #웹에서 최대 사이즈를 지정해주는 패키지
carousel_slider: ^3.0.0
get: ^3.3.0
cached_network_image: ^2.2.0+1
provider: ^4.3.3
auth and firestore code
class Transformers {
//DocumentSnapshot -> UserModel Transform
final toUser = StreamTransformer<DocumentSnapshot, UserModel>.fromHandlers(
handleData: (snapshot, sink) async {
sink.add(UserModel.fromSnapShot(snapshot));
}
);
}
class UserNetworkRepo with Transformers{
//When signing up, check if user model is registered in the firestore and upload if not.
Future<void> attempCreatUser({String userKey, String userEmail}) async {
final DocumentReference userRef =
FirebaseFirestore.instance.collection(COLLECTION_USERS).doc(userKey);
//get user document
DocumentSnapshot snapshot = await userRef.get();
//check user database
if (!snapshot.exists) {
return await userRef.set(UserModel.getMapForCreatUser(userEmail));
}
}
Stream<UserModel> getUserModelStream(String userKey) {
return FirebaseFirestore.instance
.collection(COLLECTION_USERS)
.doc(userKey)
.snapshots()
//documentSnapshot data -> UserNodel
.transform(toUser);
}
During the debug, the StreamTransformer brakes and then outputs the following errors.
TypeError: Cannot read properties of null (reading 'Symbol(dartx._get)')
at user_model.UserModel.fromSnapShot.user_model.UserModel.fromMap (http://localhost:65386/packages/omd_test/model/user_model.dart.lib.js:103:42)
at new user_model.UserModel.fromSnapShot (http://localhost:65386/packages/omd_test/model/user_model.dart.lib.js:113:34)
at http://localhost:65386/packages/omd_test/repo/helper/transformer.dart.lib.js:36:18
at Generator.next (<anonymous>)
at runBody (http://localhost:65386/dart_sdk.js:40666:34)
at Object._async [as async] (http://localhost:65386/dart_sdk.js:40697:7)
at http://localhost:65386/packages/omd_test/repo/helper/transformer.dart.lib.js:35:137
at _HandlerEventSink.new.add (http://localhost:65386/dart_sdk.js:39044:11)
at _SinkTransformerStreamSubscription.new.[_handleData] (http://localhost:65386/dart_sdk.js:38869:34)
at _RootZone.runUnaryGuarded (http://localhost:65386/dart_sdk.js:40429:11)
at _ForwardingStreamSubscription.new.[_sendData] (http://localhost:65386/dart_sdk.js:33989:22)
at _ForwardingStreamSubscription.new.[_add] (http://localhost:65386/dart_sdk.js:33935:26)
at _ForwardingStreamSubscription.new.[_add] (http://localhost:65386/dart_sdk.js:38197:20)
at _MapStream.new.[_handleData] (http://localhost:65386/dart_sdk.js:38328:19)
at _ForwardingStreamSubscription.new.[_handleData] (http://localhost:65386/dart_sdk.js:38225:37)
at _RootZone.runUnaryGuarded (http://localhost:65386/dart_sdk.js:40429:11)
at _ForwardingStreamSubscription.new.[_sendData] (http://localhost:65386/dart_sdk.js:33989:22)
at _ForwardingStreamSubscription.new.[_add] (http://localhost:65386/dart_sdk.js:33935:26)
at _ForwardingStreamSubscription.new.[_add] (http://localhost:65386/dart_sdk.js:38197:20)
at _HandleErrorStream.new.[_handleData] (http://localhost:65386/dart_sdk.js:38403:19)
at _ForwardingStreamSubscription.new.[_handleData] (http://localhost:65386/dart_sdk.js:38225:37)
at _RootZone.runUnaryGuarded (http://localhost:65386/dart_sdk.js:40429:11)
at _ForwardingStreamSubscription.new.[_sendData] (http://localhost:65386/dart_sdk.js:33989:22)
at _ForwardingStreamSubscription.new.[_add] (http://localhost:65386/dart_sdk.js:33935:26)
at _ForwardingStreamSubscription.new.[_add] (http://localhost:65386/dart_sdk.js:38197:20)
at _MapStream.new.[_handleData] (http://localhost:65386/dart_sdk.js:38328:19)
at _ForwardingStreamSubscription.new.[_handleData] (http://localhost:65386/dart_sdk.js:38225:37)
at _RootZone.runUnaryGuarded (http://localhost:65386/dart_sdk.js:40429:11)
at _BroadcastSubscription.new.[_sendData] (http://localhost:65386/dart_sdk.js:33989:22)
at _BroadcastSubscription.new.[_add] (http://localhost:65386/dart_sdk.js:33935:26)
at _SyncBroadcastStreamController.new.[_sendData] (http://localhost:65386/dart_sdk.js:34655:34)
at _SyncBroadcastStreamController.new.add (http://localhost:65386/dart_sdk.js:34449:24)
at http://localhost:65386/packages/cloud_firestore_web/src/interop/utils/utils.dart.lib.js:367:22
at Object._checkAndCall (http://localhost:65386/dart_sdk.js:5586:16)
at Object.dcall (http://localhost:65386/dart_sdk.js:5591:17)
at Object.ret [as next] (http://localhost:65386/dart_sdk.js:62759:21)
at Object.next (https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js:1:320206)
at next (https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js:1:303665)
at https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js:1:244953
[2021-11-02T07:24:18.188Z] @firebase/firestore:
I'm making the web and the app together, the app works well. Can I know the problem with this?
Thank you.
Aucun commentaire:
Enregistrer un commentaire