0

Im trying to display my stateList (List) and getting it updated with getX when the content of the stateList changes, but Obx only works for single widgets?.

Im currently using the spread operator (…) to display the Widgets in stateList. How can i get my Widget to rebuild when my stateList changes(add, remove..)?

class Designer extends StatelessWidget {
  final DesignerController c = Get.put(DesignerController());

  @override
  Widget build(BuildContext context) {
    print("rebuilds");
    return Scaffold(
        body: ArrowContainer(
            child: Container(
                child: Stack(children: <Widget>[
         
          ...c.stateList,

        ]))),
        floatingActionButton:
            Row(mainAxisAlignment: MainAxisAlignment.center, children: [
          FloatingActionButton(
              child: Icon(Icons.add), onPressed: c.addNewState("C1")),
          FloatingActionButton(
              child: Icon(Icons.remove),
              onPressed: () {
                c.addNewState("C2");
                c.stringList.add("Test");
              }),
          FloatingActionButton(
              child: Icon(Icons.clear),
              onPressed: () {
                c.count.value++;
              }),
        ]));
  }
}
class DesignerController extends GetxController {
  final List<Widget> stateList = <Widget>[].obs;

  addNewState(String stateName) {
    StateModel newState = StateModel(
        key: UniqueKey(), offset: Offset(0, 0), stateName: stateName);
    stateList.add(newState);
  }

SynX
  • 1

1 Answers1

0

Solved by wrapping the whole Stack with Obx

Obx(
      () => Stack(children: <Widget>[
        ...c.stateList,
      ]),
SynX
  • 1