url_router 0.1.0 url_router: ^0.1.0 copied to clipboard
A new Flutter package.
import 'package:example/widgets.dart';
import 'package:flutter/material.dart';
import 'package:url_router/url_router.dart';
void main() {
runApp(NavTests());
}
class NavTests extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
onGenerateRoute: (settings) {
return PageRouteBuilder(
settings: settings,
pageBuilder: (context, animation1, animation2) {
return Center(child: Text(settings.name ?? 'no-name'));
},
transitionDuration: Duration.zero,
);
return MaterialPageRoute(
fullscreenDialog: true,
settings: settings,
builder: (_) {
return Center(child: Text(settings.name ?? 'no-name'));
});
},
);
}
}
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,
);
}
}