简体   繁体   中英

Firestore Database not updating (flutter/dart)

I am unable to create collections in firebase..

I can see that the authentication table is being updated with the info being send. I can see that the storage table is being updated with the info being send. I don't see the firestore table being updated.

I am also seeing an error

Submission code::

  void _submitFormOnSignUp() async {
    final isValid = _signUpFormKey.currentState!.validate();
    if (isValid) {
      if (imageFile == null) {
        GlobalMethod.showErrorDialog(
            error: 'Please pick an image', ctx: context);
        return;
      }
      setState(() {
        _isLoading = true;
      });
      try {
        await _auth.createUserWithEmailAndPassword(
          email: _emailTextController.text.trim().toLowerCase(),
          password: _passTextController.text.trim(),
        );
        final User? user = _auth.currentUser;
        final _uid = user!.uid;
        final ref = FirebaseStorage.instance
            .ref()
            .child('userImages')
            .child(_uid + '.jpg');
        await ref.putFile(imageFile!);
        imageUrl = await ref.getDownloadURL();
        FirebaseFirestore.instance.collection('users').doc(_uid).set({
          'id': _uid,
          'name': _fullNameController.text,
          'email': _emailTextController.text,
          'userImage': imageUrl,
          'phoneNumber': _phoneNumberTextController.text,
          'location': _locationTextController,
          'createAt': Timestamp.now()
        });
        Navigator.canPop(context) ? Navigator.of(context) : null;
      } catch (error) {
        setState(() {
          _isLoading = false;
        });
        GlobalMethod.showErrorDialog(error: error.toString(), ctx: context);
      }
    }

    setState(() {
      _isLoading = false;
    });
  }

Error code::

E/flutter ( 4118): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument: Instance of 'TextEditingController'
E/flutter ( 4118): #0      StandardMessageCodec.writeValue (package:flutter/src/services/message_codecs.dart:466:7)
E/flutter ( 4118): #1      FirestoreMessageCodec.writeValue (package:cloud_firestore_platform_interface/src/method_channel/utils/firestore_message_codec.dart:119:13)
E/flutter ( 4118): #2      StandardMessageCodec.writeValue.<anonymous closure> (package:flutter/src/services/message_codecs.dart:463:9)
E/flutter ( 4118): #3      _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:617:13)
E/flutter ( 4118): #4      StandardMessageCodec.writeValue (package:flutter/src/services/message_codecs.dart:461:13)
E/flutter ( 4118): #5      FirestoreMessageCodec.writeValue (package:cloud_firestore_platform_interface/src/method_channel/utils/firestore_message_codec.dart:119:13)
E/flutter ( 4118): #6      StandardMessageCodec.writeValue.<anonymous closure> (package:flutter/src/services/message_codecs.dart:463:9)
E/flutter ( 4118): #7      _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:617:13)
E/flutter ( 4118): #8      StandardMessageCodec.writeValue (package:flutter/src/services/message_codecs.dart:461:13)
E/flutter ( 4118): #9      FirestoreMessageCodec.writeValue (package:cloud_firestore_platform_interface/src/method_channel/utils/firestore_message_codec.dart:119:13)
E/flutter ( 4118): #10     StandardMethodCodec.encodeMethodCall (package:flutter/src/services/message_codecs.dart:604:18)
E/flutter ( 4118): #11     MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:285:34)
E/flutter ( 4118): #12     MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:472:12)
E/flutter ( 4118): #13     MethodChannelDocumentReference.set (package:cloud_firestore_platform_interface/src/method_channel/method_channel_document_reference.dart:31:52)
E/flutter ( 4118): #14     _JsonDocumentReference.set (package:cloud_firestore/src/document_reference.dart:166:22)
E/flutter ( 4118): #15     _SignUpState._submitFormOnSignUp (package:ijob_clone_app/SingUpPage/signup_screen.dart:174:66)
E/flutter ( 4118): <asynchronous suspension>

It's likely complaining about this line:

'location': _locationTextController,

You forgot to add .text like you did with the other fields.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM