diff --git a/.gitignore b/.gitignore index ac83595..b2eb68e 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ .history .svn/ + # IntelliJ related *.iml *.ipr @@ -91,4 +92,6 @@ unlinked_spec.ds # Firebase configuration files ios/Runner/GoogleService-Info.plist -android/app/google-services.json \ No newline at end of file +android/app/google-services.json + +ios/Flutter/flutter_export_environment.sh \ No newline at end of file diff --git a/android/app/build.gradle b/android/app/build.gradle index 2bf72ca..cf97b11 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -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' @@ -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" diff --git a/android/gradle.properties b/android/gradle.properties index 8bd86f6..207beb6 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1 +1,5 @@ org.gradle.jvmargs=-Xmx1536M +android.enableR8=true +android.useAndroidX=true +android.enableJetifier=true + diff --git a/lib/app.dart b/lib/app.dart index d7365be..64e8d23 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -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 { @@ -28,30 +30,51 @@ class AppState extends State { 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: [ - _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: [ + _buildOffstageNavigator(TabItem.red), + _buildOffstageNavigator(TabItem.green), + _buildOffstageNavigator(TabItem.blue), + ], + ), + bottomNavigationBar: BottomNavigation( + currentTab: _currentTab, + onSelectTab: _selectTab, + ), + ), + ); + }, ), ); } diff --git a/lib/color_detail_page.dart b/lib/color_detail_page.dart index 479584d..1bda809 100644 --- a/lib/color_detail_page.dart +++ b/lib/color_detail_page.dart @@ -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}); @@ -10,7 +9,6 @@ class ColorDetailPage extends StatelessWidget { @override Widget build(BuildContext context) { - return Scaffold( appBar: AppBar( backgroundColor: color, @@ -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], ), ); diff --git a/lib/global.dart b/lib/global.dart new file mode 100644 index 0000000..3e94db9 --- /dev/null +++ b/lib/global.dart @@ -0,0 +1,5 @@ +import 'package:flutter/cupertino.dart'; + +class Global { + static GlobalKey pageNavigatorKey = GlobalKey(); +} \ No newline at end of file diff --git a/lib/other_page.dart b/lib/other_page.dart new file mode 100644 index 0000000..375b155 --- /dev/null +++ b/lib/other_page.dart @@ -0,0 +1,22 @@ +import 'package:flutter/material.dart'; + +class OtherPage extends StatefulWidget { + @override + _OtherPageState createState() => _OtherPageState(); +} + +class _OtherPageState extends State { + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text("OtherPage"), + ), + body: Container( + child: Center( + child: Text("Welcome to another page"), + ), + ), + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index 1cb9e6d..62df70f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: @@ -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: @@ -80,21 +80,21 @@ 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: @@ -102,13 +102,6 @@ packages: 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: @@ -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 @@ -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: @@ -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: @@ -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"