digita_router 0.1.0
digita_router: ^0.1.0 copied to clipboard
A lightweight, context-free Flutter navigation package. Navigate without BuildContext—ideal for MVVM, BLoC, Riverpod, or plain Flutter.
example/main.dart
import 'package:flutter/material.dart';
import 'package:digita_router/digita_router.dart';
void main() {
runApp(MyApp());
}
/// The root widget of the app.
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
// Required: attach Digita's navigatorKey to MaterialApp.
navigatorKey: digita.navigatorKey,
routes: {
'/': (_) => HomePage(),
'/details': (_) => DetailsPage(),
},
);
}
}
/// The home page with a button to navigate to the details page.
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Home')),
body: Center(
child: ElevatedButton(
// Navigate to the named route '/details' without using context.
onPressed: () {
digita.goToNamed('/details');
},
child: const Text('View Details'),
),
),
);
}
}
/// The details page with a button to go back.
class DetailsPage extends StatelessWidget {
const DetailsPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Details')),
body: Center(
child: ElevatedButton(
// Go back to the previous screen without context.
onPressed: () => digita.goBack(),
child: const Text('Go Back'),
),
),
);
}
}