From aecbd2081a0a13ba25bb80f3a1ad10f9b3674411 Mon Sep 17 00:00:00 2001 From: Jonny Borges <35742643+jonataslaw@users.noreply.github.com> Date: Thu, 24 Aug 2023 12:31:48 -0300 Subject: [PATCH] fix onClosed is not called. Add onHidden lifecycle --- example/.metadata | 29 +- example/lib/main.dart | 254 ++++++++++-------- example_nav2/android/local.properties | 4 +- example_nav2/ios/Flutter/Generated.xcconfig | 4 +- .../ios/Flutter/flutter_export_environment.sh | 4 +- .../root/controllers/root_controller.dart | 2 - .../controllers/settings_controller.dart | 2 - .../macos/Runner.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- lib/get_navigation/src/router_report.dart | 7 +- .../src/routes/get_information_parser.dart | 5 +- .../src/routes/route_middleware.dart | 5 +- .../src/snackbar/snackbar_controller.dart | 2 +- .../src/simple/get_controllers.dart | 4 + pubspec.yaml | 3 +- 15 files changed, 170 insertions(+), 159 deletions(-) diff --git a/example/.metadata b/example/.metadata index caa269cf4..b665bf909 100644 --- a/example/.metadata +++ b/example/.metadata @@ -1,11 +1,11 @@ # This file tracks properties of this Flutter project. # Used by Flutter tool to assess capabilities and perform upgrades etc. # -# This file should be version controlled. +# This file should be version controlled and should not be manually edited. version: - revision: c07f7888888435fd9df505aa2efc38d3cf65681b - channel: stable + revision: "e1e47221e86272429674bec4f1bd36acc4fc7b77" + channel: "stable" project_type: app @@ -13,26 +13,11 @@ project_type: app migration: platforms: - platform: root - create_revision: c07f7888888435fd9df505aa2efc38d3cf65681b - base_revision: c07f7888888435fd9df505aa2efc38d3cf65681b - - platform: android - create_revision: c07f7888888435fd9df505aa2efc38d3cf65681b - base_revision: c07f7888888435fd9df505aa2efc38d3cf65681b + create_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77 + base_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77 - platform: ios - create_revision: c07f7888888435fd9df505aa2efc38d3cf65681b - base_revision: c07f7888888435fd9df505aa2efc38d3cf65681b - - platform: linux - create_revision: c07f7888888435fd9df505aa2efc38d3cf65681b - base_revision: c07f7888888435fd9df505aa2efc38d3cf65681b - - platform: macos - create_revision: c07f7888888435fd9df505aa2efc38d3cf65681b - base_revision: c07f7888888435fd9df505aa2efc38d3cf65681b - - platform: web - create_revision: c07f7888888435fd9df505aa2efc38d3cf65681b - base_revision: c07f7888888435fd9df505aa2efc38d3cf65681b - - platform: windows - create_revision: c07f7888888435fd9df505aa2efc38d3cf65681b - base_revision: c07f7888888435fd9df505aa2efc38d3cf65681b + create_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77 + base_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77 # User provided section diff --git a/example/lib/main.dart b/example/lib/main.dart index 37474b083..73058e14d 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,10 +1,30 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'lang/translation_service.dart'; -import 'routes/app_pages.dart'; -import 'shared/logger/logger_utils.dart'; +// void main() { +// runApp(const MyApp()); +// } +// class MyApp extends StatelessWidget { +// const MyApp({Key? key}) : super(key: key); + +// @override +// Widget build(BuildContext context) { +// return GetMaterialApp( +// theme: ThemeData(useMaterial3: true), +// debugShowCheckedModeBanner: false, +// enableLog: true, +// logWriterCallback: Logger.write, +// initialRoute: AppPages.INITIAL, +// getPages: AppPages.routes, +// locale: TranslationService.locale, +// fallbackLocale: TranslationService.fallbackLocale, +// translations: TranslationService(), +// ); +// } +// } + +/// Nav 2 snippet void main() { runApp(const MyApp()); } @@ -15,127 +35,131 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return GetMaterialApp( - theme: ThemeData(useMaterial3: true), + getPages: [ + GetPage( + participatesInRootNavigator: true, + name: '/first', + page: () => const First()), + GetPage( + name: '/second', + page: () => const Second(), + ), + GetPage( + name: '/third', + page: () => const Third(), + ), + ], debugShowCheckedModeBanner: false, - enableLog: true, - logWriterCallback: Logger.write, - initialRoute: AppPages.INITIAL, - getPages: AppPages.routes, - locale: TranslationService.locale, - fallbackLocale: TranslationService.fallbackLocale, - translations: TranslationService(), ); } } -/// Nav 2 snippet -// void main() { -// runApp(const MyApp()); -// } - -// class MyApp extends StatelessWidget { -// const MyApp({Key? key}) : super(key: key); +class FirstController extends GetxController { + @override + void onClose() { + print('on close first'); + super.onClose(); + } +} -// @override -// Widget build(BuildContext context) { -// return GetMaterialApp( -// getPages: [ -// GetPage( -// participatesInRootNavigator: true, -// name: '/first', -// page: () => const First()), -// GetPage( -// name: '/second', -// page: () => const Second(), -// ), -// GetPage( -// name: '/third', -// page: () => const Third(), -// ), -// ], -// debugShowCheckedModeBanner: false, -// ); -// } -// } +class First extends StatelessWidget { + const First({Key? key}) : super(key: key); -// class First extends StatelessWidget { -// const First({Key? key}) : super(key: key); + @override + Widget build(BuildContext context) { + print('First rebuild'); + Get.put(FirstController()); + return Scaffold( + appBar: AppBar( + title: const Text('page one'), + leading: IconButton( + icon: const Icon(Icons.more), + onPressed: () { + print('THEME CHANGED'); + Get.changeTheme( + Get.isDarkMode ? ThemeData.light() : ThemeData.dark()); + }, + ), + ), + body: Center( + child: SizedBox( + height: 300, + width: 300, + child: ElevatedButton( + onPressed: () { + Get.toNamed('/second?id=123'); + }, + child: const Text('next screen'), + ), + ), + ), + ); + } +} -// @override -// Widget build(BuildContext context) { -// print('First rebuild'); -// return Scaffold( -// appBar: AppBar( -// title: const Text('page one'), -// leading: IconButton( -// icon: const Icon(Icons.more), -// onPressed: () { -// print('THEME CHANGED'); -// Get.changeTheme( -// Get.isDarkMode ? ThemeData.light() : ThemeData.dark()); -// }, -// ), -// ), -// body: Center( -// child: SizedBox( -// height: 300, -// width: 300, -// child: ElevatedButton( -// onPressed: () { -// Get.toNamed('/second?id=123'); -// }, -// child: const Text('next screen'), -// ), -// ), -// ), -// ); -// } -// } +class SecondController extends GetxController { + final textEdit = TextEditingController(); + @override + void onClose() { + print('on close second'); + textEdit.dispose(); + super.onClose(); + } +} -// class Second extends StatelessWidget { -// const Second({Key? key}) : super(key: key); +class Second extends StatelessWidget { + const Second({Key? key}) : super(key: key); -// @override -// Widget build(BuildContext context) { -// print('second rebuild'); -// return Scaffold( -// appBar: AppBar( -// title: Text('page two ${Get.parameters["id"]}'), -// ), -// body: Center( -// child: SizedBox( -// height: 300, -// width: 300, -// child: ElevatedButton( -// onPressed: () {}, -// child: const Text('next screen'), -// ), -// ), -// ), -// ); -// } -// } + @override + Widget build(BuildContext context) { + final controller = Get.put(SecondController()); + print('second rebuild'); + return Scaffold( + appBar: AppBar( + title: Text('page two ${Get.parameters["id"]}'), + ), + body: Center( + child: Column( + children: [ + Expanded( + child: TextField( + controller: controller.textEdit, + )), + SizedBox( + height: 300, + width: 300, + child: ElevatedButton( + onPressed: () {}, + child: const Text('next screen'), + ), + ), + ], + ), + ), + ); + } +} -// class Third extends StatelessWidget { -// const Third({Key? key}) : super(key: key); +class Third extends StatelessWidget { + const Third({Key? key}) : super(key: key); -// @override -// Widget build(BuildContext context) { -// return Scaffold( -// backgroundColor: Colors.red, -// appBar: AppBar( -// title: const Text('page three'), -// ), -// body: Center( -// child: SizedBox( -// height: 300, -// width: 300, -// child: ElevatedButton( -// onPressed: () {}, -// child: const Text('go to first screen'), -// ), -// ), -// ), -// ); -// } -// } + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: Colors.red, + appBar: AppBar( + title: const Text('page three'), + ), + body: Center( + child: SizedBox( + height: 300, + width: 300, + child: ElevatedButton( + onPressed: () {}, + child: const Text('go to first screen'), + ), + ), + ), + ); + } +} diff --git a/example_nav2/android/local.properties b/example_nav2/android/local.properties index aea030ad3..79defc581 100644 --- a/example_nav2/android/local.properties +++ b/example_nav2/android/local.properties @@ -1,2 +1,2 @@ -sdk.dir=/home/sumit/Android/Sdk -flutter.sdk=/home/sumit/softwares/flutter \ No newline at end of file +sdk.dir=/Users/jonatasborges/Library/Android/sdk +flutter.sdk=/Users/jonatasborges/flutter \ No newline at end of file diff --git a/example_nav2/ios/Flutter/Generated.xcconfig b/example_nav2/ios/Flutter/Generated.xcconfig index 127fdc6b9..2925dda96 100644 --- a/example_nav2/ios/Flutter/Generated.xcconfig +++ b/example_nav2/ios/Flutter/Generated.xcconfig @@ -1,6 +1,6 @@ // This is a generated file; do not edit or check into version control. -FLUTTER_ROOT=/home/sumit/softwares/flutter -FLUTTER_APPLICATION_PATH=/home/sumit/StudioProjects/getx/example_nav2 +FLUTTER_ROOT=/Users/jonatasborges/flutter +FLUTTER_APPLICATION_PATH=/Users/jonatasborges/getx5/getx/example_nav2 COCOAPODS_PARALLEL_CODE_SIGN=true FLUTTER_TARGET=lib/main.dart FLUTTER_BUILD_DIR=build diff --git a/example_nav2/ios/Flutter/flutter_export_environment.sh b/example_nav2/ios/Flutter/flutter_export_environment.sh index 343a2f1d5..55a609d62 100755 --- a/example_nav2/ios/Flutter/flutter_export_environment.sh +++ b/example_nav2/ios/Flutter/flutter_export_environment.sh @@ -1,7 +1,7 @@ #!/bin/sh # This is a generated file; do not edit or check into version control. -export "FLUTTER_ROOT=/home/sumit/softwares/flutter" -export "FLUTTER_APPLICATION_PATH=/home/sumit/StudioProjects/getx/example_nav2" +export "FLUTTER_ROOT=/Users/jonatasborges/flutter" +export "FLUTTER_APPLICATION_PATH=/Users/jonatasborges/getx5/getx/example_nav2" export "COCOAPODS_PARALLEL_CODE_SIGN=true" export "FLUTTER_TARGET=lib/main.dart" export "FLUTTER_BUILD_DIR=build" diff --git a/example_nav2/lib/app/modules/root/controllers/root_controller.dart b/example_nav2/lib/app/modules/root/controllers/root_controller.dart index b65726572..1a64c837e 100644 --- a/example_nav2/lib/app/modules/root/controllers/root_controller.dart +++ b/example_nav2/lib/app/modules/root/controllers/root_controller.dart @@ -1,8 +1,6 @@ import 'package:get/get.dart'; class RootController extends GetxController { - //TODO: Implement RootController - final count = 0.obs; @override void onInit() { diff --git a/example_nav2/lib/app/modules/settings/controllers/settings_controller.dart b/example_nav2/lib/app/modules/settings/controllers/settings_controller.dart index daaebe9f9..480edde5e 100644 --- a/example_nav2/lib/app/modules/settings/controllers/settings_controller.dart +++ b/example_nav2/lib/app/modules/settings/controllers/settings_controller.dart @@ -1,8 +1,6 @@ import 'package:get/get.dart'; class SettingsController extends GetxController { - //TODO: Implement SettingsController - final count = 0.obs; @override void onInit() { diff --git a/example_nav2/macos/Runner.xcodeproj/project.pbxproj b/example_nav2/macos/Runner.xcodeproj/project.pbxproj index 380032f0e..fdbc0a746 100644 --- a/example_nav2/macos/Runner.xcodeproj/project.pbxproj +++ b/example_nav2/macos/Runner.xcodeproj/project.pbxproj @@ -182,7 +182,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0920; - LastUpgradeCheck = 1300; + LastUpgradeCheck = 1430; ORGANIZATIONNAME = ""; TargetAttributes = { 33CC10EC2044A3C60003C045 = { diff --git a/example_nav2/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example_nav2/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 690f2a60c..a55e91080 100644 --- a/example_nav2/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example_nav2/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ { void reportRouteDispose(T disposed) { if (Get.smartManagement != SmartManagement.onlyBuilder) { - ambiguate(Engine.instance)!.addPostFrameCallback((_) { - _removeDependencyByRoute(disposed); - }); + // ambiguate(Engine.instance)!.addPostFrameCallback((_) { + // Future.microtask(() { + _removeDependencyByRoute(disposed); + // }); } } diff --git a/lib/get_navigation/src/routes/get_information_parser.dart b/lib/get_navigation/src/routes/get_information_parser.dart index 4961cc23f..6e58e7034 100644 --- a/lib/get_navigation/src/routes/get_information_parser.dart +++ b/lib/get_navigation/src/routes/get_information_parser.dart @@ -20,7 +20,8 @@ class GetInformationParser extends RouteInformationParser { SynchronousFuture parseRouteInformation( RouteInformation routeInformation, ) { - var location = routeInformation.location; + final uri = routeInformation.uri; + var location = uri.toString(); if (location == '/') { //check if there is a corresponding page //if not, relocate to initialRoute @@ -41,7 +42,7 @@ class GetInformationParser extends RouteInformationParser { @override RouteInformation restoreRouteInformation(RouteDecoder configuration) { return RouteInformation( - location: configuration.pageSettings?.name, + uri: Uri.tryParse(configuration.pageSettings?.name ?? ''), state: null, ); } diff --git a/lib/get_navigation/src/routes/route_middleware.dart b/lib/get_navigation/src/routes/route_middleware.dart index 69a4c31fc..6f9cc6b42 100644 --- a/lib/get_navigation/src/routes/route_middleware.dart +++ b/lib/get_navigation/src/routes/route_middleware.dart @@ -177,8 +177,9 @@ class MiddlewareRunner { return page; } - void runOnPageDispose() => - _getMiddlewares().forEach((element) => element.onPageDispose()); + void runOnPageDispose() { + _getMiddlewares().forEach((element) => element.onPageDispose()); + } } class PageRedirect { diff --git a/lib/get_navigation/src/snackbar/snackbar_controller.dart b/lib/get_navigation/src/snackbar/snackbar_controller.dart index a1240f33a..9938f1ff8 100644 --- a/lib/get_navigation/src/snackbar/snackbar_controller.dart +++ b/lib/get_navigation/src/snackbar/snackbar_controller.dart @@ -242,10 +242,10 @@ class SnackbarController { onEnter: (_) => snackbar.onHover?.call(snackbar, SnackHoverState.entered), onExit: (_) => snackbar.onHover?.call(snackbar, SnackHoverState.exited), child: GestureDetector( - child: snackbar, onTap: snackbar.onTap != null ? () => snackbar.onTap?.call(snackbar) : null, + child: snackbar, ), ); }); diff --git a/lib/get_state_manager/src/simple/get_controllers.dart b/lib/get_state_manager/src/simple/get_controllers.dart index 714924ee1..593012f43 100644 --- a/lib/get_state_manager/src/simple/get_controllers.dart +++ b/lib/get_state_manager/src/simple/get_controllers.dart @@ -122,6 +122,9 @@ mixin FullLifeCycleMixin on FullLifeCycleController { case AppLifecycleState.detached: onDetached(); break; + case AppLifecycleState.hidden: + onHidden(); + break; } } @@ -129,4 +132,5 @@ mixin FullLifeCycleMixin on FullLifeCycleController { void onPaused() {} void onInactive() {} void onDetached() {} + void onHidden() {} } diff --git a/pubspec.yaml b/pubspec.yaml index 42cf6653d..697619756 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ version: 5.0.0-release-candidate-4 homepage: https://github.com/jonataslaw/getx environment: - sdk: '>=2.17.0 <4.0.0' + sdk: ">=2.17.0 <4.0.0" dependencies: flutter: @@ -16,7 +16,6 @@ dev_dependencies: flutter_test: sdk: flutter flutter_lints: ^2.0.2 - # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec