ui_router 2.0.0 ui_router: ^2.0.0 copied to clipboard
Simple Router for Pages, Dialogs, Loading tasks. Powerful functions, interfaces will support your app.
import 'package:flutter/material.dart';
import 'package:ui_router/ui_router.dart';
final router = UiRouter(
pages: {
'/a': (params) => PageA(),
'/b': (params) => PageB(),
},
);
void main() {
final widget = UiRouterWidget(router);
final app = MaterialApp(home: widget);
runApp(app);
}
//
// Page A
//
class PageA extends StatelessWidget {
push() {
router.push('/b');
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Page A')),
body: ElevatedButton(onPressed: push, child: Text('Push To B')),
);
}
}
//
// Page B
//
class PageB extends StatelessWidget {
pop() {
router.pop();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Page B')),
body: ElevatedButton(onPressed: pop, child: Text('Pop To A')),
);
}
}