Skip to content

Commit 6e92b49

Browse files
authored
Merge pull request #45 from emanuel-braz/develop
add onRouteNotRegistered callback
2 parents 738ed13 + e61d332 commit 6e92b49

File tree

16 files changed

+188
-82
lines changed

16 files changed

+188
-82
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.12.0
2+
[2022-08-28]
3+
#### Added
4+
- Add OnRouteNotRegistered callback
5+
16
## 0.11.0
27
[2022-08-13]
38
#### Added

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,22 @@
2121
nativeNavigationLogEnabled: true,
2222
pathSeparator: MicroAppPathSeparator.slash // It joins the routes segments using slash "/" automatically
2323
24-
// the [MicroPageTransitionType.platform] is a dynamic transition type,
24+
// The [MicroPageTransitionType.platform] is a dynamic transition type,
2525
// for iOS it will use Cupertino, and for others it will use Material.
26-
pageTransitionType: MicroPageTransitionType.platform
26+
pageTransitionType: MicroPageTransitionType.platform,
27+
28+
// When pushing routes, if the route is not registered, this will be triggered,
29+
// and it will abort the navigation
30+
//
31+
// [onUnknownRoute] will not be dispatched, since the navigation was aborted.
32+
//
33+
// To makes this works, do:
34+
// - Use root navigator(from MaterialApp) call NavigatorInstance.push...() without context
35+
// - Use MicroAppNavigatorWidget as your nested navigators
36+
// - Use RouterGenerator.onGenerateRoute mixin in your custom navigators
37+
onRouteNotRegistered: (route, {arguments, type, context}) {
38+
print('[OnRouteNotRegistered] Route not found: $route, $arguments, $type');
39+
},
2740
)
2841
);
2942
```

example/app2/pubspec.lock

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ packages:
4242
name: collection
4343
url: "https://pub.dartlang.org"
4444
source: hosted
45-
version: "1.15.0"
45+
version: "1.16.0"
4646
dart_log:
4747
dependency: transitive
4848
description:
@@ -70,7 +70,7 @@ packages:
7070
name: fake_async
7171
url: "https://pub.dartlang.org"
7272
source: hosted
73-
version: "1.2.0"
73+
version: "1.3.0"
7474
flutter:
7575
dependency: "direct main"
7676
description: flutter
@@ -89,7 +89,7 @@ packages:
8989
path: "../.."
9090
relative: true
9191
source: path
92-
version: "0.8.0"
92+
version: "0.11.0"
9393
flutter_test:
9494
dependency: "direct dev"
9595
description: flutter
@@ -109,6 +109,13 @@ packages:
109109
url: "https://pub.dartlang.org"
110110
source: hosted
111111
version: "0.12.11"
112+
material_color_utilities:
113+
dependency: transitive
114+
description:
115+
name: material_color_utilities
116+
url: "https://pub.dartlang.org"
117+
source: hosted
118+
version: "0.1.4"
112119
meta:
113120
dependency: transitive
114121
description:
@@ -122,7 +129,7 @@ packages:
122129
name: path
123130
url: "https://pub.dartlang.org"
124131
source: hosted
125-
version: "1.8.0"
132+
version: "1.8.1"
126133
sky_engine:
127134
dependency: transitive
128135
description: flutter
@@ -134,7 +141,7 @@ packages:
134141
name: source_span
135142
url: "https://pub.dartlang.org"
136143
source: hosted
137-
version: "1.8.1"
144+
version: "1.8.2"
138145
stack_trace:
139146
dependency: transitive
140147
description:
@@ -169,21 +176,14 @@ packages:
169176
name: test_api
170177
url: "https://pub.dartlang.org"
171178
source: hosted
172-
version: "0.4.3"
173-
typed_data:
174-
dependency: transitive
175-
description:
176-
name: typed_data
177-
url: "https://pub.dartlang.org"
178-
source: hosted
179-
version: "1.3.0"
179+
version: "0.4.9"
180180
vector_math:
181181
dependency: transitive
182182
description:
183183
name: vector_math
184184
url: "https://pub.dartlang.org"
185185
source: hosted
186-
version: "2.1.1"
186+
version: "2.1.2"
187187
sdks:
188-
dart: ">=2.15.1 <3.0.0"
188+
dart: ">=2.17.0-0 <3.0.0"
189189
flutter: ">=1.17.0"

example/example_host/lib/main.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,19 @@ import 'example_micro_app.dart';
1414
void main() {
1515
// Define micro app configurations here
1616
final isAndroid = Platform.isAndroid;
17-
MicroAppPreferences.update(MicroAppConfig(
17+
MicroAppPreferences.update(
18+
MicroAppConfig(
1819
nativeEventsEnabled: isAndroid,
1920
nativeNavigationCommandEnabled: isAndroid,
2021
nativeNavigationLogEnabled: isAndroid,
21-
pageTransitionType: MicroPageTransitionType.platform));
22+
pageTransitionType: MicroPageTransitionType.platform,
23+
onRouteNotRegistered: (route, {arguments, type, context}) {
24+
// ignore: avoid_print
25+
print(
26+
'CALLBACK:[OnRouteNotRegistered] Route not found: $route, $arguments, $type');
27+
},
28+
),
29+
);
2230

2331
// Listen to navigation events
2432
final internalNavigationSubs =

example/example_host/lib/pages/material_app_page_initial.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,19 +142,23 @@ class _MaterialAppPageInitialState extends State<MaterialAppPageInitial>
142142
},
143143
),
144144
ElevatedButton(
145-
child: const Text('Try open a page that only exists in Native'),
145+
child: const Text(
146+
'Try to open a page that is not registered, OnRouteNotRegistered will be called'),
146147
onPressed: () {
147-
// If `onGenerateRoute.routeNativeOnError` is enabled, when there is no flutter page registered,
148+
// If this route is not registered, and OnRouteNotRegistered is not null, it will be called, and finish the execution here
149+
150+
// If `onGenerateRoute.routeNativeOnError` is enabled, and the route is not registered,
148151
// it will try to open the page in Native(Android/iOS) automatically
149152
context.maNav.pushNamed('only_native_page',
150153
arguments: 'some_arguments');
151154
},
152155
),
153156
ElevatedButton(
154-
child: const Text('Try open Page - not exists'),
157+
child: const Text(
158+
'There is no route on current Navigator, but there is a route on the root Navigator'),
155159
onPressed: () {
156160
context.maNav.pushNamed(Application1Routes()
157-
.pageExample); // There is no [pageExample] inside current MaterialApp
161+
.pageExample); // There is no [pageExample] inside current MaterialApp, but it exists in global MicroPage
158162
},
159163
),
160164
ElevatedButton(

example/example_host/pubspec.lock

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ packages:
4242
name: collection
4343
url: "https://pub.dartlang.org"
4444
source: hosted
45-
version: "1.15.0"
45+
version: "1.16.0"
4646
cupertino_icons:
4747
dependency: "direct main"
4848
description:
@@ -84,7 +84,7 @@ packages:
8484
name: fake_async
8585
url: "https://pub.dartlang.org"
8686
source: hosted
87-
version: "1.2.0"
87+
version: "1.3.0"
8888
flutter:
8989
dependency: "direct main"
9090
description: flutter
@@ -103,7 +103,7 @@ packages:
103103
path: "../.."
104104
relative: true
105105
source: path
106-
version: "0.8.0"
106+
version: "0.11.0"
107107
flutter_test:
108108
dependency: "direct dev"
109109
description: flutter
@@ -123,6 +123,13 @@ packages:
123123
url: "https://pub.dartlang.org"
124124
source: hosted
125125
version: "0.12.11"
126+
material_color_utilities:
127+
dependency: transitive
128+
description:
129+
name: material_color_utilities
130+
url: "https://pub.dartlang.org"
131+
source: hosted
132+
version: "0.1.4"
126133
meta:
127134
dependency: transitive
128135
description:
@@ -136,7 +143,7 @@ packages:
136143
name: path
137144
url: "https://pub.dartlang.org"
138145
source: hosted
139-
version: "1.8.0"
146+
version: "1.8.1"
140147
sky_engine:
141148
dependency: transitive
142149
description: flutter
@@ -148,7 +155,7 @@ packages:
148155
name: source_span
149156
url: "https://pub.dartlang.org"
150157
source: hosted
151-
version: "1.8.1"
158+
version: "1.8.2"
152159
stack_trace:
153160
dependency: transitive
154161
description:
@@ -183,21 +190,14 @@ packages:
183190
name: test_api
184191
url: "https://pub.dartlang.org"
185192
source: hosted
186-
version: "0.4.3"
187-
typed_data:
188-
dependency: transitive
189-
description:
190-
name: typed_data
191-
url: "https://pub.dartlang.org"
192-
source: hosted
193-
version: "1.3.0"
193+
version: "0.4.9"
194194
vector_math:
195195
dependency: transitive
196196
description:
197197
name: vector_math
198198
url: "https://pub.dartlang.org"
199199
source: hosted
200-
version: "2.1.1"
200+
version: "2.1.2"
201201
sdks:
202-
dart: ">=2.15.1 <3.0.0"
202+
dart: ">=2.17.0-0 <3.0.0"
203203
flutter: ">=1.17.0"

example/example_routes/pubspec.lock

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ packages:
4242
name: collection
4343
url: "https://pub.dartlang.org"
4444
source: hosted
45-
version: "1.15.0"
45+
version: "1.16.0"
4646
dart_log:
4747
dependency: transitive
4848
description:
@@ -63,7 +63,7 @@ packages:
6363
name: fake_async
6464
url: "https://pub.dartlang.org"
6565
source: hosted
66-
version: "1.2.0"
66+
version: "1.3.0"
6767
flutter:
6868
dependency: "direct main"
6969
description: flutter
@@ -82,7 +82,7 @@ packages:
8282
path: "../.."
8383
relative: true
8484
source: path
85-
version: "0.8.0"
85+
version: "0.11.0"
8686
flutter_test:
8787
dependency: "direct dev"
8888
description: flutter
@@ -102,6 +102,13 @@ packages:
102102
url: "https://pub.dartlang.org"
103103
source: hosted
104104
version: "0.12.11"
105+
material_color_utilities:
106+
dependency: transitive
107+
description:
108+
name: material_color_utilities
109+
url: "https://pub.dartlang.org"
110+
source: hosted
111+
version: "0.1.4"
105112
meta:
106113
dependency: transitive
107114
description:
@@ -115,7 +122,7 @@ packages:
115122
name: path
116123
url: "https://pub.dartlang.org"
117124
source: hosted
118-
version: "1.8.0"
125+
version: "1.8.1"
119126
sky_engine:
120127
dependency: transitive
121128
description: flutter
@@ -127,7 +134,7 @@ packages:
127134
name: source_span
128135
url: "https://pub.dartlang.org"
129136
source: hosted
130-
version: "1.8.1"
137+
version: "1.8.2"
131138
stack_trace:
132139
dependency: transitive
133140
description:
@@ -162,21 +169,14 @@ packages:
162169
name: test_api
163170
url: "https://pub.dartlang.org"
164171
source: hosted
165-
version: "0.4.3"
166-
typed_data:
167-
dependency: transitive
168-
description:
169-
name: typed_data
170-
url: "https://pub.dartlang.org"
171-
source: hosted
172-
version: "1.3.0"
172+
version: "0.4.9"
173173
vector_math:
174174
dependency: transitive
175175
description:
176176
name: vector_math
177177
url: "https://pub.dartlang.org"
178178
source: hosted
179-
version: "2.1.1"
179+
version: "2.1.2"
180180
sdks:
181-
dart: ">=2.15.1 <3.0.0"
181+
dart: ">=2.17.0-0 <3.0.0"
182182
flutter: ">=1.17.0"

lib/flutter_micro_app.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ export 'src/utils/enums/micro_page_transition_type.dart';
2323
export 'src/utils/extensions/context_extension.dart';
2424
export 'src/utils/extensions/list_extension.dart';
2525
export 'src/utils/mixins/handler_register_mixin.dart';
26+
export 'src/utils/mixins/router_generator_mixin.dart';
2627
export 'src/utils/typedefs.dart';

0 commit comments

Comments
 (0)