I’d like to make a map observable in my controller. But when I wrap the widget that’s using the observable map with Obx(), I get the runtime error that says "[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."
But I thought I had used Obx for the specific widget to be updated.
class PaintingControllerX extends GetxController {
final gridImages = <ui.Image?>[].obs;
}
class PaintingPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
var controller = Get.put<PaintingControllerX>(PaintingControllerX());
return Scaffold(
body: Obx(() => GridWidget(controller.gridImages)), // ERROR
);
}
}
I saw in a different StackOverflow question (Obx widget throws an error) that the problem was resolved by calling the value property on the observed object. But RxMap.value is protected, I can’t use it here. I also noticed there’s a toList() method on RxList, but there’s no corresponding toMap() on RxMap.
How do I use a RxMap with Obx?
2
Answers
Sure, Just use this for widget only. Also you are using list not map.
All though i have not implemented it now. but it should work. If not , then make a comment , i willl test and surely give you an work out. Happy coding.
Your question is a bit confusing.
You mention map, but in the code, there is a list
<ui.Image?>[].obs
.Below is a code for RxMap<String, String> and Obx plus GridView. Each grid item contains both Strings (key and value) from the map. You can apply changes regarding images yourself.
Controller:
Screen: