r_router 1.0.0 copy "r_router: ^1.0.0" to clipboard
r_router: ^1.0.0 copied to clipboard

outdated

A Flutter router package,you can not need use context to navigate.

r_router #

pub package

A Flutter router package,you can not need use context to navigate, support dialog/Path RegEx/navigate custom transaction/Navigator 2.0

中文点此 #

1.Getting Started. #

  • use plugin: add this code in pubspec.yaml
dependencies:
  r_router: last version
  • add the packages to your file.
import 'package:r_router/r_router.dart';

2.Simple use #

  • register router
/// [path] your router path.
/// [handler] handler Widget((ctx) => PageOne()))
/// [PageOne] your page.
/// [ctx] request data.
RRouter.addRoute(NavigatorRoute('/one', (ctx) => PageOne()));
  • Navigator 1.0: add the route in app.
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      // add new
      navigatorObservers: [
        RRouter.observer,
      ],
      // add new
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}
  • Navigator 2.0: add the route in app.
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      routerDelegate: RRouter.delegate,
      routeInformationParser: RRouter.informationParser,
    );
  }
}
  • navigate to it.
    /// [path] you register path.
    /// [body] you want to give [path] arguments.
    /// [replace] will replace route
    /// [clearTrace] will clear all route and push [path].
    /// [isSingleTop] if [path] is top,There was no response.
    /// [pageTransitions] you navigate transition , if null will use default page transitions builder.
     RRouter.navigateTo('/one');

3.Register router #


/// set error page.
  RRouter.setErrorPage(ErrorPageWrapper(
      error: (BuildContext context, FlutterErrorDetails flutterErrorDetails) =>
          Center(
            child: Text(
              'Exception Page (${flutterErrorDetails.exceptionAsString()})',
            ),
          ),
      notFound: (BuildContext context, Context ctx) => Material(
            child: Center(
              child: Text('Page Not found:${ctx.path}'),
            ),
          )));

/// set page build transform ,default platform page transitions
RRouter.addRoute(NavigatorRoute('/three', (ctx) => PageThree(),
    defaultPageTransaction: CupertinoPageTransitionsBuilder()))

5. Not context show dialog #

support as follows method

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

6.Default Navigator #

you can use

RRouter.navigator

7.Add Interceptor #

  RRouter.addInterceptor((ctx) async {
    if (ctx.path == '/other') {
      RRouter.navigateTo('/five', body: ctx.body);
      return true;
    }
    return false;
  });

8. you can use (/user/:id) or (/user/*) registe route path. #

  RRouter.addRoute(NavigatorRoute('/five/:id', (ctx) => PageFive(id:ctx.pathParams.getInt('id'))));
  RRouter.addRoute(NavigatorRoute('/five/*', (ctx) => PageFive()));

9. BuildContext get ctx #

    Context ctx = context.readCtx;
5
likes
0
pub points
41%
popularity

Publisher

verified publisherrhyme95.cn

A Flutter router package,you can not need use context to navigate.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, path_tree

More

Packages that depend on r_router