Skip to content

Commit

Permalink
Re add FlutterError in case of null
Browse files Browse the repository at this point in the history
  • Loading branch information
raapperez committed Sep 9, 2024
1 parent 2d52247 commit 82e8e5d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/src/nuvigator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,22 @@ class Nuvigator<T extends INuRouter?> extends StatelessWidget {
BuildContext context, {
bool rootNuvigator = false,
}) {
return Nuvigator.maybeOf(context, rootNuvigator: rootNuvigator)!;
final nuvigatorState =
Nuvigator.maybeOf<T>(context, rootNuvigator: rootNuvigator);

assert(() {
if (nuvigatorState == null) {
throw FlutterError(
'Nuvigator operation requested with a context that does not include a Nuvigator.\n'
'The context used to push or pop routes from the Nuvigator must be that of a '
'widget that is a descendant of a Nuvigator widget.'
'Also check if the provided Router [T] type exists withing a the Nuvigator context.');
}

return true;
}());

return nuvigatorState!;
}

/// Helper method that allows passing a Nuvigator to a builder function
Expand Down

0 comments on commit 82e8e5d

Please sign in to comment.