abstract_router 1.0.7

  • Readme
  • Changelog
  • Example
  • Installing
  • 49

Abstract Router #

Version Build Status Coverage

中文文档

The original intention of abstract routing is to implement a simple routing system for mapping URIs to specified handlers and to support binding of middleware to paths. It parses the parameter information, middleware, and processing functions carried by the URI and places it in the context of the RouterContext for the real routing system.

API Documentation on pub.dev

API Documentation on flutter-cn.io

MIT License

Copyright (c) 2019 bullub

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

1.0.7 #

  • Add badges.

1.0.6 #

  • Update the examples display.

1.0.5 #

  • Documentation link in README.

1.0.4 #

  • Remove documentation in github.
  • Modify naming to conform to the dart specification.

1.0.3 #

  • Fix the documentation location.

1.0.2 #

  • Add API documentation.
  • Remove unnecessary exports.

1.0.1 #

  • Add Changelog.
  • Add Examples.

1.0.0 #

  • Complete the routing system.
  • Add Unit tests.

example/lib/main.dart

import 'package:abstract_router/abstract_router.dart';

void main() {
  AbstractRouter router = AbstractRouter();

  router.handle('/user/:id', (RouterContext context) async {
    print('context in handle [/user/:id]  is: ${context}' );
  });

  router.handle('/user/:name/abc', (RouterContext context) async {
    print('context in handle [/user/:name/abc]  is: ${context}' );
  });

  router.use('/user', [middleware1]);
  router.use('/user/:name', [middleware2]);

  print('=======route1=======');

  RouterContext context1 = router.parse('/user/id_is_abcdefg?abc=efg');
  context1.middlewares.forEach((RouteMiddleware middleware) {
    middleware(context1);
  });
  context1.handler(context1);
  print('=======route1 end=======\n');

  print('=======route2=======');
  RouterContext context2 = router.parse('/user/name_is_abcdefg/abc?abc=efg');
  context2.middlewares.forEach((RouteMiddleware middleware) {
    middleware(context2);
  });
  context2.handler(context2);
  print('=======route2 end=======\n');
}

Future<dynamic> middleware1(RouterContext context) async {
  print('context in middleware1: ${context}');
  context.params['middleware1 add some data'] = 'yes';
}

Future<dynamic> middleware2(RouterContext context) async {
  print('context in middleware2: ${context}');
  context.params['middleware2 add some data'] = 'yes';
}

Use this package as a library

1. Depend on it

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


dependencies:
  abstract_router: ^1.0.7

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or 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:abstract_router/abstract_router.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
97
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
49
Learn more about scoring.

We analyzed this package on Oct 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:abstract_router/abstract_router.dart.

Health suggestions

Fix lib/route-tree/route_node.dart. (-2.96 points)

Analysis of lib/route-tree/route_node.dart reported 6 hints, including:

line 41 col 3: Prefer using /// for doc comments.

line 52 col 3: Prefer using /// for doc comments.

line 96 col 3: Prefer using /// for doc comments.

line 204 col 3: Prefer using /// for doc comments.

line 217 col 3: Prefer using /// for doc comments.

Fix lib/route-tree/route_tree.dart. (-0.50 points)

Analysis of lib/route-tree/route_tree.dart reported 1 hint:

line 86 col 3: Prefer using /// for doc comments.

Format lib/abstract_router.dart.

Run dartfmt to format lib/abstract_router.dart.

Format lib/route-tree/types.dart.

Run dartfmt to format lib/route-tree/types.dart.

Format lib/utils/stack.dart.

Run dartfmt to format lib/utils/stack.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.1 <3.0.0
Dev dependencies
pedantic 1.1.0
test ^1.5.1
test_coverage ^0.3.0