Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

obs supporting nullable values again #3211

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion lib/get_rx/src/rx_types/rx_core/rx_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ extension RxT<T extends Object> 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<T> obs<T>() => Rx<T>(this as T);
}
7 changes: 7 additions & 0 deletions test/state_manager/get_rxstate_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ void main() {
Text(
'Map: ${controller.map.length}',
),
Text(
'Nullable: ${controller.nullableNum.value}',
),
TextButton(
child: const Text("increment"),
onPressed: () => controller.increment(),
Expand All @@ -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'));

Expand All @@ -86,12 +91,14 @@ class Controller extends GetxController {

RxInt counter = 0.obs;
RxDouble doubleNum = 0.0.obs;
final nullableNum = null.obs<int?>();
RxString string = "string".obs;
RxList list = [].obs;
RxMap map = {}.obs;
RxBool boolean = true.obs;

void increment() {
counter.value++;
nullableNum.value ??= 0;
}
}
Loading