我试图改变边界颜色,OutlineInputBorder但尝试了无数的方式,但失败了.
我通过buildDarkTheme()函数创建了整个主题配置,但我无法将边框颜色更改为黄色
下面是图片和代码:
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),
],
),
),
)
],
),
)
);
}
}
Run Code Online (Sandbox Code Playgroud)
有关更多参考:
小智 20
这是上述问题的解决方案,如果用户未单击 TextField,则使用 enabledBorder,如果用户单击 TextField,则使用focusedBorder。
enabledBorder: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(25.0),
borderSide: BorderSide(color: Colors.pinkAccent ),
),
focusedBorder: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(25.0),
borderSide: BorderSide(color: Colors.pinkAccent ),
),
Run Code Online (Sandbox Code Playgroud)
Bri*_*per 16
像这样添加hintColor到你的主题,它应该更改OutlineInputBorder颜色.
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
),
),
);
}
Run Code Online (Sandbox Code Playgroud)
Jan*_*sen 14
从7月开始,您现在可以使用enabledBorder:
new TextField(
decoration: new InputDecoration(
enabledBorder: const OutlineInputBorder(
// width: 0.0 produces a thin "hairline" border
borderSide: const BorderSide(color: Colors.grey, width: 0.0),
),
border: const OutlineInputBorder(),
labelStyle: new TextStyle(color: Colors.green),
...
),
)
Run Code Online (Sandbox Code Playgroud)
请参阅有关新装饰器的完整文档
Dav*_*ara 12
您只需在 InputDecoration 中给出“enabledBorder”参数即可
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.yellow),
),
Run Code Online (Sandbox Code Playgroud)
小智 6
这会将按钮的轮廓颜色更改为蓝色
new OutlineButton(
borderSide: BorderSide(color: Colors.blue),
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23291 次 |
| 最近记录: |