Skip to content

Commit

Permalink
Merge pull request #52 from nubank/readme-fix
Browse files Browse the repository at this point in the history
Fix Readme to be compliant with latest 0.7 changes
  • Loading branch information
leoiacovini authored Oct 21, 2020
2 parents a09b4cb + e4c747d commit d8c9cde
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 0.7.1
- Update README
- Update pubspec.yaml to support analyzer up to version `0.41.0`

## 0.7.0
- [BREAKING] Rename classes to avoid conflicts with Flutter 1.22 Router Widget
- `Router` was renamed to `NuRouter`
Expand Down
45 changes: 22 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Routing and Navigation package.
## What

Nuvigator provides a powerful routing abstraction over Flutter's own Navigators. Model complex navigation flows using a mostly
declarative and concise approach, without needing to worry about several tricky behaviours that Nuvigator handles for you.
declarative and concise approach, without needing to worry about several tricky behaviors that Nuvigator handles for you.

## Main Concepts

Expand All @@ -27,8 +27,8 @@ class MyScreen extends StatelessWidget {
}
@NuRouter()
class MainRouter extends Router {
@nuRouter
class MainRouter extends NuRouter {
@NuRoute()
ScreenRoute myRoute() => ScreenRoute(
Expand Down Expand Up @@ -59,7 +59,7 @@ class MyApp extends StatelessWidget {
```

## Nuvigator and Router
## Nuvigator and NuRouter

`Nuvigator` is a custom `Navigator`. It behaves just like a normal `Navigator`, but has several custom improvements and
features. It is engineered specially to work under nested scenarios, where you can have several Flows one inside another.
Expand All @@ -69,8 +69,8 @@ navigation, and it can be easily fetched from the context, just like a normal `N
Nuvigator includes several extra methods, like `Nuvigator.of(context).openDeepLink()` that tries to open the desired deep link.
Another example is `Nuvigator.of(context).closeFlow()` that tries to close all screens of a nested Nuvigator.

Each `Nuvigator` should have a `Router`. The `Router` acts as a routing controller. A `Nuvigator` is responsible for
visualization, widget rendering and state keeping. A Router is a Pure class that is responsible for providing elements to
Each `Nuvigator` should have a `NuRouter`. The `NuRouter` acts as a routing controller. A `Nuvigator` is responsible for
visualization, widget rendering and state keeping. A NuRouter is a Pure class that is responsible for providing elements to
be presented and managed by the Nuvigator.

## ScreenRoute
Expand All @@ -91,8 +91,8 @@ A `ScreenRoute` may return another `Nuvigator`. This is useful for defining a ne

## Creating Routers

Defining a new Router is probably be the what you will do the most when working with Nuvigator, so understanding how
to do it properly is important. A Router class is a class that extends a `Router` and is annotated with the `@NuRouter` annotation.
Defining a new NuRouter is probably be the what you will do the most when working with Nuvigator, so understanding how
to do it properly is important. A NuRouter class is a class that extends a `NuRouter` and is annotated with the `@nuRouter` annotation.

### Defining Routes

Expand All @@ -102,8 +102,8 @@ the Arguments that can be passed to your route when navigating to it.

Example:
```dart
@NuRouter()
class MyCustomRouter extends Router {
@nuRouter
class MyCustomRouter extends NuRouter {
@NuRoute()
ScreenRoute firstScreen({String argumentHere}) => ScreenRoute(
Expand Down Expand Up @@ -132,8 +132,7 @@ types natively for parameters in a deep link:
- DateTime (`?date=2020-10-01`, `?date=2020-10-01T15:32:09.123Z`)
- String (`?name=Jane+Doe`)

Any of these **can be null** if you try to open a deep link without specifing them **or if they fail to parse** (e.g. `falseee` as
a bool outputs `null`).
Any of these **can be null** if you try to open a deep link without specifying them **or if they fail to parse** (e.g. `false` as a bool outputs `null`).

If you create a Route that takes an argument of a different type and it has a deep link, Nuvigator's code generation tool will issue
a warning about it. This is because, when decoding something that is not declared as one of these types, the result **will be a String**.
Expand Down Expand Up @@ -164,10 +163,10 @@ annotation.

Example:
```dart
@NuRouter()
class MyCustomRouter extends Router {
@nuRouter
class MyCustomRouter extends NuRouter {
@NuRouter()
@nuRouter
MyOtherRouter myOtherRouter = MyOtherRouter();
@override
Expand All @@ -179,36 +178,36 @@ class MyCustomRouter extends Router {

### Router Options

When extending from the `Router` you can override the following properties to add custom behaviors to your routes:
When extending from the `NuRouter` you can override the following properties to add custom behaviors to your routes:

- `deepLinkPrefix`:
A `Future<String>`, that is used as prefix for the deep links declared on each route, and also for the grouped routers.

- `screensWrapper`:
A function to wrap each route presented by this router. Should return a new Widget that wraps this child Widget.
The Wrapper is applied to all Screens in this Router. This function runs one time for each screen, and not one
time for the entire Router.
The Wrapper is applied to all Screens in this NuRouter. This function runs one time for each screen, and not one
time for the entire NuRouter.

- `routers`
Sub-Routers grouped into this Router.
Sub-Routers grouped into this NuRouter.

## Code Generators

You may have noticed in the examples above that we have methods that will be created by the Nuvigator generator. So while
they don't exists you can just make they return `null` or leave un-implemented.

Before running the generator we recommend being sure that each Router is in a separated file, and also make sure that you
Before running the generator we recommend being sure that each NuRouter is in a separated file, and also make sure that you
have added the `part 'my_custom_router.g.dart';` directive and the required imports (`package:nuvigator/nuvigator.dart` and `package:flutter/widgets.dart`) in your router file.

After running the generator (`flutter pub run build_runner build --delete-conflicting-outputs`), you should notice that
each router file will have its `part-of` file created. Now you can complete the `screensMap` and `routersList` functions
with the generated: `_$myScreensMap(this);` and `_$samplesRoutersList(this);`. Generated code usually follows this pattern
of stripping out the `Router` part of your Router class and using the rest of the name for generated code.
of stripping out the `NuRouter` part of your NuRouter class and using the rest of the name for generated code.

Generated code includes the following features:

- Routes Enum-like class
- Navigation extension methods to Router
- Navigation extension methods to NuRouter
- Typed Arguments classes
- Implementation Methods

Expand Down Expand Up @@ -256,7 +255,7 @@ Nested flows (declared with nested Nuvigators) will also have their generated Na
in the parent Navigation. The same applies for Grouped Routers. Usage eg:

```dart
final router = Router.of<SamplesRouter>(context);
final router = NuRouter.of<SamplesRouter>(context);
await router.sampleOneRouter.toScreenOne(testId: 'From Home');
await router.toSecond(testId: 'From Home');
```
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: nuvigator
description: A powerful and strongly typed routing abstraction over Flutter navigator, providing some new features and an easy way to define routers with code generation.
version: 0.7.0
version: 0.7.1

homepage: https://github.com/nubank/nuvigator

Expand All @@ -13,7 +13,7 @@ dependencies:
build_config: '>=0.2.6 <0.5.0'
code_builder: ^3.2.0
source_gen: '>=0.9.4+4 <0.10.0'
analyzer: '>=0.38.5 <0.40.0'
analyzer: '>=0.38.5 <0.41.0'
dart_style: '>=1.2.9 <1.4.0'
flutter:
sdk: flutter
Expand Down

0 comments on commit d8c9cde

Please sign in to comment.