美文网首页Flutter圈子Flutter
Flutter自制插件之r_router无需context路由插

Flutter自制插件之r_router无需context路由插

作者: rhyme_lph | 来源:发表于2020-02-08 12:21 被阅读0次

r_router

一个无需使用context导航的Flutter路由插件,支持dialog

.----------------------------------------------

| github地址:

| https://github.com/rhymelph/r_router

| pub地址:

| https://pub.dev/packages/r_router

`----------------------------------------------

1.开始使用.

  • pubspec.yaml文件添加依赖
dependencies:
  r_router: last version
  • 导入包
import 'package:r_router/r_router.dart';

2.简单使用

  • 注册路由
/// [path] 你的路由路径
/// [routerWidgetBuilder] 构建你的页面
/// [params] 你的参数,支持所有类型的值,类型为dynamic
/// [PageOne] 你的部件
RRouter.myRouter.addRouter(
    path: '/one',
    routerWidgetBuilder: (params) => PageOne(title:params["title"]),
  );

  • 添加你的路由到app
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!'});

3.注册路由


/// 注册未找到页面的路由
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))

4. 无需context的展示对话框方法

支持下面的方法

  • showRDialog
  • showRCupertinoDialog
  • showRCupertinoModalPopup
  • showRAboutDialog
  • showRMenu
  • showRTimePicker
  • showRGeneralDialog
  • showRDatePicker
  • showRSearch
  • showRModalBottomSheet
  • showRLicensePage

5.默认的路由器

你可以使用下面代码进行路由跳转

RRouter.navigator

相关文章

网友评论

    本文标题:Flutter自制插件之r_router无需context路由插

    本文链接:https://www.haomeiwen.com/subject/eyqixhtx.html