Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you guys add multi themes? #33

Closed
AndersonOli opened this issue Jul 20, 2021 · 5 comments
Closed

Can you guys add multi themes? #33

AndersonOli opened this issue Jul 20, 2021 · 5 comments

Comments

@AndersonOli
Copy link

Hi guys, I was testing your lib, congrats, thats great! I'm here to ask if its possible put more than two themes? How can i do it? I was trying wrap the StoryBook with a Provide but the routes crashes rs

thanks

@ookami-kb
Copy link
Owner

Hello, thanks!

I'm here to ask if its possible put more than two themes? How can i do it?

Do you mean something besides dark/light theme? The point is that dark/light can be synchronized with system settings, but you can pass any ThemeData to the Storybook.

I was trying wrap the StoryBook with a Provide but the routes crashes

That's probably a bug. Could you provide some reproducible example, please?

@AndersonOli
Copy link
Author

Hi folks!

Below the code that I'm running:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (_) => ThemeServices(),
      child: Builder(builder: (BuildContext context) {
        return StoryBook();
      }),
    );
  }
}

But, I would like use like this:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (_) => ThemeServices(),
      child: Builder(builder: (BuildContext context) {
        ThemeData theme = Provider.of<ThemeServices>(context).currentTheme;
        return MaterialApp(
          theme: theme,
          home: StoryBook()
        );
      }),
    );
  }
}

in first case I had a problem when trying acess routes of the storybook;

What I come across:


Make sure your root app widget has provided a way to generate
this route.
Generators for routes are searched for in the following order:
 1. For the "/" route, the "home" property, if non-null, is used.
 2. Otherwise, the "routes" table is used, if it has an entry for the route.
 3. Otherwise, onGenerateRoute is called. It should return a non-null value for any valid route not handled by "home" and "routes".
 4. Finally if all else fails onUnknownRoute is called.
Unfortunately, onUnknownRoute was not set.
When the exception was thrown, this was the stack

packages/flutter/src/widgets/app.dart 1228:9                                  <fn>
packages/flutter/src/widgets/app.dart 1242:14                                 [_onUnknownRoute]
packages/flutter/src/widgets/navigator.dart 4170:22                           [_routeNamed]
packages/flutter/src/widgets/navigator.dart 4280:35                           pushReplacementNamed
...
Handler: "onTap"
Recognizer: TapGestureRecognizer#d3469
    debugOwner: GestureDetector
    state: ready
    won arena
    finalPosition: Offset(41.6, 73.0)
    finalLocalPosition: Offset(41.6, 24.0)
    button: 1
    sent tap down

@AndersonOli
Copy link
Author

The whole code can be accessed in this repo.

@ookami-kb
Copy link
Owner

The storybook uses MaterialApp under the hood, so yeah, this one won't work:

return MaterialApp(
          theme: theme,
          home: Storybook()
        );

But you can pass the theme directly to the Storybook:

return Storybook(
  theme: theme,
)

In that case, it should work.

@AndersonOli
Copy link
Author

Well, thats make sense, I didnt notice it; Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants