'Flutter IconTheme won't apply
I have a simple flutter app that will switch theme on button pressed, while the overall theme is applied some that I had defined before doesn't seem to be applied in my widget, like when I define default color of Icon to green like this:
final ThemeData themeDark = ThemeData.dark().copyWith(
  iconTheme: IconThemeData(
    color: Colors.green,
  ),
);
when I use it in my floating action button icon it still uses the default IconTheme
class SwitchThemeButton extends StatelessWidget {
  SwitchThemeButton({Key? key, required this.onPressed}) : super(key: key);
  final VoidCallback onPressed;
  @override
  Widget build(BuildContext context) {
    return FloatingActionButton(
      child: Icon(
        Icons.favorite,
// This won't work unless I manually assign it!
//         color: IconTheme.of(context).color,
      ),
      onPressed: onPressed,
    );
  }
}
Can somebody point it up where I'm doing it wrong? This is how the full code looks like by the way.
Full code:
import 'package:flutter/material.dart';
void main() {
  runApp(MyApp());
}
final ThemeData themeDark = ThemeData.dark().copyWith(
  iconTheme: IconThemeData(
    color: Colors.green,
  ),
);
final ThemeData themeLight = ThemeData.light();
class MyApp extends StatefulWidget {
  @override
  MyAppState createState() => MyAppState();
}
class MyAppState extends State<MyApp> {
  final _isDarkTheme = ValueNotifier<bool>(true);
  @override
  Widget build(BuildContext context) {
    return ValueListenableBuilder<bool>(
      valueListenable: _isDarkTheme,
      builder: (context, bool isDark, _) => MaterialApp(
        theme: themeLight,
        darkTheme: themeDark,
        themeMode: isDark ? ThemeMode.dark : ThemeMode.light,
        home: Scaffold(
          body: Stack(
            children: [
              Align(
                alignment: Alignment.center,
                child: MyWidget(),
              ),
              Align(
                alignment: Alignment.bottomRight,
                child: SwitchThemeButton(onPressed: _switchTheme),
              ),
            ],
          ),
        ),
      ),
    );
  }
  void _switchTheme() {
    _isDarkTheme.value = !_isDarkTheme.value;
  }
}
class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Text('Make me green!', style: Theme.of(context).textTheme.headline4);
  }
}
class SwitchThemeButton extends StatelessWidget {
  SwitchThemeButton({Key? key, required this.onPressed}) : super(key: key);
  final VoidCallback onPressed;
  @override
  Widget build(BuildContext context) {
    return FloatingActionButton(
      child: Icon(
        Icons.favorite,
//         color: IconTheme.of(context).color,
      ),
      onPressed: onPressed,
    );
  }
}
							
						Solution 1:[1]
i use this to change the icon color on floatButton
 ThemeData lightTheme = ThemeData(
 colorScheme: ThemeData().colorScheme.copyWith(
 onSecondary :  Colors.orange,
 ),);
    					Solution 2:[2]
The color of the Icon in theFloatingActionButton will be assigned based on Theme.of(context).accentColor.
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 | Abdulkarim | 
| Solution 2 | Andrej | 
