Skip to content

Commit

Permalink
Merge pull request #4 from melWiss/replace-routes
Browse files Browse the repository at this point in the history
added replaceRoutes
  • Loading branch information
melWiss authored Oct 15, 2024
2 parents 77eb189 + 880d816 commit 79c59a2
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 106 deletions.
3 changes: 3 additions & 0 deletions eazy_router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.0.2
* Added replaceRoutes method

## 0.0.1

* Added a code generator
Expand Down
10 changes: 10 additions & 0 deletions eazy_router/lib/src/navigator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ abstract class IEazyRouterHandler with ChangeNotifier {
Map<String, EazyRoute Function(Map<String, String> params)> routes);
void push(EazyRoute route);
void pushRoutes(List<EazyRoute> routes);
void replaceRoutes(List<EazyRoute> routes);
void pop({int times = 1});
void removeRoute(EazyRoute route, {bool notifyRootWidget = false});
void removeRouteByName(String name, {bool notifyRootWidget = false});
Expand Down Expand Up @@ -46,6 +47,12 @@ class EazyRouterHandler extends IEazyRouterHandler {
notifyListeners();
}

@override
void replaceRoutes(List<EazyRoute> routes) {
_state = routes;
notifyListeners();
}

@override
void pop({int times = 1}) {
_state.removeRange(_state.length - times, _state.length);
Expand Down Expand Up @@ -205,6 +212,8 @@ extension EazyRouterNavigatorContext on BuildContext {
void push(EazyRoute route) => _navigatorHandler.push(route);
void pushRoutes(List<EazyRoute> routes) =>
_navigatorHandler.pushRoutes(routes);
void replaceRoutes(List<EazyRoute> routes) =>
_navigatorHandler.replaceRoutes(routes);
void pop({int times = 1}) => _navigatorHandler.pop(times: times);
void removeRoute(EazyRoute route, {bool notifyRootWidget = false}) =>
_navigatorHandler.removeRoute(route, notifyRootWidget: notifyRootWidget);
Expand All @@ -217,6 +226,7 @@ extension EazyRouterNavigatorContext on BuildContext {
_navigatorHandler.popUntilTrue(predicate);
bool hasRoute(String name) => _navigatorHandler.hasRoute(name);
List<EazyRoute> get routeSack => _navigatorHandler.routeStack;
IEazyRouterHandler get router => _navigatorHandler;
}

abstract class EazyRoute {
Expand Down
39 changes: 1 addition & 38 deletions eazy_router/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: eazy_router
description: "A flexible and easy-to-use navigation package for Flutter that leverages code generation to simplify route management"
version: 0.0.1
version: 0.0.3
homepage: https://github.com/melWiss/eazy_router

environment:
Expand All @@ -19,40 +19,3 @@ dev_dependencies:
flutter_lints: ^4.0.0
integration_test:
sdk: flutter

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter packages.
flutter:

# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.dev/to/asset-from-package
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/to/resolution-aware-images

# To add custom fonts to your package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.dev/to/font-from-package
40 changes: 1 addition & 39 deletions eazy_router_generator/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: eazy_router_generator
description: "The code generator of eazy_router package."
version: 0.0.1
version: 0.0.3
homepage: https://github.com/melWiss/eazy_router

environment:
Expand All @@ -20,41 +20,3 @@ dependencies:
dev_dependencies:
flutter_lints: ^3.0.0
build_runner:


# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter packages.
flutter:

# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.dev/assets-and-images/#from-packages
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware

# To add custom fonts to your package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.dev/custom-fonts/#from-packages
2 changes: 1 addition & 1 deletion full_example/lib/main.routes.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion full_example/lib/src/home.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:eazy_router_annotation/eazy_router_annotation.dart';
import 'package:flutter/material.dart';
import 'package:full_example/src/second.dart';
import 'package:full_example/src/third.dart';
import 'package:eazy_router/eazy_router.dart';
import 'package:eazy_router_annotation/eazy_router_annotation.dart';

part 'home.g.dart';

Expand Down
2 changes: 1 addition & 1 deletion full_example/lib/src/second.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:eazy_router_annotation/eazy_router_annotation.dart';
import 'package:flutter/material.dart';
import 'package:full_example/src/third.dart';
import 'package:eazy_router/eazy_router.dart';
import 'package:eazy_router_annotation/eazy_router_annotation.dart';

part 'second.g.dart';

Expand Down
9 changes: 8 additions & 1 deletion full_example/lib/src/third.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:eazy_router_annotation/eazy_router_annotation.dart';
import 'package:flutter/material.dart';
import 'package:full_example/src/home.dart';
import 'package:full_example/src/second.dart';
import 'package:eazy_router/eazy_router.dart';
import 'package:eazy_router_annotation/eazy_router_annotation.dart';

part 'third.g.dart';

Expand Down Expand Up @@ -50,6 +50,13 @@ class ThirdScaffold extends StatelessWidget {
},
child: const Text('pop two times'),
),
const Divider(),
ElevatedButton(
onPressed: () {
context.replaceRoutes(context.routeSack.reversed.toList());
},
child: const Text('replace routes => /third/second/home'),
),
],
),
),
Expand Down
58 changes: 36 additions & 22 deletions full_example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@ packages:
dependency: transitive
description:
name: _fe_analyzer_shared
sha256: "0b2f2bd91ba804e53a61d757b986f89f1f9eaed5b11e4b2f5a2468d86d6c9fc7"
sha256: f256b0c0ba6c7577c15e2e4e114755640a875e885099367bf6e012b19314c834
url: "https://pub.dev"
source: hosted
version: "67.0.0"
version: "72.0.0"
_macros:
dependency: transitive
description: dart
source: sdk
version: "0.3.2"
analyzer:
dependency: transitive
description:
name: analyzer
sha256: "37577842a27e4338429a1cbc32679d508836510b056f1eedf0c8d20e39c1383d"
sha256: b652861553cd3990d8ed361f7979dc6d7053a9ac8843fa73820ab68ce5410139
url: "https://pub.dev"
source: hosted
version: "6.4.1"
version: "6.7.0"
args:
dependency: transitive
description:
Expand Down Expand Up @@ -77,18 +82,18 @@ packages:
dependency: "direct dev"
description:
name: build_runner
sha256: "644dc98a0f179b872f612d3eb627924b578897c629788e858157fa5e704ca0c7"
sha256: "028819cfb90051c6b5440c7e574d1896f8037e3c96cf17aaeb054c9311cfbf4d"
url: "https://pub.dev"
source: hosted
version: "2.4.11"
version: "2.4.13"
build_runner_core:
dependency: transitive
description:
name: build_runner_core
sha256: e3c79f69a64bdfcd8a776a3c28db4eb6e3fb5356d013ae5eb2e52007706d5dbe
sha256: f8126682b87a7282a339b871298cc12009cb67109cfa1614d6436fb0289193e0
url: "https://pub.dev"
source: hosted
version: "7.3.1"
version: "7.3.2"
built_collection:
dependency: transitive
description:
Expand Down Expand Up @@ -173,31 +178,32 @@ packages:
dependency: transitive
description:
name: dart_style
sha256: "99e066ce75c89d6b29903d788a7bb9369cf754f7b24bf70bf4b6d6d6b26853b9"
sha256: "7856d364b589d1f08986e140938578ed36ed948581fbc3bc9aef1805039ac5ab"
url: "https://pub.dev"
source: hosted
version: "2.3.6"
version: "2.3.7"
eazy_router:
dependency: "direct main"
description:
path: "../eazy_router"
relative: true
source: path
version: "0.0.1"
version: "0.0.3"
eazy_router_annotation:
dependency: "direct main"
description:
path: "../eazy_router_annotation"
relative: true
source: path
name: eazy_router_annotation
sha256: "2829baaa33ebb34943ea6a43945e677eb57541b7ea54369a6dc5cb8217c5af71"
url: "https://pub.dev"
source: hosted
version: "0.0.1"
eazy_router_generator:
dependency: "direct dev"
description:
path: "../eazy_router_generator"
relative: true
source: path
version: "0.0.1"
version: "0.0.3"
fake_async:
dependency: transitive
description:
Expand All @@ -210,10 +216,10 @@ packages:
dependency: transitive
description:
name: file
sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c"
sha256: a3b4f84adafef897088c160faf7dfffb7696046cb13ae90b508c2cbc95d3b8d4
url: "https://pub.dev"
source: hosted
version: "7.0.0"
version: "7.0.1"
fixnum:
dependency: transitive
description:
Expand Down Expand Up @@ -344,6 +350,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.0"
macros:
dependency: transitive
description:
name: macros
sha256: "0acaed5d6b7eab89f63350bccd82119e6c602df0f391260d0e32b5e23db79536"
url: "https://pub.dev"
source: hosted
version: "0.1.2-main.4"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -372,10 +386,10 @@ packages:
dependency: transitive
description:
name: mime
sha256: "801fd0b26f14a4a58ccb09d5892c3fbdeff209594300a542492cf13fba9d247a"
sha256: "41a20518f0cb1256669420fdba0cd90d21561e560ac240f26ef8322e45bb7ed6"
url: "https://pub.dev"
source: hosted
version: "1.0.6"
version: "2.0.0"
nested:
dependency: transitive
description:
Expand Down Expand Up @@ -569,10 +583,10 @@ packages:
dependency: transitive
description:
name: web
sha256: d43c1d6b787bf0afad444700ae7f4db8827f701bc61c255ac8d328c6f4d52062
sha256: cd3543bd5798f6ad290ea73d210f423502e71900302dde696f8bff84bf89a1cb
url: "https://pub.dev"
source: hosted
version: "1.0.0"
version: "1.1.0"
web_socket:
dependency: transitive
description:
Expand All @@ -598,5 +612,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.4.3 <4.0.0"
dart: ">=3.5.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
8 changes: 5 additions & 3 deletions full_example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.0+1
version: 1.0.2

environment:
sdk: '>=3.4.3 <4.0.0'
Expand All @@ -30,7 +30,8 @@ environment:
dependencies:
flutter:
sdk: flutter
eazy_router: ^0.0.1
eazy_router:
path: ../eazy_router
eazy_router_annotation: ^0.0.1


Expand All @@ -42,7 +43,8 @@ dev_dependencies:
flutter_test:
sdk: flutter
build_runner:
eazy_router_generator: ^0.0.1
eazy_router_generator:
path: ../eazy_router_generator

# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
Expand Down

0 comments on commit 79c59a2

Please sign in to comment.