Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Milad-Akarie/auto_route_library
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: auto_route-v6.3.0
Choose a base ref
...
head repository: Milad-Akarie/auto_route_library
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: auto_route-v6.4.0
Choose a head ref
  • 8 commits
  • 23 files changed
  • 3 contributors

Commits on Apr 18, 2023

  1. update README.md

    Milad-Akarie committed Apr 18, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    871d57f View commit details
  2. Merge pull request #1499 from Milad-Akarie/revert-initial-flag

    Revert initial flag
    Milad-Akarie authored Apr 18, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    51e7f8c View commit details

Commits on Apr 20, 2023

  1. Update AS plugin

    mirland committed Apr 20, 2023
    Copy the full SHA
    a9f40ca View commit details

Commits on Apr 26, 2023

  1. Merge pull request #1505 from mirland/feature/update-plugin

    Update AS plugin
    Milad-Akarie authored Apr 26, 2023
    Copy the full SHA
    ddfa69a View commit details
  2. Update AutoRoute helper

    Milad-Akarie committed Apr 26, 2023
    Copy the full SHA
    425c6b6 View commit details

Commits on Apr 27, 2023

  1. refactor: deprecated initialDeepLink and initialRouts

    feat: Added DeepLinkBuilder to validate or override platform deep-links
    feat: Added Route.data ext to get routeData of auto routes
    docs: Updated docs
    Milad-Akarie committed Apr 27, 2023
    Copy the full SHA
    17c1940 View commit details
  2. feat: Add DeepLinkBuilder to validate or override platform deep-links

    refactor: Deprecate initialDeepLink and initialRoutes
    
    docs: Add Deep-linking docs
    Milad-Akarie committed Apr 27, 2023
    Copy the full SHA
    80dcbb2 View commit details
  3. chore(release): publish packages

     - auto_route@6.4.0
    Milad-Akarie committed Apr 27, 2023
    Copy the full SHA
    6bb80bc View commit details
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,34 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## 2023-04-27

### Changes

---

Packages with breaking changes:

- There are no breaking changes in this release.

Packages with other changes:

