我正在试着改变OutlineInputBorder的边框 colored颜色 ,但是try 了很多方法,都失败了.

我通过buildDarkTheme()函数创建了整个主题配置,但无法将边框 colored颜色 更改为黄色

下面是图片和代码:

enter image description here

import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

const kBlackHalf = const Color(0xFF212121);
const kBlackLight = const Color(0xFF484848);
const kBlack = const Color(0xFF000000);
const kYellow = const Color(0xFFffd600);
const kYellowLight = const Color(0xFFffff52);
const kYellowDark = const Color(0xFFc7a500);
const kWhite = Colors.white;

ThemeData buildDarkTheme() {
  final ThemeData base = ThemeData();
  return base.copyWith(
    primaryColor: kBlack,
    accentColor: kYellow,
    scaffoldBackgroundColor: kBlackHalf,
    primaryTextTheme: buildTextTheme(base.primaryTextTheme, kWhite),
    primaryIconTheme: base.iconTheme.copyWith(color: kWhite),
    buttonColor: kYellow,
    textTheme: buildTextTheme(base.textTheme, kWhite),    
    inputDecorationTheme: InputDecorationTheme(
      border: OutlineInputBorder(
        borderSide: BorderSide(color: kYellow)
      ),
      labelStyle: TextStyle(
        color: kYellow,
        fontSize: 24.0
      ),
    ),
  );
}

TextTheme buildTextTheme(TextTheme base, Color color) {
  return base.copyWith(
    body1: base.headline.copyWith(color: color, fontSize: 16.0),
    caption: base.headline.copyWith(color: color),
    display1: base.headline.copyWith(color: color),
    button: base.headline.copyWith(color: color),
    headline: base.headline.copyWith(color: color),
    title: base.title.copyWith(color: color),
  );
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      theme: buildDarkTheme(),
      home: new HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => new _HomePageState();
}

class _HomePageState extends State<HomePage> {
  String xp = '0';

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        actions: <Widget>[
          new IconButton(
            icon: Icon(Icons.ac_unit),
            onPressed: () {},
          )
        ],
      ),
      body: new Container(
        padding: new EdgeInsets.only(top: 16.0),
        child: new ListView(
          children: <Widget>[
            new InkWell(
              onTap: () {},
              child: new InputDecorator(
                decoration: new InputDecoration(          
                  labelText: 'XP',
                  border: OutlineInputBorder()
                ),
                child: new Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[
                    new Text(this.xp),
                  ],
                ),
              ),
            )
          ],
        ),
      )
    );
  }
}

有关更多参考信息,请访问:

Not able to change TextField Border Color

https://github.com/flutter/flutter/issues/17592

推荐答案

将hintColor添加到您的主题中,如下所示,它应该会更改OutlineInputBorde colored颜色 .

ThemeData buildDarkTheme() {
  final ThemeData base = ThemeData();
  return base.copyWith(
    primaryColor: kBlack,
    accentColor: kYellow,
    scaffoldBackgroundColor: kBlackHalf,
    primaryTextTheme: buildTextTheme(base.primaryTextTheme, kWhite),
    primaryIconTheme: base.iconTheme.copyWith(color: kWhite),
    buttonColor: kYellow,
    hintColor: YOUR_COLOR,
    textTheme: buildTextTheme(base.textTheme, kWhite),    
    inputDecorationTheme: InputDecorationTheme(
      border: OutlineInputBorder(),
      labelStyle: TextStyle(
        color: kYellow,
        fontSize: 24.0
      ),
    ),
  );
}

Flutter相关问答推荐

如何将图像从顶部和底部半向外设置为飘动

Flutter 中不存在URI的目标

如何处理Flutter Riverpod异步通知器中的状态和数据库

'Flutter的无效常数值错误

如何将assets资源 实体类型转换为文件类型?

Flutter :在后台实现振动

升级到Ffltter 3.16后,应用程序栏、背景 colored颜色 、按钮大小和间距都会发生变化

Flutter GestureDetector单击问题-堆叠外面的按钮不可点击

Flutter 中的 setState() 内部是如何工作的?

我无法找到修复此错误的位置,指出无法使用静态访问来访问实例成员

Flutter url_launcher 插件抛出java.lang.IllegalArgumentException:接收器未注册:io.flutter.plugins.urllauncher.WebViewActivity

如何删除或隐藏覆盖

alert 对话框内的 ListView 显示空的透明窗口

String类型不是Widget类型的子类型?在dart 中

如何在 Flutter 中创建 Facebook 创建帖子屏幕?

Flutter 如何要求用户在应用程序中设置电话密码?

使用 mocktail 包进行单元测试时,类型Null不是Future类型的子类型

Flutter Web Responsiveness 效率不高

Android Studio 模拟器屏幕闪烁

在自动完成中 Select 值后保持键盘焦点