url_router 0.1.0+3 url_router: ^0.1.0+3 copied to clipboard
An un-opinionated url-based Router implementation (Navigator 2.0)
import 'package:example/widgets.dart';
import 'package:flutter/material.dart';
import 'package:url_router/url_router.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
MyApp({Key? key}) : super(key: key);
bool get authorized => true;
late final router = UrlRouter(
//TODO: Does this need to be async?
onChanging: (router, newUrl) {
if (authorized == false) return '/';
return newUrl;
},
scaffoldBuilder: (router, navigator) {
return Row(
children: [
const SideBar(),
Expanded(child: navigator),
],
);
},
onGeneratePages: (router) {
return [
MaterialPage(key: ValueKey(router.url), child: const MainView()),
];
},
);
@override
Widget build(BuildContext context) {
return MaterialApp.router(
routeInformationParser: UrlRouteParser(),
routerDelegate: router,
);
}
}