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..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 @@ -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); } diff --git a/test/state_manager/get_rxstate_test.dart b/test/state_manager/get_rxstate_test.dart index aef1c2f16..de2f282dc 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.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; } }