【问题标题】:Change Background and text color of Time Picker button in Flutter在 Flutter 中更改时间选择器按钮的背景和文本颜色
【发布时间】:2022-01-13 10:10:42
【问题描述】:

我是 Flutter 新手,想实现一个 Time Picker,但是我无法更改 cancelok 按钮的背景。

预期:

我正在使用以下代码作为按钮主题

textButtonTheme: TextButtonThemeData(
  style: TextButton.styleFrom(
    primary: Color(0xFF2B2B2B),
    side: BorderSide(
     width: 1.5,
     color: Color(0xFFC5C5C5),),
     padding: EdgeInsets.fromLTRB(18, 12, 18, 12),
     elevation: 1,
  ),

谁能帮我解决这个问题?

【问题讨论】:

    标签: flutter flutter-layout timepicker


    【解决方案1】:

    使用ButtonStyle 的属性backgroundColor

    代码示例

    MaterialApp(
      theme: ThemeData.dark().copyWith(
        scaffoldBackgroundColor: darkBlue,
        textButtonTheme: TextButtonThemeData(
          style: TextButton.styleFrom(
            backgroundColor: Colors.red, // Use this
            side: const BorderSide(
              width: 1.5,
              color: Color(0xFFC5C5C5),
            ),
          ),
        ),
      ),
      // ...
    )
    

    Try the full example on DartPad

    截图

    【讨论】:

    • 但是按钮的背景颜色还是一样的
    • @amanbisht39 好的,你想要的是cancelok 有两种不同的按钮样式。这可能需要重新实现TimePickerDialog,因为您无权访问这些属性。
    猜你喜欢
    • 1970-01-01
    • 2012-05-30
    • 1970-01-01
    • 2021-10-30
    • 2020-11-07
    • 2013-10-24
    • 1970-01-01
    • 1970-01-01
    • 2017-08-31
    相关资源
    最近更新 更多