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't get the plugin changes to take effect #5

Closed
Zaxist opened this issue Aug 29, 2018 · 5 comments
Closed

Can't get the plugin changes to take effect #5

Zaxist opened this issue Aug 29, 2018 · 5 comments

Comments

@Zaxist
Copy link

Zaxist commented Aug 29, 2018

In main.dart I have this:

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return new DynamicTheme(
      defaultBrightness: Brightness.light,
      data: (brightness) => new ThemeData(
        primarySwatch: Colors.pink,
        primaryColorBrightness: Brightness.dark,
        accentColor: Colors.lightBlue
      ),
      themedWidgetBuilder: (context, theme) {
        return new MaterialApp(
          title: 'Top Tens',
          theme: theme,
          home: new LandingPage(title: 'TOP TENS'),
        );
      }
    );


    
  }
}

and on a screen later on in the app I call this method:

 _setTheme() {
    DynamicTheme.of(context).setBrightness(Brightness.dark);
}

but nothing happens, and there is no error thrown. Any ideas what I may have done wrong?

@Zaxist
Copy link
Author

Zaxist commented Aug 29, 2018

I used

DynamicTheme.of(context).setThemeData(new ThemeData(
    brightness: Brightness.dark
));

instead of

DynamicTheme.of(context).setBrightness(Brightness.dark);

as suggested in #3 (comment)

It works. Strange that the setBrightness method doesn't seem to work though.

@Norbert515
Copy link
Owner

Sorry for the late response, I didn't see the issue.
The problem is that you are not using the given brightness in the builder at:

      data: (brightness) => new ThemeData(
        primarySwatch: Colors.pink,
        primaryColorBrightness: Brightness.dark,
        accentColor: Colors.lightBlue
      ),

If you do brightness: brightness, it should work

@NewITCorp
Copy link

Personally I dont even use DynamicTheme.of(context).setBrightness() at all.
only DynamicTheme.of(context).setThemeData() is enough because brightness is already in a themedata.

thanks for a nice library. please put it to dart pub.

@Norbert515
Copy link
Owner

Thanks! Currently, only the brightness value is persisted in the shared preferences, meaning if you use setThemeData() the values will reset when you restart the app. If that's the desired behavior, perfect!

@Norbert515
Copy link
Owner

It's on pub!

@Norbert515 Norbert515 reopened this Nov 4, 2018
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

3 participants