Skip to content

Commit

Permalink
Merge pull request #921 from ozzfelipe/master
Browse files Browse the repository at this point in the history
fix: Prevent RouterOutlet to get priority.
  • Loading branch information
jacobaraujo7 authored Mar 25, 2024
2 parents 7dc9c1f + 1b92a51 commit 7c549d8
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions flutter_modular/lib/flutter_modular.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -114,11 +115,22 @@ class RouterOutletState extends State<RouterOutlet> {
_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();
Expand Down

0 comments on commit 7c549d8

Please sign in to comment.