1

I'm beginner to this flutter. Currently i am trying to do email authentication for sign-up. I already tried few solution from website/github/youtube, but it turns to the same error which is on FirebaseUser. Here i attach my code segment.

class _RegisterEmailSectionState extends State<_RegisterEmailSection> {

  void _register() async {
    final FirebaseUser user = (await
    _auth.createUserWithEmailAndPassword(
      email: _emailController.text,
      password: _passwordController.text,
    )
    ).user;
    if (user != null) {
      setState(() {
        _success = true;
        _userEmail = user.email;
      });
    } else {
      setState(() {
        _success = true;
      });
    }
  }
  void dispose() {
    _emailController.dispose();
    _passwordController.dispose();
    super.dispose();
  }

  final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
  final TextEditingController _emailController = TextEditingController();
  final TextEditingController _passwordController = TextEditingController();
  bool _success;
  String _userEmail;

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: Text(widget.title),
    ),
    body: Form(
      key: _formKey,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          TextFormField(
            controller: _emailController,
            decoration: const InputDecoration(labelText: 'Email'),
            validator: (String value) {
              if (value.isEmpty) {
                return 'Please enter some text';
              }
              return null;
            },
          ),
          TextFormField(
            controller: _passwordController,
            decoration: const InputDecoration(labelText:
            'Password'),
            validator: (String value) {
              if (value.isEmpty) {
                return 'Please enter some text';
              }
              return null;
            },
          ),
          Container(
            padding: const EdgeInsets.symmetric(vertical: 16.0),
            alignment: Alignment.center,
            child: RaisedButton(
              onPressed: () async {
                if (_formKey.currentState.validate()) {
                  _register();
                }
              },
              child: const Text('Submit'),
            ),
          ),
          Container(
            alignment: Alignment.center,
            child: Text(_success == null
                ? ''
                : (_success
                ? 'Successfully registered ' + _userEmail
                : 'Registration failed')),
          )
        ],
      ),
    ),
  );
}
 }

Is there something that I miss out? I don't know why FirebaseUser error in my code. I assume that it is error due to different version of firebase. I found someone from the flutter community and they said try to changed it to be Authresult but the same error come out.

Can anyone help me on this issue? Thank you in advance!

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Nur Atikah
  • 31
  • 3

1 Answers1

3

Change

    final FirebaseUser user = ...

to

    final User user = ...

Here is the class you trying to get here. It has the type of User.

Simon Sot
  • 2,748
  • 2
  • 10
  • 23