Git Product home page Git Product logo

navigator_manager's Introduction

简介

Navigator 2.0 for app and web. Easy Use!

快速开始

在main.dart文件引入路由管理,并进行路由配置

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _routerDelegate = LRouterDelegate(
    // 配置没有匹配url的页面(app可不配置)
    pageNotFound: (uri, params) => MaterialPage(
      key: ValueKey('not-found-page'),
      child: Builder(
        builder: (context) => Scaffold(
          body: Center(
            child: Text('Page ${uri.path} not found'),
          ),
        ),
      ),
    ),
    // 配置所有路由信息(必填)
    routes: {
      '/': (uri, params) => HomePage(),
      '/test/todo': (uri, params) =>
          TestPage(uri),
      '/result': (uri, params) => ResultPage(),
      '/login': (uri, params) => LoginPage(),
    },
  );

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      title: 'Uri navigator App',
      routerDelegate: _routerDelegate,
      routeInformationParser: LRouteInformationParser(),
    );
  }
}

其中routes字段:

key为url

value为返回页面的函数, uri是路由参数,params是页面参数,根据参数类型传递

方法

1.go(Uri uri, {dynamic params})

路由跳转方法, 支持路由传参和自定义数据类型传参

RouteManager.of(context).go(Uri(path: '/test/todo', queryParameters: {'limit': '12'}));
RouteManager.of(context).go(Uri(path: '/test/todo'), params: your model);

2.replace(Uri uri, {dynamic params})

替换当前路由并跳转

RouteManager.of(context).replace(Uri(path: '/test/todo'));

3.goBack()

返回上一页, 如若返回传参请用returnResultGo

RouteManager.of(context).goBack();

4.clearAndGo(Uri uri, {dynamic params})

清空路由栈并重设首页,如登陆场景

RouteManager.of(context).clearAndGo(Uri(path: '/login'));

5.multipleGo(List<Uri> uris, {List<dynamic> params})

一次设置多个uri并跳转到最后一个路由

RouteManager.of(context).multipleGo([Uri(path: '/test/todo', queryParameters: {'limit': '12'}), Uri(path: '/test/todo')]);

6.clearAndMultipleGo(List<Uri> uris, {List<dynamic> params})

清空路由栈并跳转(设置多个uri)

RouteManager.of(context).clearAndMultipleGo(Uri(path: '/test/todo', queryParameters: {'limit': '12'}));

7.waitResultGo(Uri uri, {dynamic params})

跳转等待结果

RouteManager.of(context).waitResultGo(Uri(path: '/test/todo', queryParameters: {'limit': '12'}));

8.returnResultGo(dynamic value)

跳转返回结果

RouteManager.of(context).returnResultGo(your value);

9.goRoot()

路由栈只保留首页

RouteManager.of(context).goRoot();

10.removeUri(Uri uri)

删除指定路由

RouteManager.of(context).removeUri(Uri(path: '/test/todo'));

11.removeLastUri()

删除栈顶的路由

RouteManager.of(context).removeLastUri();

navigator_manager's People

Contributors

fyt7943tyf avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.