Flutter   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了dart – Flutter – 更改OutlineInputBorder的边框颜色大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_616_4@ 我正在尝试更改OutlineInputBorder的边框颜色,但尝试了很多方法并失败了.

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

下面是图片代码

dart – Flutter – 更改OutlineInputBorder的边框颜色

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,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到你的主题,它应该更改OutlineInputBorder颜色.

ThemeData buildDarkTheme() {
  final ThemeData base = ThemeData();
  return base.copyWith(
    priMaryColor: kBlack,hintColor: YOUR_COLOR,inputDecorationTheme: InputDecorationTheme(
      border: OutlineInputBorder(),);
}

大佬总结

以上是大佬教程为你收集整理的dart – Flutter – 更改OutlineInputBorder的边框颜色全部内容,希望文章能够帮你解决dart – Flutter – 更改OutlineInputBorder的边框颜色所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。