构建 GetX<LogoPickerController>(controller: Instance of 'LogoPickerController', tag: null, has builder, dirty 抛出以下消息
The following message was thrown building GetX<LogoPickerController>(controller: Instance of 'LogoPickerController', tag: null, has builder, dirty
我正在使用 Getx。但我正面临这个问题:
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY
╞═══════════════════════════════════════════════════════════ The
following message was thrown building
GetX(controller: Instance of
'LogoPickerController', tag: null, has builder, dirty, state:
GetXState#ec9a5(controller: Instance of
'LogoPickerController')):
[Get] the improper use of a GetX has been detected.
You should only use GetX or Obx for the specific widget that will be updated.
If you are seeing this error, you probably did not insert any observable variables into GetX/Obx
or insert them outside the scope that GetX considers suitable for an update
(example: GetX => HeavyWidget => variableObservable).
If you need to update a parent widget and a child widget, wrap each one in an Obx/GetX.
代码是:
Center(
child: GetX<LogoPickerController>(
init: LogoPickerController(),
builder: (controller) {
if (controller.image?.value != null) {
return CircleAvatar(
radius: 30,
child: ClipOval(
child: Image.file(
controller.image?.value ?? File(""),
width: 200,
height: 200,
fit: BoxFit.fill,
)),
);
} else {
return const EntityLogoPickerWidget();
}
}),
),
当我们使用反应变量时,首选使用 GetX 和 Obx。
尝试用 GetBuilder
替换 GetX
。即
Center(
child: GetBuilder<LogoPickerController>(
init: LogoPickerController(),
initState: (_) {}, //NOT NEEDED
builder: (controller) {
if (controller.image?.value != null) {
return CircleAvatar(
radius: 30,
child: ClipOval(
child: Image.file(
controller.image?.value ?? File(""),
width: 200,
height: 200,
fit: BoxFit.fill,
)),
);
} else {
return const EntityLogoPickerWidget();
}
}),
),
我正在使用 Getx。但我正面临这个问题:
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ The following message was thrown building GetX(controller: Instance of
'LogoPickerController', tag: null, has builder, dirty, state: GetXState#ec9a5(controller: Instance of 'LogoPickerController')): [Get] the improper use of a GetX has been detected. You should only use GetX or Obx for the specific widget that will be updated. If you are seeing this error, you probably did not insert any observable variables into GetX/Obx or insert them outside the scope that GetX considers suitable for an update (example: GetX => HeavyWidget => variableObservable). If you need to update a parent widget and a child widget, wrap each one in an Obx/GetX.
代码是:
Center(
child: GetX<LogoPickerController>(
init: LogoPickerController(),
builder: (controller) {
if (controller.image?.value != null) {
return CircleAvatar(
radius: 30,
child: ClipOval(
child: Image.file(
controller.image?.value ?? File(""),
width: 200,
height: 200,
fit: BoxFit.fill,
)),
);
} else {
return const EntityLogoPickerWidget();
}
}),
),
当我们使用反应变量时,首选使用 GetX 和 Obx。
尝试用 GetBuilder
替换 GetX
。即
Center(
child: GetBuilder<LogoPickerController>(
init: LogoPickerController(),
initState: (_) {}, //NOT NEEDED
builder: (controller) {
if (controller.image?.value != null) {
return CircleAvatar(
radius: 30,
child: ClipOval(
child: Image.file(
controller.image?.value ?? File(""),
width: 200,
height: 200,
fit: BoxFit.fill,
)),
);
} else {
return const EntityLogoPickerWidget();
}
}),
),