0

I am currently using flutter_login 3.1.0 in my application. During the process of user signing up, it is required that he assigns himself a username, the application is supposed to check whether the username that is typed in is taken or not from Firebase Firestore and display it to the user.

    @override
    Widget build(BuildContext context) {
        return FlutterLogin(
            // irrelevant code removed
            additionalSignupFields: [
              UserFormField(
                keyName: 'username',
                displayName: 'Username',
                icon: const Icon(FontAwesomeIcons.at),
                fieldValidator: (value) async {   // error 'Cant assign async function to function'
                  return await DatabaseService.validateUsername(value);
                },
              ),
            ]
        )
    }

The function assigned to fieldValidator has to be async because getting data from firestore always returns a Future.

People have told me to use FutureBuilder or StreamBuilder, I have tried and failed to achieve the functionality. It would great if code is provided rather than just an explanation

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Criss Hills
  • 189
  • 1
  • 12
  • It seems like `fieldValidator` has to be a synchronous function. Check out this question/answer for an async approach: https://stackoverflow.com/questions/55360628/create-async-validator-in-flutter – Frank van Puffelen Jan 12 '22 at 04:53
  • Then i wouldn't be able to use the flutter_login package! – Criss Hills Jan 12 '22 at 17:57

0 Answers0