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-v7.9.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-v7.9.1
Choose a head ref
  • 3 commits
  • 10 files changed
  • 1 contributor

Commits on Mar 12, 2024

  1. audit CHANGELOG.md

    Milad-Akarie committed Mar 12, 2024
    Copy the full SHA
    1bc25bd View commit details

Commits on Mar 19, 2024

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    909e793 View commit details
  2. chore(release): publish packages

     - auto_route@7.9.1
    Milad-Akarie committed Mar 19, 2024
    Copy the full SHA
    0de5286 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.

## 2024-03-19

### Changes

---

Packages with breaking changes:

- There are no breaking changes in this release.

Packages with other changes:

- [`auto_route` - `v7.9.1`](#auto_route---v791)
- [`auto_route_generator` - `v7.3.3`](#auto_route_generator---v733)

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` - `v7.3.3`

---

#### `auto_route` - `v7.9.1`

- **FIX**: incorrect top route information when deep-linking into an uninitialized tab route.


## 2024-03-12

### Changes
42 changes: 26 additions & 16 deletions auto_route/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
## 7.9.1

- **FIX**: incorrect top route information when deep-linking into an uninitialized tab route.

## 7.9.0

- **REFACTOR**(example): remove unnecessary pageTransitionsTheme parameter.
- **FIX**: unable to get the label for back button(previous route title) and current route title on CupertinoNavigationBar and CupertinoSliverNavigationBar #1795.
- **FIX**: CupertinoNavigationBar and CupertinoSliverNavigationBar unable to get route title and previous route title.
- **FIX**: docstring typo(RouteData.mete -> RouteData.meta).
- **FIX**: keep TabsRouter.homeIndex in sync with AutoTabsRouter.homeIndex.
- **FEAT**: add back mixin to AutoRouteAware.
- **FIX**: unable to get the label for back button(previous route title) and current route title on
CupertinoNavigationBar and CupertinoSliverNavigationBar #1795.
- **FIX**: CupertinoNavigationBar and CupertinoSliverNavigationBar unable to get route title and
previous route title.
- **Fix**: PopScope.onPopInvoked not called when canPop is set to true,
- **Refactor**: rename router.pop to router.maybePop to avoid confusion
- **Refactor**: rename router.popTop to router.maybePopTop to avoid confusion
- **Refactor**: rename context.popRoute to context.maybePop

## 7.8.5

@@ -34,30 +40,34 @@

## 7.8.0

- **FEAT**: add PlatformDeepLink.initial flag to tell whether we're coming from setInitialRoutePath or setNewRoutePath.
- **FEAT**: add option to pass custom ignore_for_file rules to the generated file.
- **FEAT**: support the new allowSnapshotting flag.
- **FEAT**: add PlatformDeepLink.initial flag to tell whether we're coming from setInitialRoutePath
or setNewRoutePath.
- **FEAT**: add option to pass custom ignore_for_file rules to the generated file.
- **FEAT**: support the new allowSnapshotting flag.

## 7.7.1

- **FIX**: tab routes should be matched by key not name.
- **FIX**: tab routes should be matched by key not name.

## 7.7.0

- **FEAT**: Add basic support to dart records.
- **FIX**: encoded path segments are not decoded in RouteMatch.pathParams
- **FIX**: encoded browser path is checked against a decoded matched path when deciding whether to replace route #1637
- **FIX**: encoded browser path is checked against a decoded matched path when deciding whether to
replace route #1637

## 7.6.0

- **FEAT**: add 'scoped' argument to to StackRouter.removeUntil, if true the predicate will visit all StackRouters in hierarchy.
- **FEAT**: add 'scoped' argument to to StackRouter.popUntil, if true the predicate will visit all StackRouters in hierarchy.
- **FEAT**: add 'scoped' argument to to StackRouter.removeUntil, if true the predicate will visit
all StackRouters in hierarchy.
- **FEAT**: add 'scoped' argument to to StackRouter.popUntil, if true the predicate will visit all
StackRouters in hierarchy.

## 7.5.0

- **FIX**: Uri percent-encoded characters encoded twice #1620.
- **FIX**: delegate missing arguments in auto_route_guard redirect.
- **FEAT**(auto_route): add `AutoPageRouteBuilder.opaque` argument.
- **FIX**: Uri percent-encoded characters encoded twice #1620.
- **FIX**: delegate missing arguments in auto_route_guard redirect.
- **FEAT**(auto_route): add `AutoPageRouteBuilder.opaque` argument.

## 7.4.0

2 changes: 1 addition & 1 deletion auto_route/lib/src/common/auto_route_observer.dart
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ class AutoRouterObserver extends NavigatorObserver {

/// An interface used to mark classes as AutoRouteAware entities
/// usually implemented by widget States
abstract class AutoRouteAware {
mixin class AutoRouteAware {
/// Called when the top route has been popped off, and the current route
/// shows up.
void didPopNext() {}
2 changes: 1 addition & 1 deletion auto_route/lib/src/router/auto_route_page.dart
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import 'package:flutter/material.dart';
/// Creates a RoutePage based on [routeData.type],
/// The decision happens inside of [onCreateRoute]
class AutoRoutePage<T> extends Page<T> {
///
/// The Route Data that's used to build the page
final RouteData routeData;
final Widget _child;

60 changes: 47 additions & 13 deletions auto_route/lib/src/router/controller/routing_controller.dart
Original file line number Diff line number Diff line change
@@ -107,11 +107,10 @@ abstract class RoutingController with ChangeNotifier {
/// if needed rebuild the url
void notifyAll({bool forceUrlRebuild = false}) {
notifyListeners();
if (!isRoot) {
root.notifyListeners();
}
if (forceUrlRebuild || !isRouteDataActive(current)) {
navigationHistory.rebuildUrl();
} else if (!isRoot) {
root.notifyListeners();
}
}

@@ -380,7 +379,7 @@ abstract class RoutingController with ChangeNotifier {
});

/// Takes a state snapshot of the current segments
int get stateHash => const ListEquality().hash(currentSegments);
int get stateHash => const ListEquality().hash(_addedSegments);

/// The Identifier key of this routing controller
LocalKey get key;
@@ -556,6 +555,21 @@ abstract class RoutingController with ChangeNotifier {
return segments;
}

/// this is an indicator for controller state changes,
/// every controller's state is considered updated if it's stateHash or any of it's children's stateHash changes
List<RouteMatch> get _addedSegments {
var currentData = currentChild;
final segments = <RouteMatch>[];
if (currentData != null) {
segments.add(currentData.route);
final childCtrl = _innerControllerOf(currentData.key);
if (childCtrl?.hasEntries == true) {
segments.addAll(childCtrl!._addedSegments);
}
}
return segments;
}

/// Finds match of [path] then returns a route-able entity
PageRouteInfo? buildPageRoute(String? path, {bool includePrefixMatches = true}) {
if (path == null) return null;
@@ -606,11 +620,16 @@ class TabsRouter extends RoutingController {
required this.key,
required RouteData routeData,
this.homeIndex = -1,
required this.preload,
RoutingController? parent})
: matcher = RouteMatcher(routeCollection),
_parent = parent,
_routeData = routeData;

/// Called to preload a page before other navigation events occur
/// if it returns true, the page has been preloaded, otherwise we assume it's already loaded
bool Function(int index) preload;

@override
RouteData get routeData => _routeData;

@@ -646,10 +665,20 @@ class TabsRouter extends RoutingController {
void setActiveIndex(int index, {bool notify = true}) {
assert(index >= 0 && index < _pages.length);
if (_activeIndex != index) {
_previousIndex = _activeIndex;
_activeIndex = index;
if (notify) {
notifyAll();
void setIndex() {
_previousIndex = _activeIndex;
_activeIndex = index;
if (notify) {
notifyAll();
}
}

if (!preload(index)) {
setIndex();
} else {
WidgetsBinding.instance.addPostFrameCallback((_) {
setIndex();
});
}
}
}
@@ -763,20 +792,24 @@ class TabsRouter extends RoutingController {
ctr._markedForDataUpdate = true;
}
}

final data = _createRouteData(mayUpdateRoute, routeData);

_pages[pageToUpdateIndex] = pageBuilder(data);

final hasInitCtrl = _innerControllerOf(mayUpdateRoute.key) != null;

if (_activeIndex != pageToUpdateIndex) {
setActiveIndex(pageToUpdateIndex);
} else if (mayUpdateRoute != routeToBeUpdated) {
notifyAll();
}

var mayUpdateController = _innerControllerOf(mayUpdateRoute.key);
if (mayUpdateController != null) {
final newRoutes = mayUpdateRoute.children ?? const [];
return mayUpdateController._navigateAll(newRoutes, onFailure: onFailure);
if (hasInitCtrl) {
final mayUpdateController = _innerControllerOf(mayUpdateRoute.key);
if (mayUpdateController != null) {
final newRoutes = mayUpdateRoute.children ?? const [];
mayUpdateController._navigateAll(newRoutes, onFailure: onFailure);
}
}
}
_updateSharedPathData(
@@ -1779,6 +1812,7 @@ class NestedStackRouter extends StackRouter {
final initialRoutes = List<RouteMatch>.unmodifiable(
_routeData.pendingChildren,
);

if (managedByWidget) {
pendingRoutesHandler._setPendingRoutes(
initialRoutes.map((e) => e.toPageRouteInfo()).toList(),
54 changes: 43 additions & 11 deletions auto_route/lib/src/router/widgets/auto_page_view.dart
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@ import 'package:auto_route/auto_route.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

import 'eager_page_view.dart';

/// Most of the code here is taking from flutter's [TabView]
class AutoPageView extends StatefulWidget {
/// Default constructor
@@ -58,6 +60,7 @@ class AutoPageViewState extends State<AutoPageView> {
late final TabsRouter _router = widget.router;
late List<Widget> _children;
int _warpUnderwayCount = 0;
final _tabKeys = <int, GlobalKey<KeepAliveTabState>>{};

@override
void initState() {
@@ -87,17 +90,35 @@ class AutoPageViewState extends State<AutoPageView> {
}
}

/// Preload the page at [index]
bool preload(int index) {
final didPreload = _tabKeys[index]?.currentState?.preload() == true;
if (didPreload) {
_updateChildren();
}
return didPreload;
}

void _updateChildren() {
final stack = widget.router.stack;
_children = List.generate(
stack.length,
(index) => KeepAliveTab(
key: ValueKey(index),
key: _tabKeys.putIfAbsent(index, () => GlobalKey()),
initiallyLoaded: _router.activeIndex == index,
page: stack[index],
),
);
}

_disposeInactiveChildren() {
for (int i = 0; i < _tabKeys.length; i++) {
if (i != _router.activeIndex) {
_tabKeys[i]?.currentState?.unloadIfRequired();
}
}
}

Future<void> _warpToCurrentIndex() async {
if (!mounted) return Future<void>.value();

@@ -108,19 +129,16 @@ class AutoPageViewState extends State<AutoPageView> {
if ((_router.activeIndex - previousIndex).abs() == 1) {
_warpUnderwayCount += 1;
if (animatePageTransition) {
await _controller.animateToPage(_router.activeIndex,
duration: duration, curve: Curves.ease);
await _controller.animateToPage(_router.activeIndex, duration: duration, curve: Curves.ease);
} else {
_controller.jumpToPage(_router.activeIndex);
}
_warpUnderwayCount -= 1;
return Future<void>.value();
}
assert((_router.activeIndex - previousIndex).abs() > 1);
final int initialPage = _router.activeIndex > previousIndex
? _router.activeIndex - 1
: _router.activeIndex + 1;

final int initialPage = _router.activeIndex > previousIndex ? _router.activeIndex - 1 : _router.activeIndex + 1;
_disposeInactiveChildren();
setState(() {
_warpUnderwayCount += 1;
_children = List<Widget>.of(_children, growable: false);
@@ -131,8 +149,7 @@ class AutoPageViewState extends State<AutoPageView> {
_controller.jumpToPage(initialPage);

if (animatePageTransition) {
await _controller.animateToPage(_router.activeIndex,
duration: duration, curve: Curves.ease);
await _controller.animateToPage(_router.activeIndex, duration: duration, curve: Curves.ease);
} else {
_controller.jumpToPage(_router.activeIndex);
}
@@ -144,11 +161,24 @@ class AutoPageViewState extends State<AutoPageView> {

// Called when the PageView scrolls
bool _handleScrollNotification(ScrollNotification notification) {
if (notification is ScrollEndNotification) {
_disposeInactiveChildren();
}
if (_warpUnderwayCount > 0) return false;
if (notification.depth != 0) return false;
_warpUnderwayCount += 1;

if (notification is ScrollUpdateNotification) {
_router.setActiveIndex(_controller.page!.round());
final currentPage = _controller.page!.round();
_router.setActiveIndex(currentPage);
final deltaDx = notification.dragDetails?.delta.dx;
if (deltaDx != null) {
if (deltaDx > 0 && currentPage > 0) {
preload(currentPage - 1);
} else if (deltaDx < 0 && currentPage < _children.length) {
preload(currentPage + 1);
}
}
}
_warpUnderwayCount -= 1;
return false;
@@ -158,13 +188,15 @@ class AutoPageViewState extends State<AutoPageView> {
Widget build(BuildContext context) {
return NotificationListener<ScrollNotification>(
onNotification: _handleScrollNotification,
child: PageView(
child: EagerPageView(
scrollDirection: widget.scrollDirection,
dragStartBehavior: widget.dragStartBehavior,
cacheExtent: _children.length,
controller: _controller,
physics: widget.physics == null
? const PageScrollPhysics().applyTo(const ClampingScrollPhysics())
: const PageScrollPhysics().applyTo(widget.physics),
// children: _children,
children: _children,
),
);
Loading