Issue
I have get value of RxString? name;
and want to use in the Text()
widget like
Text(uController.name() ?? 'noooo nameeee'),
However, it causes an error of
The function can't be unconditionally invoked because it can be 'null'. Try adding a null check ('!').
Even if I add ?
to RxString, I can't use it as null assignable. Is there any way that I can use GetX with ??
command?
// my GetxController file
class uController extends GetxController {
RxString? name;
}
uController uController = Get.find();
I'd just tried with (_uController?.name() ?? 'noooo nameeee')
, I still get
The function can't be unconditionally invoked because it can be 'null'. Try adding a null check ('!').
uController _uController = Get.put(uController());
class DashboardView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Obx(() => Column(
children: [
Text(_uController.name() ?? 'hmm'),
Text(_uController?.name() ?? 'hmm'),
],
)),
],
),
)); .....
Solution
Use both ?.
and ??
Text(uController?.name() ?? 'noooo nameeee'),
For more read this https://dart.dev/null-safety/understanding-null-safety
Answered By - Jahidul Islam
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.