Created
January 24, 2024 10:39
-
-
Save sahildev001/76955690a6d8368ce6289050fd70446a to your computer and use it in GitHub Desktop.
create routs in flutter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static const String routeName = '/LogInScreen'; | |
static Route route() { | |
return PageRouteBuilder( | |
settings: RouteSettings(name: routeName), | |
pageBuilder: (context, animation, secondaryAnimation) => LogInScreen(), | |
transitionsBuilder: (context, animation, secondaryAnimation, child) { | |
const begin = Offset(1.0, 0.0); | |
const end = Offset.zero; | |
final tween = Tween(begin: begin, end: end); | |
final offsetAnimation = animation.drive(tween); | |
return SlideTransition( | |
position: offsetAnimation, | |
child: child, | |
); | |
}, | |
); | |
} | |
//----------------------------------------------------- | |
class AppRouter { | |
static Route? onGenerateRoute(RouteSettings settings) { | |
SharedPreferenceHelper? preferenceHelper = SharedPreferenceHelper(); | |
dev.log("This is route: ${settings.name}"); | |
switch (settings.name) { | |
case '/': | |
return SplashScreen.route(); | |
case LogInScreen.routeName: | |
return LogInScreen.route(); //LogInScreen.route(); | |
default: | |
return _errorRoute(); | |
} | |
} | |
static Route _errorRoute() { | |
return MaterialPageRoute( | |
settings: RouteSettings(name: "/error"), | |
builder: (_) => Scaffold( | |
appBar: AppBar(title: Text("Error")), | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment