Reputation:
I would like to achieve that the icon of my dark / light button changes accordingly when the mode is activated, that is, I would like a sun icon in ligt mode and a moon icon in dark mode. I found different solutions for this, but I can't use them, maybe who can help? It could be that the code is broken down incorrectly because I'm a newbie and I can't get it right: /
Padding(
padding: const EdgeInsets.only(left: 40),
child: ClipOval(
child: Material(
color: Color(0xFF282C39),
child: InkWell(
splashColor: Colors.blue,
child: SizedBox(width: 32, height: 32, child: Icon(Icons.brightness_2, size: 20, color: Colors.white)),
onTap: () {
isDark
? Magazin.of(context)!
.setBrightness(Brightness.light)
: Magazin.of(context)!
.setBrightness(Brightness.dark);
},
),
),
),
),
Upvotes: 1
Views: 3061
Reputation: 3557
The reason why your Icon doesn't change because you set your icon always to Icons.brightness_2
. You should check if it is using dark/light theme before.
Icon(
isDark ? Icons.brightness_4 : Icons.brightness_2,
size: 20,
color: Colors.white,
),
Upvotes: 1