veno_router

Creator: coderz1093

Last updated:

0 purchases

TODO
Add to Cart

Description:

veno router

一个 Flutter 路由.

特性 #

嵌套路由
路径参数[:*]
Query String

快速开始 #
定义路由
router.dart
import 'package:flutter/material.dart';
import 'package:veno_router/veno_router.dart';

import 'parent_view.dart';
import 'child_ciew.dart';

final router = VenoRouter(routes: [
VenoRoute(
path: '/',
builder: (_, Widget child, VenoRoute route) => ParentView(child: child, route: route),
children: [
VenoRoute(
path: '/products/:id',
builder: (_, Widget child, VenoRoute route) => ChildView(child: child, route: route),
),
],
),
]);
copied to clipboard
注册 onGenerateRoute routeFactory
main.dart
import 'package:flutter/material.dart';
import 'router.dart';

void main() {
runApp(MaterialApp(
onGenerateRoute: router.routeFactory(),
));
}
copied to clipboard
例子 #
import 'package:flutter/material.dart';
import 'package:veno_router/veno_router.dart';

class ParentView extends StatelessWidget {
Widget child;

ParentView({Key key, this.child}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Wrap(
children: [
Text('公共'),
child ??
OutlineButton(
onPressed: () =>
Navigator.of(context).pushNamed('/products/1'),
child: Text('子页面'),
),
],
),
),
);
}
}

class ChildView extends StatelessWidget {
VenoRoute route;

ChildView({Key key, this.route}) : super(key: key);

@override
Widget build(BuildContext context) {
return OutlineButton(
onPressed: () => Navigator.of(context).pop(),
child: Text('${route.params} 返回父页面'),
);
}
}

class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
onGenerateRoute: VenoRouter(routes: [
VenoRoute(
path: '/',
builder: (_, child, __) => ParentView(child: child),
children: [
VenoRoute(
path: '/products/:id',
builder: (_, __, VenoRoute route) => ChildView(route: route),
),
],
),
]).routeFactory(),
);
}
}

void main() {
runApp(App());
}
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.