简体   繁体   中英

Flutter/Firebase error - Unhandled Exception: type '_CompactLinkedHashSet<void>' is not a subtype of type 'FutureOr<Set<Future<void>>>'

I am trying to allow users to sign up to use my app using firebase. I have a "Create account" button and when pressed I expect my submit() function to be executed. Here is my submit function:

  Future submit() async {
if (validate()) {
  _formKey.currentState.reset();
  await firebaseAuth
      .createUserWithEmailAndPassword(
          email: _emailController.text, password: _passwordController.text)
      .then(
        (user) => {
          FirebaseFirestore.instance
              .collection('users')
              .doc(user.user.uid)
              .set(
            {
              'id': user.user.uid,
              'displayName': _firstNameController.text.trim() +
                  " " +
                  _lastNameController.text.trim(),
              'email': _emailController.text.trim(),
              'createdat': DateTime.now(),
            },
          ),
        },
      )
      .catchError(
        (err) => {
          print(
            err.toString(),
          ),
        },
      );
}

}

I then call this here:

                          RaisedButton(
                          child: Text(
                            'Create an Account',
                            style: TextStyle(color: Colors.white),
                          ),
                          onPressed: () async {
                            await submit();
                          }),

However, when I run my app, fill out my signup form and then press the button to submit I get the following message:

    [VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: type '_CompactLinkedHashSet<void>' is not a subtype of type 'FutureOr<Set<Future<void>>>'
#0      _FutureListener.handleError (dart:async/future_impl.dart:160:20)
#1      Future._propagateToListeners.handleError (dart:async/future_impl.dart:708:47)
#2      Future._propagateToListeners (dart:async/future_impl.dart:729:24)
#3      Future._completeError (dart:async/future_impl.dart:537:5)
#4      _AsyncAwaitCompleter.completeError (dart:async-patch/async_patch.dart:47:15)
#5      FirebaseAuth.createUserWithEmailAndPassword (package:firebase_auth/src/firebase_auth.dart)
<asynchronous suspension>
#6      _SignUpPageState.submit (package:consi/screens/SignUpPage.dart:68:12)
#7      _SignUpPageState.build.<anonymous closure> (package:consi/screens/SignUpPage.dart:242:39)
#8      _SignUpPageState.build.<anonymous closure> (package:consi/screens/SignUpPage.dart:241:42)
#9      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:993:19<…>

Can someone help me resolve this issue? Thanks

Try to remove the Future type of the code like below and then call in the submit button.

If does not work; remove it in every function that called during the signup.

if the problems persist, please I advise you to do inline debug by putting breaking points on this view so that you can see how the program itself is executing each line of code.

submit() async {
if (validate()) {
  _formKey.currentState.reset();
  await firebaseAuth
      .createUserWithEmailAndPassword(
          email: _emailController.text, password: _passwordController.text)
      .then(
        (user) => {
          FirebaseFirestore.instance
              .collection('users')
              .doc(user.user.uid)
              .set(
            {
              'id': user.user.uid,
              'displayName': _firstNameController.text.trim() +
                  " " +
                  _lastNameController.text.trim(),
              'email': _emailController.text.trim(),
              'createdat': DateTime.now(),
            },
          ),
        },
      )
      .catchError(
        (err) => {
          print(
            err.toString(),
          ),
        },
      );
}

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