如何设置InputDecoration的OutlineInputBorder的样式? [英] How to style the OutlineInputBorder of InputDecoration?

查看:857
本文介绍了如何设置InputDecoration的OutlineInputBorder的样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置TextFormField的边框的样式.我将它与OutlineInputBorder一起使用.默认情况下,它采用近乎黑色的颜色,对焦时则采用原色.我试图更改BorderSide的颜色,但是没有用.

I am trying to style the border of TextFormField. I'm using it with an OutlineInputBorder. It by default takes an almost black color and on focus takes primary color. I tried to change color of the BorderSide but it ain't worked.

我还尝试了在Flutter中更改TextField的下划线中提到的解决方法,但没有任何变化.

I also tried the workarounds mentioned at Change TextField's Underline in Flutter for UnderlineInputBorder, but nothing changes.

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),
        )
    ),
),

推荐答案

深入研究之后,似乎只能由ThemeData对其进行配置.所以我只是添加了一个主题小部件.

After digging deep, it seems like it's only configurable by ThemeData. So I simply added a Theme widget.

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;
  }

这篇关于如何设置InputDecoration的OutlineInputBorder的样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