ookami-kb / storybook_flutter

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

Support for themes #120

Closed guilhermedaldim closed 1 year ago

guilhermedaldim commented 1 year ago

Hey man, thanks for your package, it's very good!

How to use custom themes coming from another package (own library)?

Thanks!

ookami-kb commented 1 year ago

Hey, thanks!

Do you mean to wrap the whole app in one custom theme? For that, you can provide a custom wrapperBuilder to wrap each story in the custom theme. If you mean switching custom themes in the storybook in runtime, I guess, you'll need to write a custom plugin – you can check how the default theme switcher is implemented: https://github.com/ookami-kb/storybook_flutter/blob/master/packages/storybook_flutter/lib/src/plugins/theme_mode.dart

guilhermedaldim commented 1 year ago

Yes man, I want to change the whole app to the selected theme.

Can you show me an example code?

ookami-kb commented 1 year ago

If it's based on the Flutter material theme data, it can be something like this:

  @override
  Widget build(BuildContext context) => Storybook(
        initialStory: 'Screens/Scaffold',
        wrapperBuilder: (context, child) => MaterialApp(
          title: 'Storybook Flutter',
          theme: CustomTheme(),
          home: child,
        ),
        stories: [

If it's totally custom widget, you can wrap the child:

  @override
  Widget build(BuildContext context) => Storybook(
        initialStory: 'Screens/Scaffold',
        wrapperBuilder: (context, child) => MaterialApp(
          title: 'Storybook Flutter',
          home: CustomTheme(child: child),
        ),
        stories: [
guilhermedaldim commented 1 year ago

Hey man, this works, thanks for your help!