input - 颤振输入装饰后缀图标未出现但始终显示十字符号
问题描述
我有以下示例代码。我现在已经设法放置了前缀图标,它工作正常。我想将相同的图标移动到右侧的后缀含义,但它不起作用,但 X 符号它出现了。这是一个屏幕截图。
我添加了以下几行 suffixIcon: IconButton( 但它似乎没有出现,但左侧的前缀看起来非常好。我无法获得右侧的那个。是什么阻止它出现?
下面是我的代码。
class MyHomePageState extends State<MyHomePage> {
// Show some different formats.
final formats = {
//InputType.both: DateFormat("EEEE, MMMM d, yyyy 'at' h:mma"),
//InputType.date: DateFormat('dd/MM/yyyy'),
//InputType.time: DateFormat("HH:mm"),
InputType.date: DateFormat("d MMMM yyyy"),
};
//InputType.date: DateFormat('yyyy-MM-dd'),
// Changeable in demo
InputType inputType = InputType.date;
bool editable = true;
DateTime date;
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: Text(appName)),
body: Padding(
padding: EdgeInsets.all(16.0),
child: ListView(
children: <Widget>[
Form(
//key: _myKey,
child: Column(
children : [
new Container(
width: 200.0,
child:new DateTimePickerFormField(
dateOnly: true,
format: formats[inputType],
editable: false,
validator: (val) {
if (val != null) {
return null;
} else {
return 'Date Field is Empty';
}
},
/*decoration: InputDecoration(
border: InputBorder.none,
labelText: 'From',contentPadding: const EdgeInsets.symmetric(horizontal: 20.0)),*/
decoration: InputDecoration(
hintText: 'To',
border: InputBorder.none,
filled: false,
prefixIcon: Icon(
Icons.arrow_drop_down,
color: Colors.blue,
size: 28.0,
),
suffixIcon: IconButton(
icon: Icon(Icons.arrow_drop_down,size: 28),
onPressed: () {
debugPrint('222');
})),
initialValue: DateTime.now().subtract(new Duration(days: 7)), //Add this in your Code.
),
)
]
),
),
RaisedButton(
onPressed: () {
/*if (_myKey.currentState.validate()) {
_myKey.currentState.save();
} else {
}*/ print("check;");
if(emailController.text.isEmpty){
print("TEST;");
//valid = false;
//emailError = "Email can't be blank!";
//openAlertBox();
Toast.show("Empty Date From", context, backgroundColor: Colors.red );
}
else{
print("not empty;");
final f = new DateFormat('yyyy-MM-dd');
final original = new DateFormat('d MMMM yyyy');
print("Format datre is"+emailController.text);
print("Formate date :"+original.parse(emailController.text).toString());
}
},
child: Text('Submit'),
)
],
),
));
解决方案
我通过仅挑选出您提供的代码重新创建了您的案例,TextFormField
并且能够看到dropdown arrow
as suffixIcon
。
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
height: MediaQuery
.of(context)
.size
.height,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children : [
new Container(
color: Colors.yellow,
width: 200.0,
child: TextFormField(
decoration: InputDecoration(
hintText: 'To',
border: InputBorder.none,
filled: false,
prefixIcon: Icon(
Icons.arrow_drop_down,
color: Colors.blue,
size: 28.0,
),
suffixIcon: IconButton(
icon: Icon(Icons.arrow_drop_down,size: 28),
onPressed: () {
debugPrint('222');
})),
),
)
]
)
),
)
);
}
}
我看到你用作Padding
你body
的回报Scaffold
。尝试将其替换为Center
orContainer
推荐阅读
- templates - PhpStorm 使用变量内的变量创建实时模板
- python - 根据另一个数组中 argmax 的索引从数组中选择值
- c# - Visual Studio 中的数据库问题(c# 和 SQL Server)
- python-3.x - 如何使用 Python Docx 将图像从一个文档中的表格复制到另一个文档
- r - “选择了未知的列”
- python - 有没有办法在 Google Cloud Datastore 中执行阻塞 get() 调用?
- c# - 在每次迭代中处理内存中的对象
- sql - Oracle SQL - 在交货行后选择第一个检验行
- java - 使用 Jackson 将转义的 json 解析为 JsonNode
- java - 如何从段落中提取恒定长度的单词?