skip to Main Content

I am trying to add Firebase Authentication to my app via email and password signup and login. When I test it out, it does not navigate to the next screen and I get the following message:

"Ignoring header X-Firebase-Locale because it was null"

However, when I go to Firebase, it shows the information I entered has been stored as a new user. Could someone please provide some insight on what is going on?

Here is my main.dart:

int? isViewed;
Future <void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  
  final prefs = await SharedPreferences.getInstance();
  final showLogin = prefs.getBool('showLogin') ?? false;
  Paint.enableDithering = true;
  
// This is for our onboarding screen
isViewed = prefs.getInt('onboard');

  runApp(MyApp(showLogin: showLogin));
}

class MyApp extends StatelessWidget {
  final bool showLogin;
  
  const MyApp({Key? key,
  required this.showLogin}) : super(key: key);


  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Strength',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        appBarTheme: const AppBarTheme(color: Color(0xffe0eff5),
        elevation: 0,
        brightness: Brightness.light,
        iconTheme: IconThemeData(color: Colors.black),
        textTheme: TextTheme(headline6: TextStyle(color: Color(0xff888888), fontSize: 18),
        )
      ),),
      home: const SplashScreen(),
    );
  }
}

Here are chunks of my signup.dart:

class SignUpScreen extends StatefulWidget {
  const SignUpScreen({Key? key}) : super(key: key);

  @override
  _SignUpScreenState createState() => _SignUpScreenState();

}

class _SignUpScreenState extends State<SignUpScreen> {
  TextEditingController _passwordTextController = TextEditingController();
  bool showPassword = false;
  bool _isPasswordEightLetters = false;
  bool _OneNumberPassword = false;
  TextEditingController _emailTextController = TextEditingController();

  OnPasswordChanged(String password) {
    
    final numericRegex = RegExp(r'[0-9;]');

    setState(() {

      _isPasswordEightLetters = false;
      if (password.length >= 8) {
        _isPasswordEightLetters = true;
      }

      _OneNumberPassword = false;
      if(numericRegex.hasMatch(password)) {
        _OneNumberPassword = true;
      }
    });
  }
.
.
.

Container(
                        child: TextFormField(
                          controller: _emailTextController,
                          style: const TextStyle(color: Colors.black),
                          keyboardType: TextInputType.emailAddress,
                          // inputFormatters: <TextInputFormatter>[
                          //   FilteringTextInputFormatter.allow(RegExp(r'[0-9]'))
                          // ],
                          decoration: InputDecoration(
                            hintText: "Enter Your Email Address",
                            hintStyle: const TextStyle(color: Color(0xff31708c),
                            fontSize: 15.5),
                            prefixIcon: const Icon(Icons.email_sharp,
                            color: Color(0xff31708c)),
                            focusedBorder: OutlineInputBorder(
                              borderRadius: BorderRadius.circular(10),
                              borderSide: const BorderSide(color: Color(0x6630728c))),
                              enabledBorder: OutlineInputBorder(
                                borderRadius: BorderRadius.circular(10),
                                borderSide: const BorderSide(color: Color(0x6630728c),
                              ),
                          ),
                        ),
                        autofillHints: const [AutofillHints.email]
                        ),
                        decoration: BoxDecoration(color: Colors.blueGrey.withOpacity(0.08),
                        borderRadius: BorderRadius.circular(10)),
                      )
.
.
.
ButtonTheme(
                      minWidth: MediaQuery.of(context).size.width,
                      height: 55,
                      buttonColor: const Color(0xff31708c),
                      child: RaisedButton(
                        onPressed: () {
                          FirebaseAuth.instance.createUserWithEmailAndPassword(
                            email: _emailTextController.text, 
                            password: _passwordTextController.text).then((_) {
                              print('New Account Created');
                          Navigator.of(context).
                          pushReplacement(MaterialPageRoute(builder: (context) => Dashboard()));
                          }
                      ).onError((error, stackTrace) {
                        print('Error');
                      });
                      },
                        shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(20),
                        ),
                        child: const Text("Sign Up",
                        style: TextStyle(color: Colors.white,
                        fontSize: 18,
                        fontWeight: FontWeight.bold),
                        ),
                      ),
                    )

3

Answers


  1. PREPARATION

    1. Check if your emulator has the permission to access internet and also is connected to.
    2. Email/Password Sign-in method in your firebase console is enabled to gain access.

    STEP 1: Create sha1 key + debug key information + Adding firebase.
    You probably have your sha1 key only with the normal information from the release key, I guess?

    STEP 2: Activate Android Device Verification from console.cloud.google.com and insert your sha keys that are automatically generated by firebase + their matching preferences (like package name…)

    CONCLUSION

    Your code looks good to me! Everything is set up right. I think you forgot some trivial settings or the right sha key.

    Login or Signup to reply.
  2. I have the same error while running on an Emulator.

    But it works perfectly fine when I run it on a real mobile device.

    So, if you test it on an emulator you have to create a new emulator.

    Login or Signup to reply.
  3. I faced the same problem for a week, the solution that I found is to change emulator, So I installed NoxPlayer android emulator and it works just great: this is the link to download it = https://www.bignox.com/

    and this is a video that explains how to connect it with android studio and vscode = https://www.youtube.com/watch?v=mEoGhw4LiNM

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search