'Ignoring header X-Firebase-Locale because its value was null - Yet app launches after a manual restart
I have a very weird error. When I try to log in/sign up to my app the user gets authenticated in firebase but the screens don't change. What's more, if I manually restart my app the authentication screen changes, and the app works the way it is supposed to. I attach the snippets of code, responsible for authentication and debug console data.
Debug console:
W/System ( 7512): Ignoring header X-Firebase-Locale because its value was null. 2 I/System.out( 7512): (HTTPLog)-Static: isSBSettingEnabled false D/InputConnectionAdaptor( 7512): The input method toggled cursor monitoring off I/SurfaceControl( 7512): nativeRelease nativeObject s[470179726496] I/SurfaceControl( 7512): nativeRelease nativeObject
Code:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final Future<FirebaseApp> _initialization = Firebase.initializeApp();
return FutureBuilder<Object>(
future: _initialization,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
}
...
home: StreamBuilder(
stream: FirebaseAuth.instance.authStateChanges(),
builder: (context, AsyncSnapshot<User?> userSnapshot) {
if (userSnapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
}
if (userSnapshot.hasData) {
print('user exists');
return MainScreen();
}
print('user does not exists');
return AuthScreen();
}),
routes: {
RecipeDetailScreen.routeName: (ctx) => RecipeDetailScreen(),
AddRecipeScreen.routeName: (ctx) => AddRecipeScreen(),
AuthScreen.routeName: (ctx) => AuthScreen(),
DiaryScreen.routeName: (ctx) => DiaryScreen(),
MainScreen.routeName: (ctx) => MainScreen(),
NutritionScreen.routeName: (ctx) => NutritionScreen(),
},
),
);
});
}
}
void authUser(
String email,
String password,
String conPassword,
bool isLogin,
) async {
setState(() {
isLoading = true;
});
FocusScope.of(context).unfocus();
try {
if (isLogin == false) {
await firebaseAuth.createUserWithEmailAndPassword(
email: email,
password: password,
);
} else {
await firebaseAuth.signInWithEmailAndPassword(
email: email,
password: password,
);
}
setState(() {
isLoading = false;
});
} on PlatformException catch (err) {
print(err);
var message = 'An error occurred, pelase check your credentials!';
if (err.message != null) {
message = err.message!;
}
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text(message),
backgroundColor: Theme.of(context).errorColor,
),
);
setState(() {
isLoading = false;
});
} catch (e) {
print(e);
setState(() {
isLoading = false;
});
rethrow;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
