From d2e98078d538ec2da53da1febaf8f6a8680a2a2b Mon Sep 17 00:00:00 2001 From: wheeOs <101183252+wheeOs@users.noreply.github.com> Date: Fri, 9 Sep 2022 18:05:38 +0200 Subject: [PATCH 1/4] hopefully Out of scope observable fix from https://github.com/jonataslaw/getx/pull/2522/commits/8002d5fa242472bbcb74d5ea025d2f17468530d3 --- lib/get_state_manager/src/simple/list_notifier.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/get_state_manager/src/simple/list_notifier.dart b/lib/get_state_manager/src/simple/list_notifier.dart index b96fe48e6..f75fd2e64 100644 --- a/lib/get_state_manager/src/simple/list_notifier.dart +++ b/lib/get_state_manager/src/simple/list_notifier.dart @@ -178,7 +178,7 @@ class Notifier { if (data.disposers.isEmpty && data.throwException) { throw ObxError(); } - _notifyData = data; + _notifyData = null; return result; } } From f7dcc9801d0e1bb6386258109379f04e9e473028 Mon Sep 17 00:00:00 2001 From: Osman Kutlucan <101183252+wheeOs@users.noreply.github.com> Date: Thu, 12 Sep 2024 15:33:08 +0200 Subject: [PATCH 2/4] Update rx_impl.dart `.obs` now supports nullable types again as before --- lib/get_rx/src/rx_types/rx_core/rx_impl.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/get_rx/src/rx_types/rx_core/rx_impl.dart b/lib/get_rx/src/rx_types/rx_core/rx_impl.dart index c879e234e..88b594ee2 100644 --- a/lib/get_rx/src/rx_types/rx_core/rx_impl.dart +++ b/lib/get_rx/src/rx_types/rx_core/rx_impl.dart @@ -327,7 +327,7 @@ extension BoolExtension on bool { RxBool get obs => RxBool(this); } -extension RxT on T { +extension RxT on T { /// Returns a `Rx` instance with [this] `T` as initial value. Rx get obs => Rx(this); } @@ -336,7 +336,7 @@ extension RxT on T { /// It's a breaking change, but it is essential to avoid conflicts with /// the new dart 3 features. T will be inferred by contextual type inference /// rather than the extension type. -extension RxTnew on Object { +extension RxTnew on Object? { /// Returns a `Rx` instance with [this] `T` as initial value. Rx obs() => Rx(this as T); } From 45fe11bad4a6722b21ac69a0cc56f583b30c651d Mon Sep 17 00:00:00 2001 From: Osman Kutlucan <101183252+wheeOs@users.noreply.github.com> Date: Thu, 12 Sep 2024 15:58:54 +0200 Subject: [PATCH 3/4] added test for obs with nullable value --- test/state_manager/get_rxstate_test.dart | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/state_manager/get_rxstate_test.dart b/test/state_manager/get_rxstate_test.dart index aef1c2f16..91f935c44 100644 --- a/test/state_manager/get_rxstate_test.dart +++ b/test/state_manager/get_rxstate_test.dart @@ -30,6 +30,9 @@ void main() { Text( 'Map: ${controller.map.length}', ), + Text( + 'Nullable: ${controller.nullableNum.value}', + ), TextButton( child: const Text("increment"), onPressed: () => controller.increment(), @@ -56,12 +59,14 @@ void main() { expect(find.text("Bool: true"), findsOneWidget); expect(find.text("List: 0"), findsOneWidget); expect(find.text("Map: 0"), findsOneWidget); + expect(find.text("Nullable: null"), findsOneWidget); Controller.to.increment(); await tester.pump(); expect(find.text("Count: 1"), findsOneWidget); + expect(find.text("Nullable: 0"), findsOneWidget); await tester.tap(find.text('increment')); @@ -86,6 +91,7 @@ class Controller extends GetxController { RxInt counter = 0.obs; RxDouble doubleNum = 0.0.obs; + final nullableNum = (null as int?).obs; RxString string = "string".obs; RxList list = [].obs; RxMap map = {}.obs; @@ -93,5 +99,6 @@ class Controller extends GetxController { void increment() { counter.value++; + nullableNum.value ??= 0; } } From 3690a474328dad880e286c1a1c83390ddd59b024 Mon Sep 17 00:00:00 2001 From: Osman Kutlucan <101183252+wheeOs@users.noreply.github.com> Date: Fri, 13 Sep 2024 10:07:27 +0200 Subject: [PATCH 4/4] fixes conflict issues, hence reducing nullable types to the extension method --- lib/get_rx/src/rx_types/rx_core/rx_impl.dart | 2 +- test/state_manager/get_rxstate_test.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/get_rx/src/rx_types/rx_core/rx_impl.dart b/lib/get_rx/src/rx_types/rx_core/rx_impl.dart index 88b594ee2..27feb34da 100644 --- a/lib/get_rx/src/rx_types/rx_core/rx_impl.dart +++ b/lib/get_rx/src/rx_types/rx_core/rx_impl.dart @@ -327,7 +327,7 @@ extension BoolExtension on bool { RxBool get obs => RxBool(this); } -extension RxT on T { +extension RxT on T { /// Returns a `Rx` instance with [this] `T` as initial value. Rx get obs => Rx(this); } diff --git a/test/state_manager/get_rxstate_test.dart b/test/state_manager/get_rxstate_test.dart index 91f935c44..de2f282dc 100644 --- a/test/state_manager/get_rxstate_test.dart +++ b/test/state_manager/get_rxstate_test.dart @@ -91,7 +91,7 @@ class Controller extends GetxController { RxInt counter = 0.obs; RxDouble doubleNum = 0.0.obs; - final nullableNum = (null as int?).obs; + final nullableNum = null.obs(); RxString string = "string".obs; RxList list = [].obs; RxMap map = {}.obs;