fluent_navigation 0.0.6
fluent_navigation: ^0.0.6 copied to clipboard
Package that provides a simple way to navigate within your app
fluent_navigation #
Package that provides a simple way to navigate within your app
Getting Started #
Add dependencies #
fluent_navigation: ^0.0.5
Create pages #
// Page one (initial)
class PageOne extends StatelessWidget {
const PageOne({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Page one")),
body: Center(
child: Column(
children: [
ElevatedButton(
onPressed: () async {
// Push to registered route two
final result = await Fluent.get<NavigationApi>().pushTo("two");
if (result != null) {
debugPrint("Result: $result");
}
},
child: const Text("Push to second page"),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () {
// Navigate to page two
Fluent.get<NavigationApi>().navigateTo("two");
},
child: const Text("Navigate to second page"),
),
],
),
),
);
}
}
// Page two
class PageTwo extends StatelessWidget {
const PageTwo({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Page two")),
body: Center(
child: ElevatedButton(
onPressed: () {
Fluent.get<NavigationApi>().pop(true);
},
child: const Text("Go back to previous page"),
),
),
);
}
}
Create module and register routes #
class ExampleModule extends FluentModule {
@override
Future<void> build(Registry registry) async {
registry
// Initial route
..registerRoute(const Route(
"one",
"/one",
initial: true,
page: PageOne(),
))
// Second route
..registerRoute(const Route(
"two",
"/two",
page: PageTwo(),
));
}
}
Build module #
void main() async {
await Fluent.build([
NavigationModule(),
ExampleModule(),
]);
runApp(const MainApp());
}
Use it #
class App extends StatelessWidget {
const App({super.key});
@override
Widget build(BuildContext context) {
// Get router config
final config = Fluent.get<NavigationApi>().getConfig();
return MaterialApp.router(
title: "Fluent Navigation Demo",
routerConfig: config,
);
}
}
Example #