Flutter Tutorial:
Flutter Widgets:
Flutter Advance
Flutter REST API
Advanced Concepts
Wrap vs Builder vs OverBarFlow
Circular progress contain Icon
Flutter State management Comparison
Flutter Database
Flutter Token Expired Handling
Flutter Provider
Flutter GetX
Flutter with Native
Flutter Tips:
Interview Questions
Flutter 100 Interview Questions
Token Expired Handling in Flutter
When Token Expired how to navigate to Home Page or Login Page in Flutter
// Generally, if token expires we have to take user to login page, for this below navigator works automatically, you can use as per your needs
Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (context) =>LoginScreen()), (Route<dynamic> route) => false);
OR
Navigator.of(context)
.pushNamedAndRemoveUntil('/login', (Route<dynamic> route) => false);
Navigator.of(context).popUntil(ModalRoute.withName('/root'));
OR
SchedulerBinding.instance.addPostFrameCallback((_) async {
Navigator.of(context).pushNamedAndRemoveUntil(
'/login',
(Route<dynamic> route) => false);
});
With GetX
Get.offUntil(page, (route) => false)
OR
Get.offAllNamed('/home');
OR
Get.offAll(Home());
OR
Get.offAll(()=>PageName());
OR
Get.offNamedUntil('home', (route) => false);
If you have any query, please comment below, we will reply soon