flutter - 提示文本未内联显示
问题描述
我正在尝试在文本字段中对齐图标和文本,但是输出与我的计划不同,下面是我的代码:
class _HomeScreenState extends State<HomeScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.account_circle),
iconSize: 30.0,
onPressed: () {
},
),
title: Text('Food Delivery'),
centerTitle: true,
actions: <Widget>[
FlatButton(
child: Text('Cart (${currentUser.cart.length})',
style: TextStyle(color: Colors.white, fontSize: 15.0),),
onPressed: () {
},
)
],
),
body: ListView(
children: <Widget>[
Padding(
padding: EdgeInsets.all(20.0),
child: TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 15.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30.0),
borderSide: BorderSide(width: 0.8)
),
hintText: 'Search Food or Restaurants',
prefixIcon: Icon(Icons.search, size: 30.0,),
suffix: IconButton(
icon: Icon(Icons.clear),
onPressed: () {
},
)
),
),
),
],
),
);
}
}
我看不到问题所在,模拟器上的输出和实际设备上的输出是一样的:
我认为这可能是搜索图标的问题,但是,减小图标的大小并没有改变输出。任何人都可以建议修复以使提示文本与图标内联显示。
解决方案
正如您已经说过的,问题出在后缀/前缀中的图标!所以这是一个替代方案!
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
border: Border.all(color: Colors.white, width: 0.8)),
padding: EdgeInsets.all(10.0),
child: Row(
children: <Widget>[
Icon(
Icons.search,
size: 30.0,
),
SizedBox(width: 10),
Expanded(
child: TextField(
decoration: InputDecoration(
border:InputBorder.none,
contentPadding: EdgeInsets.symmetric(vertical: 15.0),
hintText: 'Search Food or Restaurants',
),
),
),
IconButton(
icon: Icon(Icons.clear),
onPressed: () {},
)
],
),
),
推荐阅读
- python - 之前所有值的列值平均值
- java - 使用 rmi 时出现 java.net.ConnectException
- java - org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; 糟糕的 SQL 语法
- c++ - lambda 中的 [capture] 是什么?
- r - 从数据框中行的每个元素中减去行的最小值,
- android - 在android studio中并排放置的两个垂直线性布局之间添加图像视图的问题
- flutter - 如何从 URL 重定向回 Flutter App?
- python - 将类属性添加到 ModelForm 上的查询集字段
- azure - 每当在我的 azure 虚拟规模集中添加或删除实例时调用 azure 函数
- android - GMS 服务更新会杀死 android 设备中当前正在运行的进程/服务,这些进程/服务依赖于 GMS