GregoryConrad / rearch-dart

Re-imagined approach to application design and architecture
https://pub.dev/packages/rearch
MIT License
92 stars 4 forks source link

RearchConsumer with data passed in via constructor not getting rebuilds #163

Closed GregoryConrad closed 6 months ago

GregoryConrad commented 6 months ago

Discussed in https://github.com/GregoryConrad/rearch-dart/discussions/161

Minimal reproducible example:

class Parent extends StatefulWidget {
  const Parent({super.key});

  @override
  State<Parent> createState() => _ParentState();
}

class _ParentState extends State<Parent> {
  int count = 0;
  @override
  Widget build(BuildContext context) {
    return TextButton(
      onPressed: () => setState(() => count++),
      // child: Child1(count),
      child: ChildConsumer(count),
    );
  }
}

class Child1 extends StatelessWidget {
  const Child1(this.i, {super.key});
  final int i;
  @override
  Widget build(BuildContext context) {
    return Text('$i');
  }
}

class ChildConsumer extends RearchConsumer {
  const ChildConsumer(this.i, {super.key});
  final int i;
  @override
  Widget build(BuildContext context, WidgetHandle use) {
    print('$i');
    return Text('$i');
  }
}

The ChildConsumer is not being rebuilt with the new state.

Originally posted by **busslina** April 28, 2024 So, In my way back to `rearch_flutter` I had a problem for 30 minutes trying to figuring out why a `RearchConsumer` was not refreshing, and it was because I was passing it data on its constructor (like with State(less/ful)Widgets). So my question is what would be the preferred way to handle a situation when you need a `RearchConsumer` but also you need to pass it some values (that could change over the time) via its constructor? Would you advice against that "mixin" even if you know the passed values should not change over the time?
busslina commented 6 months ago

That was fast, thanks again.