Ignoring header X-Firebase-Locale because its value was null

I'm currently doing a project on Android Studio and I'm using the sign in authentication. It works sometimes but sometimes it doesn't with the error "Ignoring header X-Firebase-Locale because its value was null."

Usually the way I fix this is just reloading the app but is there a way around to this?

My code

authentication_service.dart

import 'package:firebase_auth/firebase_auth.dart';


class AuthenticationService{
  final FirebaseAuth _firebaseAuth;

  AuthenticationService(this._firebaseAuth);

  Stream<User> get authStateChanges => _firebaseAuth.authStateChanges();


  Future<void> signOut() async{
    await _firebaseAuth.signOut();
  }

  Future<void> sendPasswordResetEmail(String email) async{
    return _firebaseAuth.sendPasswordResetEmail(email: email);
  }


  Future<String> signIn({String email, String password}) async{
    try{
      await _firebaseAuth.signInWithEmailAndPassword(email: email, password: password);
      return "Signed in";

    } on FirebaseAuthException catch (e){
      var errorCode = e.code;
      var errorMessage = e.message;
      

      if(errorCode == 'auth/wrong-password'){
        return ('Wrong Password.');
      }
      else{
        return errorMessage;
      }
    }

  }

  Future<String> signUp({String email, String password}) async{
    try{
      await _firebaseAuth.createUserWithEmailAndPassword(email: email, password: password);
      return "Signed up";
    } on FirebaseAuthException catch(e){
      return e.message;
    }
  }


}

login.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'main.dart';
import 'package:provider/provider.dart';
import 'package:final_app/authentication_service.dart';
import 'signup.dart';


class MyLogin extends StatefulWidget{
  @override
  _MyLoginPage createState() => new _MyLoginPage();
}

class _MyLoginPage extends State<MyLogin>{
  final _formKey = GlobalKey<FormState>();

  String _email;
  String _password;
  TextEditingController emailController = new TextEditingController();


  bool validateEmail(String value) {
    Pattern pattern =
        r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$';
    RegExp regex = new RegExp(pattern);
    return (!regex.hasMatch(value)) ? false : true;
  }



