簡體   English   中英

如何更改 CupertinoDatePicker 的背景顏色

[英]How can i change the background color of CupertinoDatePicker

我在我的應用程序中使用 CupertinoDatePicker。

Container(
    height: 200,
    padding: const EdgeInsets.all(16.0),
    child: CupertinoDatePicker(
        mode: CupertinoDatePickerMode.date,
        minimumYear: DateTime.now().year,
        onDateTimeChanged: (DateTime value) {
        print(value);
        },
    )

該應用程序正在使用 MaterialApp (MaterialTheme)。 有沒有辦法改變 CupertinoDatePicker 的背景顏色?

這是我嘗試過的(將 CupertinoDatePicker 包裹在 CupertinoTheme 周圍並將顏色設置為黑色),但它不起作用。

Container(
    height: 200,
    padding: const EdgeInsets.all(16.0),
    child: CupertinoTheme(
        data: CupertinoThemeData(
            primaryColor: Colors.black),
        child: CupertinoDatePicker(
        mode: CupertinoDatePickerMode.date,
        minimumYear: DateTime.now().year,
        onDateTimeChanged: (DateTime value) {
            print(value);
        },
        ),
    ),
)

在撰寫本文時,這是不可能的,並且date_picker.dart的源代碼中有一條注釋,內容如下:

// 考慮在未來設置主題的默認背景顏色。 const Color _kBackgroundColor = CupertinoColors.white;

在撰寫本文時,Flutter 已為 Master 頻道上的 CupertinoDatePicker 添加了 backgroundColor 屬性。 https://github.com/flutter/flutter/commit/19cdb21cb67acf51fb9b4e4e7a367d0bcd82fc7b#diff-54c54e67345e65bac63291794f109fd1它在以下版本支持:主機(#39056)v1.10.14 v1.10.13 v1.10.12 v1.10.11 v1.10.10 v1.10.9 V1 .10.8 v1.10.7 v1.10.6 v1.10.5 v1.10.4 v1.10.3 v1.10.2 v1.10.1 v1.10.0 v1.9.7 v1.9.6

您可以按如下方式設置背景顏色:

CupertinoTimerPicker(
     backgroundColor: Colors.black,
     initialTimerDuration: timer,
     mode: CupertinoTimerPickerMode.hms,
     onTimerDurationChanged: (Duration newTimer) {
                                       setState(() {
                                       timer = newTimer;
                     });

如果您為 flutter 應用程序選擇深色主題,則 CupertinoDatePicker 的文本顏色將更改為白色

暫無
暫無

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

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