I am writing code to change Dark/Light Theme using SwitchListTile where I need to use bool type variable.
Issue: The MaterialApp has no Dark/Light Theme bool variable parameter.
Using ValueNotifier and ValueListenableBuilder uses non-bool enum type variable themeNotifier to update Theme.
Here is my code:
This line defines themeNotifier which is not bool type.
static final ValueNotifier<ThemeMode> themeNotifier = ValueNotifier(ThemeMode.light);
This line defines my own isLightThemeMode bool type variable.
static bool isLightThemeMode = (myClassState.themeNotifier.value == ThemeMode.light) ? true : false;
Main Issue: I need to use themeNotifier in the ValueListenableBuilder to change Theme Mode, but there is no bool variable here:
ValueListenableBuilder<ThemeMode>(valueListenable: themeNotifier,builder: (_, ThemeMode currentMode, __)
I should be using bool variable isLightThemeMode in SwitchListTile:
SwitchListTile(title: Text("Theme",style: TextStyle(fontSize: 11)),value: isLightThemeMode,onChanged: (bool value) {{setState(() {isLightThemeMode = value;});}})
This code does not work.
The following code works, but it does not use bool variable isLightThemeMode.
SwitchListTile(title: Text("Theme",style: TextStyle(fontSize: 11)),value: myClassState.themeNotifier.value==ThemeMode.light,onChanged: (bool value) {{setState(() {myClassState.themeNotifier.value = value ? ThemeMode.light: ThemeMode.dark;;});}})
Could you please advice how to use bool variable to change Theme.
Thank You