  @override
  Widget build(BuildContext context){
    return new Scaffold(
      resizeToAvoidBottomPadding: false,
      // backgroundColor: Colors.cyan,
      body: Form(
        key: _formKey,
        child: SingleChildScrollView(
          child: Column(
            children: <Widget>[
              Container(
                child: Stack(
                  children: <Widget>[
                    Container(
                        padding: EdgeInsets.fromLTRB(45.0, 55.0, 0.0, 0.0),
                        child: Text(
                            'Pawsibilities',
                            style: TextStyle(fontSize: 60.0,fontFamily: "Smile", fontWeight: FontWeight.bold)
                        )
                    ),
                    Container(
                        padding: EdgeInsets.fromLTRB(140.0, 150.0, 130.0, 0.0),
                        child: Image.asset('assets/download.png')
                    ),
                  ]
                )
              ),
              Container(
                padding: EdgeInsets.only(top: 35.0, left: 20.0, right: 20.0),
                child: Column(
                  children: <Widget>[
                    TextFormField(
                      decoration: InputDecoration(
                        labelText: 'Username',
                        hintText: 'Email',
                        labelStyle: TextStyle(
                          fontWeight: FontWeight.bold,
                          color: Colors.grey,
                        ),
                      ),
                      onSaved: (value) => _email = value,
                      validator: (value){
                        if(value.isEmpty){
                          return 'Email needed!';
                        }
                        if(!validateEmail(_email)){
                          return 'Valid Email Needed!';
                        }
                        return null;
                      },
                    ),
                    SizedBox(height: 20.0),
                    TextFormField(
                        decoration: InputDecoration(
                            labelText: 'Password',
                            labelStyle: TextStyle(
                              fontWeight: FontWeight.bold,
                              color: Colors.grey,
                            ),
                        ),
                      onSaved: (value) => _password = value,
                      validator: (value)
                        {
                          if(value.isEmpty){
                            return 'Password Needed!';
                        }
                          return null;
                        },
                      obscureText: true,
                    ),
                    SizedBox(height: MediaQuery.of(context).viewInsets.bottom),
                    SizedBox(height: 5.0),
                    Container(
                      alignment: Alignment(1.0,0.0),
                      padding: EdgeInsets.only(top: 15.0, left: 20.0),
                      child: InkWell(
                        onTap: (){
                          showDialog(
                            context: context,
                            builder: (BuildContext context) => new CupertinoAlertDialog(
                              title: Text("Enter Email"),
                              actions: [
                                CupertinoDialogAction(
                                  child: Text("Send"),
                                  onPressed: () {
                                    Navigator.of(context).pop();
                                    context.read<AuthenticationService>().sendPasswordResetEmail(emailController.text);
                                  }
                                )
                              ],
                              content: CupertinoTextField(
                                placeholder: "Email",
                                controller: emailController,
                              )
                            ),
                          );
                        },
                        child: Text(
                          'Forgot Password?',
                          style: TextStyle(
                            color: Colors.cyan,
                            fontWeight: FontWeight.bold,
                            decoration: TextDecoration.underline
                          ),
                        ),
                      )
                    ),
                    SizedBox(height: 40.0),
                    Container(
                      height: 40.0,
                      child: Material(
                        borderRadius: BorderRadius.circular(20.0),
                        shadowColor: Colors.cyanAccent,
                        color: Colors.cyan,
                        elevation: 7.0,
                        child: InkWell(
                          onTap: () {
                            final form = _formKey.currentState;
                            form.save();
                            if(form.validate()){
                            context.read<AuthenticationService>().signIn(
                              email: _email,
                              password: _password,
                            );
                          }
                            },
                          child: Center(
                            child: Text(
                              'Login',
                              style: TextStyle(
                                fontWeight: FontWeight.bold,
                                color: Colors.white,
                              ),
                            ),
                          ),
                        ),
                      ),
                    ),
                    SizedBox(height: 20.0),
                    Container(
                      height: 40.0,
                      color: Colors.transparent,
                      child: InkWell(
                        onTap: (){
                          showDialog(
                              context: context,
                              builder: (BuildContext context) => CupertinoAlertDialog(
                              title: Text("Please fur-give me! Coming Soon :)"),
                              actions:[
                                CupertinoDialogAction(
                                    child: Text("Close"),
                                    onPressed: (){
                                      Navigator.of(context).pop();
                                    }
                                )
                              ]
                          ));
                        },
                        child: Container(
                          decoration: BoxDecoration(
                            border: Border.all(
                              color: Colors.black,
                              style: BorderStyle.solid,
                              width: 1.0,
                            ),
                            color: Colors.transparent,
                            borderRadius: BorderRadius.circular(20.0)
                          ),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: <Widget>[
                              Center(
                                child: ImageIcon(AssetImage('assets/facebook.png')),
                              ),
                              SizedBox(width: 10.0),
                              Center(
                                child: Text('Login with Facebook', style: TextStyle(
                                  fontWeight: FontWeight.bold,
                                ))
                              )
                            ]
                          )
                        ),
                      )
                    )
                  ]
                )
              ),
              SizedBox(height:15.0),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Text(
                    'Looking for Pawsibilites?',
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                    )
                  ),
                  SizedBox(width: 5.0),
                  InkWell(
                    onTap: () {
                      Navigator.push(context, MaterialPageRoute(builder: (context) => MySignUp()));
                    },
                    child: Text(
                      'Register',
                      style: TextStyle(
                        color: Colors.cyan,
                        fontWeight: FontWeight.bold,
                        decoration: TextDecoration.underline,
                      )
                    )
                  )
                ],
              )
            ]
          ),
        ),
      ),


    );


  }

}

main.dart

import 'package:final_app/authentication_service.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'dogs.dart';
import 'doginfo.dart';
import 'search.dart';
import 'login.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:provider/provider.dart';
import 'package:firebase_auth/firebase_auth.dart';

Future<void> main() async{
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();

  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        Provider<AuthenticationService>(
          create: (_) => AuthenticationService(FirebaseAuth.instance),
        ),
        StreamProvider(
          create: (context) => context.read<AuthenticationService>().authStateChanges,
        )
      ],
      child: MaterialApp(
        title: 'Final',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: SplashScreen(),
      ),
    );
  }
}

class AuthenticationWrapper extends StatelessWidget{

  const AuthenticationWrapper({
    Key key,
}): super(key:key);

