I am implementing switch to change Theme in my application.
As switch value I am using Theme.of(context).brightness == Brightness.dark
and switch it's not working (I can drag switch but he is coming back to his position)
When I change value to Theme.of(context).brightness == Brightness.light
switch is working but I need it in first option.
here is my switch code:
Switch(
value: Theme.of(context).brightness == Brightness.dark,
onChanged: (brightness) async {
print(brightness);
await MySecureStorage().writeData('theme', brightness ? 'dark' : 'light');
Provider.of<MainProvider>(context, listen: false).changeThemeMode(brightness ? ThemeMode.light : ThemeMode.dark);
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: brightness
? Brightness.dark
: Brightness.light
)
);
},
)
and why is compared to Brightness.dark
it's not working? What I am missing?