states_rebuilder icon indicating copy to clipboard operation
states_rebuilder copied to clipboard

[Question] How to work with multiple files which need to access and update the same state?

Open basic-bhavya opened this issue 3 years ago • 1 comments

Like if I have a widget with structure

Injector(
        inject: <Injectable>[Inject(() => MyState())],
        builder: (context) {
            ReactiveModel<MyState> myState =
                Injector.getAsReactive<MyState>();
                return SomeWidget(
                    child: ChildWidget(),
                )
        }
)

Where MyState can be anything but let's assume

class MyState {
  String? name;
  int? id;

  MyState({this.name, this.id});

  setName(String myName){
        name = myName;
    }

  setId(int myId){
        id = myId;
    }
}

Now I want to access / update myState from ChildWidget which is in a different dart file. I could not find help on this in docs. What should be the right way to go about it?

basic-bhavya avatar Jan 28 '22 20:01 basic-bhavya

You can check the example folders for up-to-date examples. https://github.com/GIfatahTH/states_rebuilder/tree/master/examples

topcheese avatar Feb 01 '22 02:02 topcheese