Can't register user in firebase (firebase_auth/unknown: null)

0

I am registering a user in firebase and each time I try to register it shows me the mentioned error and donot send credentials to the firebase. Although it is getting the credentials from the firebase for login but shows error while storing values in firebase. Below is the code for only register that is getting the email address and password. I have another question that like password and email how could I store other details in firebase e.g Age, Gender etc. Kindly help me go through this.

class _ClientRegistrationScreenState extends State<ClientRegistrationScreen> {
  bool showSpinner = false;
  final _auth = FirebaseAuth.instance;
  File image;
  //final ImagePicker _picker = ImagePicker();
  String password;
  String confirmPassword;
  String email;
  String name;
  bool _passwordVisible = false;
  bool _confirmPasswordVisible = false;

  @override
  void initState() {

    _passwordVisible = false;
    _confirmPasswordVisible = false;
  }
  final _formKey = GlobalKey<FormState>();
  Expanded(
                    child: Center(
                      child: TextFormField(
                        validator: (value) {
                          if (value == null || value.isEmpty) {
                            return '*Email Address Required';
                          }
                          return null;
                        },
                     
                        ),
                      ),
                    ),
                  ),
                  Expanded(
                    child: Center(
                      child: TextFormField(
                        onChanged: (value){
                          password = value;
                        },
                        validator: (value) {
                          if (value == null || value.isEmpty) {
                            return '*Password Required';
                          }
                          if (password != confirmPassword) {
                            return 'Password Donot Match';
                          }
                          return null;
                        },
                        
                            onPressed: () {
                            
                              setState(() {
                                _passwordVisible = !_passwordVisible;
                              });
                            },
                          ),
                        ),
                      ),
                    ),
                  ),
                  Expanded(
                    child: Center(
                      child: TextFormField(
                        onChanged: (value){
                          confirmPassword = value;
                        },
                        validator: (value) {
                          if (value == null || value.isEmpty) {
                            return '*Confirm Password';
                          }
                          if (password != confirmPassword) {
                            return 'Password Donot Match';
                          }
                          return null;
                        },
                             onPressed: () {
                              
                              setState(() {
                                _confirmPasswordVisible = !_confirmPasswordVisible;
                              });
                            },
                          ),
                        ),
                      ),
                    ),
                  ),
                  RoundedButton(
                      colour: Colors.yellow,
                      opColour: Colors.yellow.withOpacity(0.2),
                      title: 'Register',
                      buttonTextColor: Colors.black,
                      onPressed: () async {
                        if (_formKey.currentState.validate()) {
                          setState(() {
                            showSpinner = true;
                          });
                         
                          ScaffoldMessenger.of(context).showSnackBar(
                            const SnackBar(content: Text('Processing Data')),
                          );
                        }

                        try {
                          final newUser = await _auth.createUserWithEmailAndPassword(
                              email: email, password: password);
                          if(newUser!=null){
                            Navigator.pushNamed(context, MainEmployeeScreen.id);
                            print(name);
                          }
                          setState(() {
                            showSpinner = false;
                          });
                        }
                        catch(e){
                          print(e);
                        }
                      }
                  ),
1

0

Did you initialize firebase in main function?

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}
2021-11-24 06:32:41

yes I have initialized it in main
Usama Bin Tahir

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................