W/System ( 6271): Ignoring header X-Firebase-Locale because its value was null

Viewed 1380

I get this error at my terminal Ignoring header X-Firebase-Locale because its value was null when user sign in or sign up. The screen doesnt change state when user sign in. I have enabled email password sign in, use SHA-1 and SHA-256 (get from ./gradlew signingReport) at my firebase.console for this app but still, keep getting this error from the terminal and I have no idea how to solve this. Really need your help.

Below is my code and the directories.

auth.dart

import 'package:firebase_auth/firebase_auth.dart';
import 'package:twitterclone/models/users.dart';

class AuthService {
  FirebaseAuth auth = FirebaseAuth.instance;

  UserModel? _userFromFirebaseUser(User? user) {
    return user != null ? UserModel(id: user.uid) : null;
  }

  Stream<UserModel?> get user {
    return auth.authStateChanges().map(_userFromFirebaseUser);
  }

  Future signUp(emailSignUp, passwordSignUp) async {
    try {
      User user = (await auth.createUserWithEmailAndPassword(
          email: emailSignUp, password: passwordSignUp) as User);
      _userFromFirebaseUser(user);
    } on FirebaseAuthException catch (e) {
      if (e.code == 'weak-password') {
        print('The password provided is too weak.');
      } else if (e.code == 'email-already-in-use') {
        print('The account already exists for that email.');
      }
    } catch (e) {
      print(e);
    }
  }

  Future signIn(emailSignIn, passwordSignIn) async {
    try {
      User user = (await auth.signInWithEmailAndPassword(
          email: emailSignIn, password: passwordSignIn) as User);
      _userFromFirebaseUser(user);
    } on FirebaseAuthException catch (e) {
      print(e);
    } catch (e) {
      print(e);
    }
  }

  Future signOut() async {
    try {
      return await auth.signOut();
    } catch (e) {
      print(e.toString());
      return null;
    }
  }
}

wrapper.dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:twitterclone/models/users.dart';
import 'package:twitterclone/screens/auth/welcome.dart';
import 'package:twitterclone/screens/mainscreen/feedscreen.dart';

class Wrapper extends StatelessWidget {
  const Wrapper({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final user = Provider.of<UserModel?>(context);
    if (user == null) {
      print('no user');
      return Welcome();
    }
    print('has user');
    return FeedScreen();
  }
}

user.dart

class UserModel {
  final String? id;
  UserModel({this.id});
}

main.dart

import 'dart:core';
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:provider/provider.dart';
import 'package:twitterclone/models/users.dart';
import 'package:twitterclone/services/auth/auth.dart';
import 'package:twitterclone/wrapper/wrapper.dart';

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

class MyApp extends StatelessWidget {
  final Future<FirebaseApp> _initialization = Firebase.initializeApp();

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      future: _initialization,
      builder: (context, snapshot) {
        // Check for errors
        if (snapshot.hasError) {
          return Text('Oops, something went error. Try to restart the app.');
        }

        // Once complete, show your application
        if (snapshot.connectionState == ConnectionState.done) {
          return StreamProvider<UserModel?>.value(
            value: AuthService().user,
            initialData: null,
            child: MaterialApp(home: Wrapper()),
          );
        }

        // Otherwise, show something whilst waiting for initialization to complete
        return Text('Loading...');
      },
    );
  }
}
1 Answers

I hope you fotgot to add ChangeNotifier .

replace class AuthService { ... with class AuthService with ChangeNotifier{ ... .

upVote if it works, I'm new here .

Related