How to change color of floating action button on theme change ? in flutter

Viewed 370

How to change color of floating action button on theme change ? in flutter and also How can I find out what the current theme is in the app? in flutter

2 Answers

In ThemeData you have the floatingActionButtonTheme property

   ThemeData(
      floatingActionButtonTheme: FloatingActionButtonThemeData(
         focusColor: ,
         hoverColor: ,
         splashColor: ,
         backgroundColor: ,
         foregroundColor: ,  
      ),
   );

Theme is declare in MaterialApp, in theme property

To get Current theme

ThemeData theme = Theme.of(context);

To change Theme

    ThemeData(
//to change primary color
primarySwatch: Colors.red,


//to change only floating action button theme

          floatingActionButtonTheme: FloatingActionButtonThemeData(
        
             backgroundColor: ,
             foregroundColor: ,  
          ),
       );

to get current device theme is Dark theme or not

final brightnessValue = MediaQuery.of(context).platformBrightness;
            bool isDark = brightnessValue == Brightness.dark; 
Related