diff --git a/flutter_modular/lib/flutter_modular.dart b/flutter_modular/lib/flutter_modular.dart index 1012b736..89947a29 100644 --- a/flutter_modular/lib/flutter_modular.dart +++ b/flutter_modular/lib/flutter_modular.dart @@ -2,6 +2,7 @@ library flutter_modular; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_modular/flutter_modular.dart'; import 'package:flutter_modular/src/flutter_modular_module.dart'; import 'package:modular_core/modular_core.dart'; @@ -114,11 +115,22 @@ class RouterOutletState extends State { _navigatorKey, currentObservers, ); + + /// Prevent RouterOutlent to take back button priority + /// when the new named route, is not a children + if (_newRouteIsNotChildren(modal.route)) { + _backButtonDispatcher = null; + return; + } final router = Router.of(context); _backButtonDispatcher = router.backButtonDispatcher // ?.createChildBackButtonDispatcher(); } + bool _newRouteIsNotChildren(ParallelRoute route) { + return !route.children.any((e) => Modular.to.path.contains(e.name)); + } + @override void dispose() { super.dispose();