首页 > 解决方案 > 如何设置 InputDecoration 的 OutlineInputBorder 样式?

问题描述

我正在尝试设置TextFormField. 我将它与OutlineInputBorder. 默认情况下,它采用几乎黑色的颜色,而在焦点上采用原色。我试图改变它的颜色,BorderSide但它不起作用。

我还尝试了Change TextField's Underline in Flutter for中提到的解决方法UnderlineInputBorder,但没有任何改变。

new TextFormField(
    decoration: new InputDecoration(
        labelText: "Email",
        contentPadding: new EdgeInsets.all(12.0),
        filled: true,
        border: new OutlineInputBorder(
            borderSide: new BorderSide(width: 2.0, color: Colors.white),
        )
    ),
),

标签: flutter

解决方案


深入挖掘后,似乎只能由 ThemeData 配置。所以我只是添加了一个主题小部件。

body: Theme(data: Theme.of(context).copyWith(
          primaryColor: Colors.white,
          accentColor: Colors.amber
      ), child: new TextFormField(
          decoration: new InputDecoration(
          labelText: "Email",
          contentPadding: new EdgeInsets.all(12.0),
      ),
),

input_decorator.dart#1440-1450

Color _getActiveColor(ThemeData themeData) {
    if (isFocused) {
      switch (themeData.brightness) {
        case Brightness.dark:
          return themeData.accentColor;
        case Brightness.light:
          return themeData.primaryColor;
      }
    }
    return themeData.hintColor;
  }

推荐阅读