  @override
  Widget build(BuildContext context){
    final firebaseUser = context.watch<User>();

    if(firebaseUser != null){
      return MyHomePage();
    }
    return MyLogin();
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  var url = "https://bitbucket.org/cs481group5/doggydex/raw/e75c3c49f55fdcf63044e89d85ab512affb87483/doggydexx.json";


  DogHub dogHub;

  @override
  void initState(){
    super.initState();
    fetchData();
  }

  fetchData() async{
    var res = await http.get(url);
    var decodedJson = jsonDecode(res.body);

    dogHub = DogHub.fromJson(decodedJson);
    print(dogHub.toJson());
    setState(() {

    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          title: Text("Doggies Search", style: TextStyle(fontSize: 18, wordSpacing: 125)),
          backgroundColor: Colors.cyan,
          actions: <Widget>[
            IconButton(icon: Icon(Icons.search),
                onPressed: () {
              showSearch(context: context, delegate: DataSearch());
                })
          ]
      ),
      body: dogHub == null? Center(child: CircularProgressIndicator()):
      GridView.count(
        crossAxisCount: 2,
          children: dogHub.dog
              .map((dog) => Padding(
            padding: const EdgeInsets.all(2.0),
            child: InkWell(
              onTap: (){
                Navigator.push(context, MaterialPageRoute(builder: (context) => DogDetail(
                  dog: dog,
                )));

              },
              child: Hero(
                tag: dog.image,
                child: Card(
                  elevation: 3.0,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: <Widget>[
                      Container(
                        height: 100.0,
                        width: 100.0,
                        decoration: BoxDecoration(
                          image: DecorationImage(image: NetworkImage(dog.image)),
                        ),
                      ),
                      Text(
                        dog.breed, style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold)),
                    ]
                  )
                ),
              ),
            ),
          )).toList(),
      ),
      drawer: Drawer(
        child: ListView(
          padding: EdgeInsets.zero,
          children: [
            Container(
              color: Colors.cyan,
              child: DrawerHeader(
                child: CircleAvatar(
                    radius: 10,
                    backgroundColor: Colors.transparent,
                    child: ClipOval(
                      child: Image.asset('images/avatar.png',
                      width: 125,
                      height: 125,
                      fit: BoxFit.cover,)
                    ),
                  ),
                ),
              ),
            ListTile(
              leading: Icon(Icons.search, color: Colors.deepPurple),
              title: Text('Dog List'),
              onTap: (){
                Navigator.push(context, MaterialPageRoute(builder: (context) => MyHomePage()));
              },
            ),
            Divider(color: Colors.black),
            ListTile(
              leading: Icon(Icons.map, color: Colors.blue),
              title: Text('Dog Parks'),
              onTap: (){

              },
            ),
            Divider(color: Colors.black),
            ListTile(
              leading: Icon(Icons.favorite, color: Colors. red),
              title: Text('Favorites'),
              onTap: (){

              },
            ),
            Divider(color: Colors.black),
            ListTile(
              leading: Icon(Icons.person, color: Colors.green),
              title: Text('Account Info'),
              onTap: (){

              },
            ),
            Divider(color: Colors.black),
            ListTile(
              title: Text('Log Out'),
              onTap: (){
                context.read<AuthenticationService>().signOut();
                // Navigator.of(context).pop();
              },
            ),
          ],
        ),
      ),
    );
  }
}

class SplashScreen extends StatefulWidget{
  @override
  _SplashScreenState createState() => _SplashScreenState();
}

class _SplashScreenState extends State<SplashScreen> with SingleTickerProviderStateMixin{
  double opacity = 0;

  @override
  void initState(){
    super.initState();
    Timer(Duration(seconds: 5), ()=>Navigator.pushReplacement(context,MaterialPageRoute(builder: (context)=>AuthenticationWrapper())));
    changeOpacity();
  }

  changeOpacity(){
    Future.delayed(Duration(seconds: 3), (){
      setState(() {
        opacity = opacity == 0.0 ? 1.0 : 1.0;
      });
    });
  }

  Widget build(BuildContext context) {
      return Scaffold(
        body: Container(
          child: Stack(
            alignment: Alignment.center,
            children: [
              Opacity(
                opacity: 1,
                child: Image.asset('images/wallpaper.jpg',
                fit: BoxFit.cover,
                height: 800),
              ),
              Opacity(
                opacity: 1,
                child: Image.asset('images/paw2.gif'),
              ),
              AnimatedOpacity(
                duration: Duration(seconds: 1),
                opacity: opacity,
                child: Text(
                  'Pawsibilities',
                  style: TextStyle(color: Colors.black, fontFamily: "Smile", fontSize: 50),
                ),
              )
            ],
          )
        ),
      );
   }

    @override
    dispose() {
    //  _animationController.dispose();
      super.dispose();
    }
  }

build.gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 29

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.cs481.final_app"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation platform('com.google.firebase:firebase-bom:26.1.0')
    implementation 'com.google.firebase:firebase-auth'
}

This also happens when I sign up, I usually have to restart the app for the new username/password to be used.

I have the dependences in my build.grade


Solution 1:

The message "Ignoring header X-Firebase-Locale because its value was null." is just a warning. It'll be helpful if you can provide the complete error log that you received.

Usual cause of this issue are Email/Password Sign-in method being disabled in the Firebase console and the Android emulator not being set up properly.