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

Issue

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

Solution

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; 

Answered By – Fuad Saneen

Answer Checked By – Katrina (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.