- [`auto_route` - `v6.4.0`](#auto_route---v640)
- [`auto_route_generator` - `v6.2.1`](#auto_route_generator---v621)

Packages with dependency updates only:

> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project.
- `auto_route_generator` - `v6.2.1`

---

#### `auto_route` - `v6.4.0`

- **REFACTOR**: deprecated initialDeepLink and initialRouts.


## 2023-04-18

### Changes
132 changes: 107 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -12,7 +12,9 @@

<p align="center">
<a href="https://www.buymeacoffee.com/miladakarie" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" height="30px" width= "108px"></a>
</p>
</p>

---

- [Introduction](#introduction)
- [Installation](#installation)
@@ -28,6 +30,7 @@
- [Using TabBar](#using-tabbar)
- [Finding The Right Router](#finding-the-right-router)
- [Navigating Without Context](#navigating-without-context)
- [Deep Linking](#deep-linking)
- [Declarative Navigation](#declarative-navigation)
- [Working with Paths](#working-with-paths)
- [Route guards](#route-guards)
@@ -177,7 +180,8 @@ class App extends StatelessWidget {

## Generated Routes

A `PageRouteInfo` object will be generated for every declared AutoRoute, These objects hold strongly-typed page arguments which are extracted from the page's default
A `PageRouteInfo` object will be generated for every declared AutoRoute, These objects hold
strongly-typed page arguments which are extracted from the page's default
constructor. Think of them as string path segments on steroids.

```dart
@@ -808,6 +812,58 @@ getIt<AppRouter>().push(...);
use `navigate` instead of `push` and you provide a full hierarchy.
e.g `router.navigate(SecondRoute(children: [SubChild2Route()]))`

## Deep Linking

AutoRoute will automatically handle deep-links coming from the platform, but native platforms
require some setup, see [Deep linking topic](https://docs.flutter.dev/ui/navigation/deep-linking) in
flutter documentation.

### Using Deep-link Builder

Deep link builder is an interceptor for deep-links where you can validate or override deep-links
coming from the platform.

In the following example we will only allow deep-links starting with `/products`

```dart
MaterialApp.router(
routerConfig: _appRouter.config(
deepLinkBuilder: (deepLink){
if(deepLink.path.startsWith('/products'){
// continute with the platfrom link
return deepLink;
}else{
return DeepLink.defaultPath;
// or DeepLink.path('/')
// or DeepLink([HomeRoute()])
}
}
),
)
```

### Deep Linking to None-nested Routes

AutoRoute can build a stack from a linear route list as long as they're ordered properly and can be
matched as prefix.
e.g `/` is a prefix match of `/products`, and `/products` is prefix match of `/products/:id`
so we have a setup that looks something like this:
-- `/`
-- `/products`
-- `/products/:id`

Now receiving this deep-link `/products/123` will add all above routes to the stack, this of-course
requires `includePrefixMatches` to be true in the root config (default is true) or when
using `pushNamed`, `navigateNamed` and `replaceNamed`.

**Things to keep in mind**:

- if a full match can not finally be found no prefix matches will be included.
- Paths that require a full path match => `AutoRoute(path:'path', fullMatch: true)` will not be
included as prefix matches.
- in the above example if `/products/:id` comes before `/products`, `/products` will not be
included.

## Declarative Navigation

To use declarative navigation with auto_route you simply use the `AutoRouter.declarative`
@@ -827,7 +883,7 @@ AutoRouter.declarative(
## Working with Paths

Working with paths in **AutoRoute** is optional because `PageRouteInfo` objects are matched by name
unless pushed as a string using the `initialDeepLink` property in root delegate or `pushNamed`
unless pushed as a string using the `deepLinkBuilder` property in root delegate or `pushNamed`
, `replaceNamed` `navigateNamed` methods.

if you don’t specify a path it’s going to be generated from the page name e.g. `BookListPage` will
@@ -864,20 +920,23 @@ Now writing `/books/1` in the browser will navigate you to `BookDetailsPage` and
extract the `bookId` argument from path and inject it to your widget.

#### Inherited Path Parameters
To inherit a path-parameter from a parent route's path we need to use `@PathParam.inherit` annotation in the child route's constructor e.g let's say we have the following setup

To inherit a path-parameter from a parent route's path we need to use `@PathParam.inherit`
annotation in the child route's constructor e.g let's say we have the following setup

```dart
AutoRoute(
path: '/product/:id',
page: ProductScreen,
page: ProductRoute.page,
children: [
AutoRoute(path: 'review',page: ProductReviewScreen),
AutoRoute(path: 'review',page: ProductReviewRoute.page),
],
),
```

now `ProductReviewScreen` expects a path-param named `id` but, from the above snippet we know that
the path corresponding with it `review` has no path parameters, but we can inherit 'id' form the parent '/product/:id' like follows:
the path corresponding with it `review` has no path parameters, but we can inherit 'id' form the
parent '/product/:id' like follows:

```dart
@RoutePage()
@@ -1001,9 +1060,13 @@ Now we assign our guard to the routes we want to protect.
```dart
AutoRoute(page: ProfileRoute.page, guards: [AuthGuard()]);
```

#### Guarding all stack-routes
You can have all your stack-routes (none-tab-routes) go throuw a global guard by having your Router implement an AutoRouteGuard.
let's say you have an App with no publish screens, we'd have a global guard that only allows navigation if the user is authenticated or if we're navigating to the LoginRoute.

You can have all your stack-routes (none-tab-routes) go through a global guard by having your Router
implement an AutoRouteGuard.
let's say you have an App with no publish screens, we'd have a global guard that only allows
navigation if the user is authenticated or if we're navigating to the LoginRoute.

```dart
@AutoRouterConfig()
@@ -1248,8 +1311,12 @@ CustomRoute(page: CustomPage, customRouteBuilder:
```

## Others

### Optimizing generation time
To pass builder configuration to auto_route_generator we need to add build.yaml file next to pubspec.yaml if not already added.

To pass builder configuration to auto_route_generator we need to add build.yaml file next to
pubspec.yaml if not already added.

```yaml
targets:
$default:
@@ -1259,19 +1326,25 @@ targets:
auto_route_generator:auto_router_generator:
# configs for @AutoRouterConfig() generator ...
```
The first thing you want to do to reduce generation time is specifying the files build_runner should process and we do that by using [globs](https://pub.dev/packages/glob), Globs are kind of regex patterns with little differences that's used to match file names.

The first thing you want to do to reduce generation time is specifying the files build_runner should
process and we do that by using [globs](https://pub.dev/packages/glob), Globs are kind of regex
patterns with little differences that's used to match file names.
**Note** for this to work on file level you need to follow a naming convention

let's say we have the following files tree
├── lib
│ ├── none_widget_file.dart
│ ├── none_widget_file2.dart
│ └── ui
│ ├── products_screen.dart
│ ├── products_details_screen.dart

By default the builder will process all of these files to check for a page with `@RoutePage()` annotation, we can help by letting it know what files we need processed, e.g only process the files inside the ui folder:
│ ├── none_widget_file.dart
│ ├── none_widget_file2.dart
│ └── ui
│ ├── products_screen.dart
│ ├── products_details_screen.dart

By default the builder will process all of these files to check for a page with `@RoutePage()`
annotation, we can help by letting it know what files we need processed, e.g only process the files
inside the ui folder:
**Note** (**) matches everything including '/';

```yaml
targets:
$default:
@@ -1280,7 +1353,10 @@ targets:
generate_for:
- lib/ui/**.dart
```
let's say you have widget files inside of the ui folder but we only need to process files ending with `_screen.dart`

let's say you have widget files inside of the ui folder but we only need to process files ending
with `_screen.dart`

```yaml
targets:
$default:
@@ -1289,24 +1365,29 @@ targets:
generate_for:
- lib/ui/**_screen.dart
```

now only `products_screen.dart`, `products_details_screen.dart` will be processed

The same goes for `@AutoRouterConfig` builder

```yaml
targets:
$default:
builders:
auto_route_generator:auto_route_generator: # this for @RoutePage
generate_for:
generate_for:
- lib/ui/**_screen.dart
auto_route_generator:auto_router_generator: # this for @AutoRouterConfig
generate_for:
- lib/ui/router.dart
```

## Enabling cached builds

**This is still experimental**
When cached builds are enabled auto_route will try to prevent redundant re-builds by analyzing whether the file changes has any effect on the extracted route info, e.g any changes inside of the build method should be ignored.
When cached builds are enabled auto_route will try to prevent redundant re-builds by analyzing
whether the file changes has any effect on the extracted route info, e.g any changes inside of the
build method should be ignored.

**Note** Enable cached builds on both generators

@@ -1315,12 +1396,12 @@ targets:
$default:
builders:
auto_route_generator:auto_route_generator: # this for @RoutePage
options:
options:
enable_cached_builds: true
generate_for:
generate_for:
- lib/ui/**_screen.dart
auto_route_generator:auto_router_generator: # this for @AutoRouterConfig
options:
options:
enable_cached_builds: true
generate_for:
- lib/ui/router.dart
@@ -1382,7 +1463,8 @@ MaterialApp.router(
In version 6.0 auto_route aims for less generated code for more flexibility and less generation
time.

**Note: You can use [AutoRoute-helper](https://plugins.jetbrains.com/plugin/21071-autoroute-helper) plugin for Android studio to help you migrate to v6.0**
**Note: You can use [AutoRoute-helper](https://plugins.jetbrains.com/plugin/21071-autoroute-helper)
plugin for Android studio to help you migrate to v6.0**

<img src="https://raw.githubusercontent.com/Milad-Akarie/auto_route_library/v6.0.0_redesigned/tools/demo/migrate_to_v6_demo.gif" alt="add route from intent action" width= "px"></a>
1- Instead of using `MaterialAutoRouter`,`CupertinoAutoRouter` ...etc we now only have one
5 changes: 4 additions & 1 deletion auto_route/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## 6.4.0

- **REFACTOR**: deprecated initialDeepLink and initialRouts.

## 6.3.0

- **REFACTOR**: make AutoRouterState and AutoTabsRouterState public.
- **FEAT**: Bring AutoRoute.initial back.

## 6.2.1
14 changes: 14 additions & 0 deletions auto_route/lib/src/common/auto_route_observer.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/widgets.dart';

/// Adds auto-route data getter
/// to [Route]
extension RouteX<T> on Route<T> {
/// Returns RouteData of this page if
/// it's an [AutoRoutePage] otherwise it
/// returns null
RouteData? get data {
if (settings is AutoRoutePage) {
return (settings as AutoRoutePage).routeData;
}
return null;
}
}

/// An extended version of [NavigatorObserver] to support
/// Tab-int and tab-change events observation
class AutoRouterObserver extends NavigatorObserver {
Loading