rooute 0.0.4
rooute: ^0.0.4 copied to clipboard
A lightweight, enum-centric routing framework for Flutter with platform-adaptive transitions and strongly-typed navigation.
Rooute #
Author: Ibrahim Khatrii GitHub: https://github.com/IbrahimKhatrii/rooute
A lightweight, enum-centric routing framework for Flutter that enables strongly-typed navigation without messy switch-cases or string-based route names. Rooute is designed for developers who want clean, maintainable, and platform-adaptive routing.
Features #
- Strongly-typed routes using enums – no more fragile string-based navigation.
- Declarative mapping of enum → RouteBuilder – define how each route should transition.
- Platform-adaptive navigation – automatically chooses Material or Cupertino transitions.
- Custom transitions supported – use
PageRouteBuilderfor slides, fades, or complex animations. - Convenient navigation helpers – push, pushReplacement, pushAndRemoveUntil, pushForResult, etc.
- Argument passing – type-safe route arguments with easy retrieval via
RoutableApp.arguments<T>.
Installation #
Add rooute to your pubspec.yaml:
dependencies:
rooute: ^0.0.4
Then run:
flutter pub get
Quick Start #
1. Define your routes #
Create an enum that mixes in Rooute<T>:
enum MyRoutes with Rooute<MyRoutes> {
launcher,
home,
customPage;
@override
Map<MyRoutes, RoouteBuilder> get routes => {
launcher: RoouteBuilder.material(() => LauncherScreen()),
home: RoouteBuilder.cupertino(() => Home()),
customPage: RoouteBuilder.custom(
(settings) => PageRouteBuilder(
settings: settings,
pageBuilder: (context, animation, secondaryAnimation) =>
CustomScreen(),
transitionsBuilder: (context, animation, secondaryAnimation, child) =>
FadeTransition(opacity: animation, child: child),
),
),
};
@override
List<MyRoutes> get valuesOf => values;
}
2. Wrap your app with RoutableApp #
void main() {
runApp(
RoutableApp(
launcher: MyRoutes.launcher,
builder: (initialRoute, onGenerateRoute) => MaterialApp(
initialRoute: initialRoute,
onGenerateRoute: onGenerateRoute,
debugShowCheckedModeBanner: false,
),
),
);
}
3. Navigate between routes #
// Push a route
MyRoutes.home.push(context, arguments: 'Hello Home');
// Push a route and get result
final result = await MyRoutes.customPage.pushForResult<String>(context);
// Push replacement
MyRoutes.home.pushReplacement(context);
// Push and remove until predicate
MyRoutes.launcher.pushAndRemoveUntil(context, (route) => route.isFirst);
4. Retrieve route arguments #
final arg = RoutableApp.arguments<String>(context);
print(arg ?? 'No args');
Route Types #
RoouteBuilder supports multiple route types:
| Type | Description |
|---|---|
material |
Standard MaterialPageRoute transitions. |
cupertino |
Standard CupertinoPageRoute transitions. |
adaptive |
Automatically uses Material or Cupertino based on platform. |
custom |
Fully custom PageRoute (use PageRouteBuilder for complex animations). |
Advantages Over Traditional Routing #
- No more long
switch-caseorif-elsechains. - All routes are strongly-typed.
- Easier to refactor route names without breaking code.
- Fully supports argument passing with type safety.
- Platform-adaptive transitions out-of-the-box.
- Centralized route definition and navigation helpers.
Example Flow #
RoutableAppsetsMyRoutes.launcheras initial route.LauncherScreenwaits 1 second and pushesMyRoutes.home.Homeretrieves any arguments passed from the previous route.- Routes resolve automatically using enum-based mapping.
- You can also create custom transitions with
PageRouteBuilder.
Author #
Ibrahim Khatrii – passionate about clean architecture, Dart, and Flutter. GitHub: https://github.com/IbrahimKhatrii
License #
MIT License – see LICENSE