From f83ec34428bd2fcb074774a1b5fb3530d39e5d72 Mon Sep 17 00:00:00 2001 From: "Felipe C. dos Santos" Date: Thu, 30 Nov 2023 14:44:10 -0300 Subject: [PATCH] ref to better code reading --- flutter_modular/lib/flutter_modular.dart | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/flutter_modular/lib/flutter_modular.dart b/flutter_modular/lib/flutter_modular.dart index ea0fed16..86fc2610 100644 --- a/flutter_modular/lib/flutter_modular.dart +++ b/flutter_modular/lib/flutter_modular.dart @@ -2,6 +2,7 @@ library flutter_modular_forked; 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'; @@ -98,9 +99,6 @@ class RouterOutletState extends State { /// visible for test @visibleForTesting void listener() { - print(Modular.to.path); - final modal = ModalRoute.of(context)?.settings as ModularPage?; - setState(() {}); } @@ -117,9 +115,10 @@ class RouterOutletState extends State { _navigatorKey, currentObservers, ); - if (!(modal?.route.children.any((e) => Modular.to.path.contains(e.name)) ?? - true)) { - print('is not a children'); + + /// Prevent RouterOutlent to take back button priority + /// when the new named route, is not a children + if (_newRouteIsNotChildren(modal.route)) { _backButtonDispatcher = null; return; } @@ -128,6 +127,10 @@ class RouterOutletState extends State { ?.createChildBackButtonDispatcher(); } + bool _newRouteIsNotChildren(ParallelRoute route) { + return !route.children.any((e) => Modular.to.path.contains(e.name)); + } + @override void dispose() { super.dispose();