ookami-kb / storybook_flutter

A storybook for Flutter widgets.
https://pub.dev/packages/storybook_flutter
MIT License
284 stars 63 forks source link

Hot-reload causes Story (and thus widgets) to be rebuilt / reinitialised #123

Closed bramp closed 11 months ago

bramp commented 11 months ago

It's unclear if this is intentional, but when hot-reloading, the Stories are rebuilt causing any Stateful widgets to lose their state and reload.

return Storybook(
      stories: [
        Story(
          name: 'Test,
          builder: (context) {
            return TestWidget();
          }
        )
      ]
);
class TestWidget extends StatefulWidget {
  const TestWidget({super.key});

  @override
  State<TestWidget> createState() => _TestWidgetState();
}

class _TestWidgetState extends State<TestWidget> {
  @override
  initState() {
    super.initState();
    print('initState');
  }

  @override
  Widget build(BuildContext context) {
    return const Placeholder();
  }
}

Hot-reload is meant to preserve state, so is this a bug? or intentional feature to help in testing stateful widgets?

bramp commented 11 months ago

You know what, this might be a problem I've caused outside of Storybook. Sorry for the noise.