getx
getx copied to clipboard
Null controller with GetWidget + Get.Create when access controller in GetWidget constructor
Describe the bug
Using GetWidget together with Get.Create generates a null error for the controller if we tries to access the controller inside the GetWidget constructor. Note that access the controller via the constructor is allowed with GetView
**Reproduction code
widget:
class GridVerticalIconButton extends GetWidget<GridVerticalIconButtonController> {
GridVerticalIconButton(
{String title,
Key? key})
: super(key: key) {
controller.title = title; // Null error here
}
}
controller:
class GridVerticalIconButtonController extends GetxController {
late String title;
}
bindings:
class GlobalBindings implements Bindings {
@override
void dependencies() {
Get.create(() => GridVerticalIconButtonController());
}
}
To Reproduce Steps to reproduce the behavior:
Expected behavior Should be able to access controller in the GetWidget constructor
Flutter Version: 2.5.3
Getx Version: 4.6.1
Describe on which device you found the bug: Samsung Galaxy S21+
Minimal reproduce code Try to access the controller in a widget constructor that extends GetWidget
This is interesting, because the only solution would be calling Get.find beforehand and that's horrible