简体   繁体   English

Flutter GetX 按钮自定义主题

[英]Flutter GetX Custom Theme for Button

I have written my custom theme like this and stored it in Get storage.我已经像这样编写了我的自定义主题并将其存储在 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 theme like this but this gave me an error.我也尝试像这样分配主题,但这给了我一个错误。

在此处输入图像描述

Now how can I assign that custom button theme in my button?现在如何在我的按钮中分配自定义按钮主题? I am using GetX for state management.我正在使用 GetX 进行 state 管理。

Try to use like this尝试像这样使用

style: context.theme.outlinedButtonTheme.style

you are trying to add OutlinedButtonThemeData in a parameter type 'ButtonStyle?'您正在尝试在参数类型“ButtonStyle”中添加OutlinedButtonThemeData 'ButtonStyle?' that's why giving error.这就是为什么给出错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM