如何更改 flutter 应用程序键盘颜色?

How to change flutter app keyboard color?

在我的 flutter 中,我创建了一个 TextFormField,但它的键盘颜色在 iOS 中是黑色的,我想知道如何将其更改为白色。

flutter语言版本:>=2.2.2 <3.0.0

这是我关于 TextFormField 的代码:

TextFormField(
     style: TextStyle(
               fontSize: 14,
               color: Colors.black),
               autofocus: false,
               initialValue: 'initial value', 
               maxLines: 1,
               // onSaved: (String value) => _person = value,
               // obscureText: _isObscure,
               validator: (String value) {
                          if (value.isEmpty) {
                            return 'nononono';
                          }
                          return null;
                        },
               decoration: InputDecoration(
                          hintText: 'please make sure',
                          contentPadding: EdgeInsets.fromLTRB(15, 5, 15, 5),
               hintStyle: TextStyle(
                             color: Colors.grey,
                             fontSize: 12,
                             ),
               hasFloatingPlaceholder: false,
               // contentPadding: contentPadding,
               border: InputBorder.none,
               ),
),

当我点击这个 TextFormField

我得到的: 黑色键盘

我想要的: 白色键盘

白色键盘使用Brightness.light

黑色键盘使用Brightness.dark

    body: Center(
            child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
                TextField(
                    keyboardType: TextInputType.text,
                    keyboardAppearance: Brightness.light, // no matter what you set, it simply shows white keyboard
                )
            ],
            ),
        )

如果您使用 ThemeData 作为应用程序的全局样式,您可以设置 primaryColorBrightness。如果没有为 keyboardAppearance.

指定值,文本字段的键盘将使用此亮度(亮或暗)
final ThemeData themeDark = ThemeData(
  primaryColorBrightness: Brightness.dark,
  // ...
);

这样做的好处是您不必为每个文本字段定义 keyboardAppearance

https://api.flutter.dev/flutter/material/TextField/keyboardAppearance.html