@@ -79,7 +79,7 @@ class _NuvigatorInner<T extends INuRouter> extends Navigator {
79
79
_NuvigatorInner ({
80
80
required this .router,
81
81
required String initialDeepLink,
82
- Map <String , Object >? initialArguments,
82
+ Map <String , dynamic >? initialArguments,
83
83
Key ? key,
84
84
List <NavigatorObserver > observers = const [],
85
85
this .screenType = materialScreenType,
@@ -133,7 +133,7 @@ class _NuvigatorInner<T extends INuRouter> extends Navigator {
133
133
class NuvigatorState <T extends INuRouter > extends NavigatorState
134
134
with WidgetsBindingObserver {
135
135
NuvigatorState get rootNuvigator =>
136
- Nuvigator .of (context, rootNuvigator: true ) ?? this ;
136
+ Nuvigator .maybeOf (context, rootNuvigator: true ) ?? this ;
137
137
138
138
List <NuvigatorState > nestedNuvigators = [];
139
139
@@ -174,7 +174,7 @@ class NuvigatorState<T extends INuRouter> extends NavigatorState
174
174
175
175
@override
176
176
void initState () {
177
- parent = Nuvigator .of (context, nullOk : true );
177
+ parent = Nuvigator .maybeOf (context);
178
178
if (isNested) {
179
179
parent! .nestedNuvigators.add (this );
180
180
}
@@ -549,35 +549,49 @@ class Nuvigator<T extends INuRouter?> extends StatelessWidget {
549
549
final List <ObserverBuilder > inheritableObservers;
550
550
final List <NavigatorObserver > observers;
551
551
final Key ? _innerKey;
552
- final Map <String , Object >? initialArguments;
552
+ final Map <String , dynamic >? initialArguments;
553
553
final ShouldRebuildFn ? shouldRebuild;
554
554
555
- /// Fetches a [NuvigatorState] from the current BuildContext.
556
- static NuvigatorState <T >? of <T extends INuRouter >(
555
+ /// Maybe fetches a [NuvigatorState] from the current BuildContext.
556
+ static NuvigatorState <T >? maybeOf <T extends INuRouter >(
557
557
BuildContext context, {
558
558
bool rootNuvigator = false ,
559
- bool nullOk = false ,
560
559
}) {
561
560
if (rootNuvigator) {
562
561
return context.findRootAncestorStateOfType <NuvigatorState <T >>();
563
562
} else {
564
563
final closestNuvigator =
565
564
context.findAncestorStateOfType <NuvigatorState <T >>();
566
565
if (closestNuvigator != null ) return closestNuvigator;
567
- assert (() {
568
- if (! nullOk) {
569
- throw FlutterError (
570
- 'Nuvigator operation requested with a context that does not include a Nuvigator.\n '
571
- 'The context used to push or pop routes from the Nuvigator must be that of a '
572
- 'widget that is a descendant of a Nuvigator widget.'
573
- 'Also check if the provided Router [T] type exists withing a the Nuvigator context.' );
574
- }
575
- return true ;
576
- }());
566
+
577
567
return null ;
578
568
}
579
569
}
580
570
571
+ /// Fetches a [NuvigatorState] from the current BuildContext, or throws an
572
+ /// error if doesn't find it
573
+ static NuvigatorState <T > of <T extends INuRouter >(
574
+ BuildContext context, {
575
+ bool rootNuvigator = false ,
576
+ }) {
577
+ final nuvigatorState =
578
+ Nuvigator .maybeOf <T >(context, rootNuvigator: rootNuvigator);
579
+
580
+ assert (() {
581
+ if (nuvigatorState == null ) {
582
+ throw FlutterError (
583
+ 'Nuvigator operation requested with a context that does not include a Nuvigator.\n '
584
+ 'The context used to push or pop routes from the Nuvigator must be that of a '
585
+ 'widget that is a descendant of a Nuvigator widget.'
586
+ 'Also check if the provided Router [T] type exists withing a the Nuvigator context.' );
587
+ }
588
+
589
+ return true ;
590
+ }());
591
+
592
+ return nuvigatorState! ;
593
+ }
594
+
581
595
/// Helper method that allows passing a Nuvigator to a builder function
582
596
Nuvigator call (BuildContext context, [Widget ? child]) {
583
597
return this ;
0 commit comments