When I press back button and reopen my app it goes back to login screen but user is still logged in. I am using navigator.pushandremoveuntill when user signs in and my app works fine until I reopen my app then I am taken back to login page which shouldn't happen as I used navigator.pushandremoveuntill and removed all the background stack screens . can any one help me .
This is my code
signIn() async {
if (emailController.text.isNotEmpty &&
passwordController.text.isNotEmpty &&
passwordController.text.length >= 6) {
setState(() {
isClicked = true;
});
await FirebaseFunctions()
.signIn(emailController.text, passwordController.text, context);
if (FirebaseAuth.instance.currentUser != null) {
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (context) => const HomeScreen()),
(route) => false);
}
} else {
timerSnackbar(
backgroundColor: Colors.red,
buttonLabel: "",
context: context,
contentText: "Please Check your Credentials",
second: 2,
afterTimeExecute: () {});
setState(() {
isClicked = false;
});
}
}
and this is main app
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
home: FirebaseAuth.instance.currentUser != null
? const HomeScreen()
: const SelectionScreen(),
debugShowCheckedModeBanner: false,
);
}
}