A declarative implementation of Flutter's Navigator for easy and clean code.
- Easy to integrate & easy to use
- Uses Flutter's Navigator v2.0
Add this package as a dependency
flutter pub add app_navigator
Import this package in your file
import 'package:app_navigator/app_navigator.dart';
- Init
import 'package:flutter/material.dart';
import 'package:app_navigator/app_navigator.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'AppNavigator Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: NavigationLayer(
initPage: Page1(),
initPath: Page1.route,
),
);
}
}
To navigate between routes, use the AppNavigator.push
method:
onTap() => AppNavigator().push(Page(), name: 'page');
To navigate backward, use the AppNavigator.pop
method:
onTap() => AppNavigator().pop();
To navigate backward to a target page, use AppNavigator.popUntilNamed
onTap() => AppNavigator().popUntilNamed();
The class AppNavigator
by using the singleton pattern allows navigation within the app without care about the context.