簡體   English   中英

Flutter GetX 按鈕自定義主題

[英]Flutter GetX Custom Theme for Button

我已經像這樣編寫了我的自定義主題並將其存儲在 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,
        ),
      ),
    ),
  );
}

然后我嘗試像這樣在我的輪廓按鈕上應用我的輪廓按鈕主題

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

我也嘗試像這樣分配主題,但這給了我一個錯誤。

在此處輸入圖像描述

現在如何在我的按鈕中分配自定義按鈕主題? 我正在使用 GetX 進行 state 管理。

嘗試像這樣使用

style: context.theme.outlinedButtonTheme.style

您正在嘗試在參數類型“ButtonStyle”中添加OutlinedButtonThemeData 'ButtonStyle?' 這就是為什么給出錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM