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

toggle theme on icon button click bug #42

Closed
yagizdo opened this issue Jul 7, 2022 · 3 comments
Closed

toggle theme on icon button click bug #42

yagizdo opened this issue Jul 7, 2022 · 3 comments

Comments

@yagizdo
Copy link

yagizdo commented Jul 7, 2022

Describe the bug
Thank you for preparing such a package first of all. When I assign the toggletheme code to the icon button, it does not detect some clicks. It works when I click it again.

When I first open the application, the theme does not change at the first click. It changes when I click it for the second time. Nothing happens on the first click.

Smartphone

  • Device: iPhone 11 Simulator
  • OS: iOS 13.0
  • Version : flutter version 3.0.3, adaptive theme version 3.1.0

Bug Video :

Kapture.2022-07-07.at.14.02.48.mp4

Codes :

app.dart

 class MyApp extends StatelessWidget {
  MyApp({Key? key,required this.savedThemeMode}) : super(key: key);
  var savedThemeMode;
  @override
  Widget build(BuildContext context) {
    // App Theme
    final appTheme = AppTheme();
    return AdaptiveTheme(
      light: appTheme.lightTheme,
      dark: appTheme.darkTheme,
      initial: savedThemeMode ?? AdaptiveThemeMode.light,
      builder: (theme,darkTheme) => MaterialApp(
        title: 'Material App',
        theme: theme,
        darkTheme: darkTheme,
        home: const HomeView(),
      ),
    );
  }
} 

homeView.dart

class HomeView extends StatelessWidget {
  const HomeView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Home View'),
        actions: [
          IconButton(
            icon: Icon(Icons.settings),
            onPressed: () {
              AdaptiveTheme.of(context).toggleThemeMode();
            },
          ),
        ],
      ),
      body: Center(
        child: Container(
          child: Text('Hello World'),
        ),
      ),
    );
  }
} 
@BirjuVachhani
Copy link
Owner

@yagizdo This is not a bug. Its an expected behavior. AdaptiveTheme supports 3 theme modes: Light, dart and System. Calling AdaptiveTheme. toggleThemeMode() goes through all 3.

So, for example, your OS is running in light mode and you are also on light mode in the app and then if you toggle theme mode, it may go from light -> system mode where system mode also is light so you see no change. Then when you toggle again, it may go to dark mode and you see the change.

It seems that you wanna toggle between only light and dark, not the system. So, instead of calling toggleThemeMode() do this:

final manager  = AdaptiveTheme.of(context);
if(manager.mode.isLight){
  manager.setDark();
}else {
  manager.setLight();
}

@yagizdo
Copy link
Author

yagizdo commented Jul 11, 2022

@yagizdo This is not a bug. Its an expected behavior. AdaptiveTheme supports 3 theme modes: Light, dart and System. Calling AdaptiveTheme. toggleThemeMode() goes through all 3.

So, for example, your OS is running in light mode and you are also on light mode in the app and then if you toggle theme mode, it may go from light -> system mode where system mode also is light so you see no change. Then when you toggle again, it may go to dark mode and you see the change.

It seems that you wanna toggle between only light and dark, not the system. So, instead of calling toggleThemeMode() do this:

final manager  = AdaptiveTheme.of(context);
if(manager.mode.isLight){
  manager.setDark();
}else {
  manager.setLight();
}

Oh okay I get it. Sorry my bad @BirjuVachhani

@yagizdo yagizdo closed this as completed Jul 11, 2022
@BirjuVachhani
Copy link
Owner

@yagizdo Np. Glad I could help😊

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