I don't know English very well. So I use Google Translation. Sorry!
my flutter project use getx package
[store code]
class TestStore extends GetxController {
static TestStore get to => Get.find<TestStore >();
Rxn<double> test = Rxn<double>();
void aFuntion() async {
test(1); // screen update
// test value = 1
}
void bFunction() {
test(null); // no screen update
// test value = null
}
}
[Test Screen code]
class ABFuntionTest extends StatelessWidget {
const ABFuntionTest({ Key? key }) : super(key: key);
@override
Widget build(BuildContext context) {
Get.put(TestStore());
return MaterialApp(
home: Scaffold(
body: Column(
children: [
TextButton(onPressed: TestStore.to.aFunction, child: Text("A function button")),
TextButton(onPressed: TestStore.to.bFunction, child: Text("B function button")),
Obx(
() => Text("${LoginStore.to.test.value}")
),
],
),
),
);
}
}
why bFunction code no screen update ? how to null value update and screen update?
CodePudding user response:
Rxn is not nullable, use Rx if you want null value
or use 0 instead null for double
void aFuntion() async {
test.value = 1; // screen update
}
void bFunction() {
test.value = 0;
}
CodePudding user response:
I found a solution.
Rxn<double> test= Rxn<double>();
void bFunction() {
test(test.value = null);
// or test.value = null;
}
thank you