Skip to content
Open
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
.history
.svn/


# IntelliJ related
*.iml
*.ipr
Expand Down Expand Up @@ -91,4 +92,6 @@ unlinked_spec.ds

# Firebase configuration files
ios/Runner/GoogleService-Info.plist
android/app/google-services.json
android/app/google-services.json

ios/Flutter/flutter_export_environment.sh
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 27
compileSdkVersion 28

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -30,7 +30,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.codingwithflutter.nestednavigationdemoflutter"
minSdkVersion 16
targetSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand Down
4 changes: 4 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true

51 changes: 37 additions & 14 deletions lib/app.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:nested_navigation_demo_flutter/bottom_navigation.dart';
import 'package:nested_navigation_demo_flutter/global.dart';
import 'package:nested_navigation_demo_flutter/other_page.dart';
import 'package:nested_navigation_demo_flutter/tab_navigator.dart';

class App extends StatefulWidget {
Expand Down Expand Up @@ -28,30 +30,51 @@ class AppState extends State<App> {
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
if (Global.pageNavigatorKey.currentState.canPop()) {
Global.pageNavigatorKey.currentState.pop();

return false;
}

final isFirstRouteInCurrentTab =
!await _navigatorKeys[_currentTab].currentState.maybePop();

if (isFirstRouteInCurrentTab) {
// if not on the 'main' tab
if (_currentTab != TabItem.red) {
// select 'main' tab
_selectTab(TabItem.red);
// back button handled by app
//* back button handled by app

return false;
}
}
// let system handle back button if we're on the first route

return isFirstRouteInCurrentTab;
},
child: Scaffold(
body: Stack(children: <Widget>[
_buildOffstageNavigator(TabItem.red),
_buildOffstageNavigator(TabItem.green),
_buildOffstageNavigator(TabItem.blue),
]),
bottomNavigationBar: BottomNavigation(
currentTab: _currentTab,
onSelectTab: _selectTab,
),
child: Navigator(
key: Global.pageNavigatorKey,
onGenerateRoute: (settings) {
if (settings.name == '/other') {
return MaterialPageRoute(
builder: (context) => OtherPage(),
);
}

return MaterialPageRoute(
builder: (context) => Scaffold(
body: Stack(
children: <Widget>[
_buildOffstageNavigator(TabItem.red),
_buildOffstageNavigator(TabItem.green),
_buildOffstageNavigator(TabItem.blue),
],
),
bottomNavigationBar: BottomNavigation(
currentTab: _currentTab,
onSelectTab: _selectTab,
),
),
);
},
),
);
}
Expand Down
11 changes: 8 additions & 3 deletions lib/color_detail_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@


import 'package:flutter/material.dart';
import 'package:nested_navigation_demo_flutter/global.dart';

class ColorDetailPage extends StatelessWidget {
ColorDetailPage({this.color, this.title, this.materialIndex: 500});
Expand All @@ -10,7 +9,6 @@ class ColorDetailPage extends StatelessWidget {

@override
Widget build(BuildContext context) {

return Scaffold(
appBar: AppBar(
backgroundColor: color,
Expand All @@ -19,6 +17,13 @@ class ColorDetailPage extends StatelessWidget {
),
),
body: Container(
child: Center(
child: RaisedButton(
child: Text("Push to another screen"),
onPressed: () {
Global.pageNavigatorKey.currentState.pushNamed('/other');
}),
),
color: color[materialIndex],
),
);
Expand Down
5 changes: 5 additions & 0 deletions lib/global.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'package:flutter/cupertino.dart';

class Global {
static GlobalKey<NavigatorState> pageNavigatorKey = GlobalKey<NavigatorState>();
}
22 changes: 22 additions & 0 deletions lib/other_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:flutter/material.dart';

class OtherPage extends StatefulWidget {
@override
_OtherPageState createState() => _OtherPageState();
}

class _OtherPageState extends State<OtherPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("OtherPage"),
),
body: Container(
child: Center(
child: Text("Welcome to another page"),
),
),
);
}
}
37 changes: 15 additions & 22 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,42 @@ packages:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.10"
version: "2.0.13"
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.2"
version: "1.6.0"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.0"
version: "2.4.1"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
version: "2.0.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.2"
version: "1.1.3"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.11"
version: "1.14.12"
convert:
dependency: transitive
description:
Expand All @@ -56,7 +56,7 @@ packages:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
version: "2.1.4"
cupertino_icons:
dependency: "direct main"
description:
Expand All @@ -80,35 +80,28 @@ packages:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.4"
version: "2.1.12"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.5"
version: "0.12.6"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.7"
version: "1.1.8"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.4"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0+1"
petitparser:
dependency: transitive
description:
Expand All @@ -122,7 +115,7 @@ packages:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
version: "2.1.3"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -134,7 +127,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.5"
version: "1.7.0"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -169,7 +162,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.5"
version: "0.2.15"
typed_data:
dependency: transitive
description:
Expand All @@ -190,6 +183,6 @@ packages:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.5.0"
version: "3.6.1"
sdks:
dart: ">=2.4.0 <3.0.0"
dart: ">=2.6.0 <3.0.0"