nav_router 0.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 73

Language: English | 中文简体

nav_router #

flutter最简单/轻量/便捷的路由管理方案,支持各种路由动画,跳转/传参起来非常方便,跳转新页面只需:routePush(NewPage());

开始使用 #

添加依赖 #

dependencies:
  nav_router: any #具体版本自定义(any表示最新)

相关文章更新中..

然后使用flutter packages upgrade来更新flutter的插件包

示例项目 #

example文件夹中有一个非常漂亮的示例项目。看看这个。否则,请继续阅读以启动并运行。

配置 #

  • 1.在MaterialApp的页面先导入我们的插件
import 'package:nav_router/nav_router.dart';
  • 2.在MaterialAppnavigatorKey属性写上navGK
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: '',
      navigatorKey: navGK,
    );
  }
  • 3.然后,我们就可以开始使用啦,下面是一个跳转页面的例子
Widget buildItem(RouteModel item) {
  return new FlatButton(
    onPressed: () => routePush(new NewPage()),
    child: new Text('点击跳转'),
  );
} 
  • 4.如果我们想用其他路由动画跳转可以在后面添加跳转属性,比如:渐变动画
routePush(new NewPage(), RouterType.fade);

参数传递 #

方式1: #

正常push新页面,但是在后面加上Then,后面的v就是我们跳转之后的页面带回来的数据,然后我们给它打印出来。

routePush(NewPage()).then((v) {
  print('I received::$v');
});

那么我们新页面就要pop返回值了,直接在pop然后括号里加上我们的参数,可以是任何类型的参数值,之后上面写的东西就能接收到我们这次返回并带过去的参数了。

FlatButton(
  onPressed: () {
    pop('This is the parameter');
  },
  child: Text('Return with parameters'),
),

方式2: #

方式二可以用我们的NavData,先在我们要push到的页面添加NavData类型的参数接收,

class NewPage extends StatlessWidget {
  final NavData navData;

  NewPage({this.navData});
}

然后下面就判断这个navData是否为空,也就是上级是否有接收这个方法,如果有的话就带参数返回。

FlatButton(
  onPressed: () {
    if(navData == null) return;
    widget.navData('NavData mode parameter transmission');
    pop();
  },
  child: Text('Return with parameters'),
),

那么我们push的那个地方就可以用navData来接收值并且打印出来了。

routePush(NewPage(navData: (v) {
    print('I received::$v');
  }),
);

效果图 #

1.gif2.gif3.gif
4.gif5.gif6.gif
7.gif8.gif9.gif

Flutter微信群 #

Flutter教程网:www.flutterj.com

Flutter交流QQ群:874592746

公众号 #

关注公众号“Flutter前线”,各种Flutter项目实战经验技巧,干活知识,Flutter面试题答案,等你来领取。

贡献者 #

0.0.1 #

  • TODO: Describe initial release.

0.0.2 #

  • add example

example/README.md

nav_router_example #

Demonstrates how to use the nav_router plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  nav_router: ^0.0.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:nav_router/nav_router.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
52
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
84
Overall:
Weighted score of the above. [more]
73
Learn more about scoring.

We analyzed this package on Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health suggestions

Format lib/advanced/advance_slide.dart.

Run flutter format to format lib/advanced/advance_slide.dart.

Format lib/all_routes.dart.

Run flutter format to format lib/all_routes.dart.

Format lib/routers/fade.dart.

Run flutter format to format lib/routers/fade.dart.

Fix additional 6 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/routers/rotation.dart (Run flutter format to format lib/routers/rotation.dart.)
  • lib/routers/scale.dart (Run flutter format to format lib/routers/scale.dart.)
  • lib/routers/scale_rotate.dart (Run flutter format to format lib/routers/scale_rotate.dart.)
  • lib/routers/size.dart (Run flutter format to format lib/routers/size.dart.)
  • lib/routers/slide.dart (Run flutter format to format lib/routers/slide.dart.)
  • lib/src/common_advance.dart (Run flutter format to format lib/src/common_advance.dart.)

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Update README.md. (-6 points)

3 image links are insecure (e.g. http://www.flutterj.com/content/uploadfile/201903/64821551854137.png), use https URLs instead.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test