Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,19 @@ If you are pushing a new `modal` screen, use the following function:

- To push bottom sheet on top of the Navigation Bar, use showModalBottomScreen and set it's property `useRootNavigator` to true. See example project for an illustration.

- To handle PopScopes down in the widget tree just implement 'NestedWillPopScope':

```dart
import 'package:persistent_bottom_nav_bar/models/nested_will_pop_scope.dart';

NestedWillPopScope(
onWillPop: () async {
'your statements to handle PopScope'
},
child: ThirdNestedScreen(),
);
```

## Custom Navigation Bar Styling

If you want to have your own style for the navigation bar, follow these steps:
Expand Down
6 changes: 3 additions & 3 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0"
version: "2.6.1"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -99,7 +99,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -134,7 +134,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19"
version: "0.3.0"
typed_data:
dependency: transitive
description:
Expand Down
67 changes: 67 additions & 0 deletions lib/models/nested_will_pop_scope.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import 'package:flutter/material.dart';

class NestedWillPopScope extends StatefulWidget {
const NestedWillPopScope({
Key? key,
required this.child,
required this.onWillPop,
}) : super(key: key);

final Widget child;
final WillPopCallback onWillPop;

@override
_NestedWillPopScopeState createState() => _NestedWillPopScopeState();

static _NestedWillPopScopeState? of(BuildContext context) {
return context.findAncestorStateOfType<_NestedWillPopScopeState>();
}
}

class _NestedWillPopScopeState extends State<NestedWillPopScope> {
ModalRoute<dynamic>? _route;

_NestedWillPopScopeState? _descendant;

//ignore: avoid_setters_without_getters
set descendant(_NestedWillPopScopeState state) {
_descendant = state;
updateRouteCallback();
}

Future<bool> onWillPop() async {
bool? willPop;
if (_descendant != null) {
willPop = await _descendant!.onWillPop();
}
if (willPop == null || willPop) {
willPop = await widget.onWillPop();
}
return willPop;
}

void updateRouteCallback() {
_route?.removeScopedWillPopCallback(onWillPop);
_route = ModalRoute.of(context);
_route?.addScopedWillPopCallback(onWillPop);
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
final parentGuard = NestedWillPopScope.of(context);
if (parentGuard != null) {
parentGuard.descendant = this;
}
updateRouteCallback();
}

@override
void dispose() {
_route?.removeScopedWillPopCallback(onWillPop);
super.dispose();
}

@override
Widget build(BuildContext context) => widget.child;
}
2 changes: 2 additions & 0 deletions lib/persistent-tab-view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import 'dart:ui';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart' show CupertinoApp;
import 'models/nested_will_pop_scope.dart';


//Main TabView Widget
part 'persistent-tab-view.widget.dart';
Expand Down
4 changes: 2 additions & 2 deletions lib/persistent-tab-view.widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -667,11 +667,11 @@ class _PersistentTabViewState extends State<PersistentTabView> {
}

if (widget.handleAndroidBackButtonPress || widget.onWillPop != null) {
return WillPopScope(
return NestedWillPopScope(
onWillPop: !widget.handleAndroidBackButtonPress &&
widget.onWillPop != null
? widget.onWillPop!(_contextList[_controller!.index])
as Future<bool> Function()?
as Future<bool> Function()
: widget.handleAndroidBackButtonPress && widget.onWillPop != null
? () async {
if (_controller!.index == 0 &&
Expand Down
6 changes: 3 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0"
version: "2.6.1"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -92,7 +92,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -127,7 +127,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19"
version: "0.3.0"
typed_data:
dependency: transitive
description:
Expand Down