Flutter Easy Routing
A lightweight, flexible routing solution for Flutter applications that simplifies route management with type-safe navigation and customizable transitions.
Features
- π§ Type-safe navigation - No more string-based routes
- π Custom transitions - Smooth animations between screens
- π£οΈ Route generation - Simplified route setup
- πΊοΈ Route mapping - Easy management of route names
- π± Platform adaptive - Uses CupertinoPageRoute on iOS
- π§© Extension methods - Intuitive context-based navigation APIs
Installation
Add flutter_easy_routing to your pubspec.yaml:
dependencies:
flutter_easy_routing:
Then run:
flutter pub get
Import the package:
import 'package:flutter_easy_routing/flutter_easy_routing.dart';
Basic Usage
Setup
- Define your route names by extending
AppRoutes
:
class Routes extends AppRoutes {
const Routes._(super.name);
static const home = Routes._('home');
static const profile = Routes._('profile');
static const settings = Routes._('settings');
}
- Configure the navigator in your MaterialApp:
MaterialApp(
title: 'Flutter Easy Routing Demo',
debugShowCheckedModeBanner: false,
/// TODO : add following configuations
navigatorKey: AppRouter.navigatorKey,
onGenerateRoute: (settings) => AppRouter.generateRoute(settings, MyHomePage()),
//
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
)
Create Routes
Create routes by implementing the BaseRoute
mixin:
class MyHomePage extends StatefulWidget with BaseRoute {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
/// TODO : override following properties (transitionType is option, if not given than takes default that set on material app)
@override
AppRoutes get routeName => Routes.home;
@override
Widget get screen => this;
@override
TransitionType get transitionType => TransitionType.fade;
}
/// next code
Navigation
Navigate using context extensions:
// Navigate to a route
context.push(HomePage().route);
// Navigate to a named route
context.pushNamed(HomePage());
// Replace current route
context.pushReplacement(ProfilePage());
// Clear stack and navigate
context.pushAndRemoveUntil(HomePage(), (route) => route.settings.name == Routes.home.path);
// Go back
context.pop();
/// and all other methods like Navigator..
Global Context
If you have no context than AppRouter provide navigation context:
final BuildContext context = AppRouter.context;
Global Navigator State
final NavigatorState navigatorState = AppRouter.state;
Transition Types
You can choose from several transition types:
TransitionType.fade
- Fade transitionTransitionType.slideUp
- Slide up from bottomTransitionType.slideLeft
- Slide in from rightTransitionType.scale
- Scale transitionTransitionType.size
- Size transition
Set a global default transition:
void main() {
RouteConfig.setDefaultTransition(TransitionType.slideLeft);
runApp(MyApp());
}
Route with Arguments
Pass arguments with your routes:
class NextPage extends StatelessWidget with BaseRoute {
final int count;
const NextPage({super.key, required this.count});
@override
AppRoutes get routeName => Routes.next;
@override
Widget get screen => this;
/// --- other code --
}
// Navigate with arguments
context.pushNamed(NextPage(count: 10));
Custom Route
Use the CustomRoute
class for quick route creation without defining a separate class:
final detailsRoute = CustomRoute(
routename: Routes.details,
page: DetailsScreen(item: selectedItem),
transition: TransitionType.scale,
);
context.pushNamed(detailsRoute);
π Love this package? Give it a β on GitHub & show some π β your support means everything!
~ π€ Nayan Parmar
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This package is licensed under the MIT License - see the LICENSE file for details.