Search code examples
flutterdartflutter-getxflutter-theme

Flutter GetX Custom Theme for Button


I have written my custom theme like this and stored it in Get storage.

class Themes {
  static final lightTheme = ThemeData(
    brightness: Brightness.light,
    colorScheme: const ColorScheme.light(),
    outlinedButtonTheme: OutlinedButtonThemeData(
      style: OutlinedButton.styleFrom(
        textStyle: TextStyle(
          color: CustomColor.lightLandingScreenTextColor,
        ),
      ),
    ),
  );

  static final darkTheme = ThemeData(
    brightness: Brightness.dark,
    colorScheme: const ColorScheme.dark(),
    outlinedButtonTheme: OutlinedButtonThemeData(
      style: OutlinedButton.styleFrom(
        backgroundColor: Colors.red,
        textStyle: TextStyle(
          color: CustomColor.darkLandingScreenTextColor,
        ),
      ),
    ),
  );
}

Then I tried to apply my outlinedbutton theme on my outlinedbutton like this

SizedBox(
  height: 48.h,
  width: 155.w,
  child: OutlinedButton(
           onPressed: () {},
           child: Text("SKIP"),  
           style: OutlinedButton.styleFrom(),
         ),)

I also tried to assign a theme like this but this gave me an error.

enter image description here

Now how can I assign that custom button theme to my button? I am using GetX for state management.


Solution

  • Try to use like this

    style: context.theme.outlinedButtonTheme.style
    

    you are trying to add OutlinedButtonThemeData in a parameter type 'ButtonStyle?' that's why giving error.