Skip to content

Instantly share code, notes, and snippets.

@sahildev001
Created January 24, 2024 10:39
Show Gist options
  • Save sahildev001/76955690a6d8368ce6289050fd70446a to your computer and use it in GitHub Desktop.
Save sahildev001/76955690a6d8368ce6289050fd70446a to your computer and use it in GitHub Desktop.
create routs in flutter
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