'Does not change the icon after switching the theme
There is an animated_theme_switcher package and assigned a code to change the icon after switching, but it does not change .. what code is needed? Help please .. I will be grateful my code:
Container(
margin: const EdgeInsets.only(
),
child: ThemeSwitcher(
clipper: const ThemeSwitcherCircleClipper(),
builder: (context)
{
return IconButton(
onPressed: () async {
var themeName =
ThemeModelInheritedNotifier
.of(context)
.theme
.brightness ==
Brightness.light
? 'dark'
: 'light';
var service = await ThemeService.instance
..save(themeName);
var theme = service.getByName(themeName);
ThemeSwitcher.of(context).changeTheme(theme: theme);
},
icon: Icon(ThemeModelInheritedNotifier
.of(context)
.theme == Brightness.light ? Icons.light_mode_outlined : Icons.dark_mode_outlined),
);
},
),
),
Solution 1:[1]
Wrap the screen where you want to make them switch with ThemeSwitchingArea widget, as it has shown in the following example:
ThemeSwitchingArea(
child: Builder(builder: (context)
{
return IconButton(
onPressed: () async {
var themeName =
ThemeModelInheritedNotifier
.of(context)
.theme
.brightness ==
Brightness.light
? 'dark'
: 'light';
var service = await ThemeService.instance
..save(themeName);
var theme = service.getByName(themeName);
ThemeSwitcher.of(context).changeTheme(theme: theme);
},
icon: Icon(ThemeModelInheritedNotifier
.of(context)
.theme == Brightness.light ? Icons.light_mode_outlined : Icons.dark_mode_outlined),
);
},);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | marc_s |
