一个无需使用context导航的Flutter路由插件,支持dialog .---------------------------------------------- | github地址: | https://github.com/rhymelph/r_router | pub地址: | https://pub.dev/packages/r_router `----------------------------------------------
pubspec.yaml
文件添加依赖dependencies:
r_router: last version
import 'package:r_router/r_router.dart';
/// [path] 你的路由路径
/// [routerWidgetBuilder] 构建你的页面
/// [params] 你的参数,支持所有类型的值,类型为dynamic
/// [PageOne] 你的部件
RRouter.myRouter.addRouter(
path: '/one',
routerWidgetBuilder: (params) => PageOne(title:params["title"]),
);
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
// add new
onGenerateRoute: RRouter.myRouter.routerGenerate,
navigatorObservers: [
RRouter.myRouter.observer,
],
// add new
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
RRouter.myRouter.navigateTo('/one', arguments: {'title': 'hello world!'});
/// 注册未找到页面的路由
RRouter.myRouter.notFoundPage = (String path) => NoFoundPage(
path: path,
);
/// 注册带过渡动画的路由,默认为根据对应平台的过渡动画,ios:CupertinoPageRoute,android:MaterialPageRoute
RRouter.myRouter.addRouter(
path: '/three',
routerWidgetBuilder: (params) => PageThree(),
routerPageBuilder: (RouteSettings setting, WidgetBuilder builder) =>
CupertinoPageRoute(builder: builder, settings: setting))
支持下面的方法
你可以使用下面代码进行路由跳转
RRouter.navigator