flutter - 如何设置这种文本字段的样式
问题描述
我想设计这种 TextField 的样式。
我面临的主要问题是设计美元部分来引导文本字段。到目前为止,这是我的代码。
/// My Place Bid Text Field
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(4),
),
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
SizedBox(
child: Container(
//width: mySize.width * 0.2,
//height: 50,
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4),
bottomLeft: Radius.circular(4),
),
color: Colors.grey[200]),
child: Text(
"RS \u20B9",
style: TextStyle(fontSize: 24),
),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
labelText: "Place Bid",
labelStyle: TextStyle(fontSize: 24)),
),
),
],
),
),
这给了我输出
我知道这个问题并不复杂,但我还是比较陌生,所以你的帮助将不胜感激。
解决方案
根据您的解决方案。
注意“IntrinsicHeight”小部件。它使孩子内部的所有孩子都具有相同的大小(取决于最大的孩子)。前缀内的“中心”小部件使容器达到最大高度 + 将其中的文本居中。只要确保不要过多地使用 IntrinsicHeight,因为文档声明它有点资源重。
Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
border: Border.all(color: Colors.grey[200]),
),
child: IntrinsicHeight(
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(horizontal: 10.0),
decoration: BoxDecoration(
color: Colors.grey[100],
border: Border(
right: BorderSide(color: Colors.grey[200]),
),
),
child: Center(
child: Text(
'RS \u20B9',
style: TextStyle(fontSize: 24),
),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
border: InputBorder.none,
labelText: "Place Bid",
),
),
),
],
),
),
),
第二个代码几乎相同,只是在 TextField 中键入文本后没有标签。
Container(
margin: EdgeInsets.symmetric(horizontal: 20.0),
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
border: Border.all(color: Colors.grey[200]),
),
child: IntrinsicHeight(
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(horizontal: 10.0),
decoration: BoxDecoration(
color: Colors.grey[100],
border: Border(
right: BorderSide(color: Colors.grey[200]),
),
),
child: Center(
child: Text(
'RS \u20B9',
style: TextStyle(fontSize: 24),
),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(
horizontal: 20.0,
vertical: 20.0,
),
border: InputBorder.none,
hintText: "Place Bid",
),
),
),
],
),
),
),
推荐阅读
- r - 如果字符串包含列表中的元素,则创建新的条件列
- c++ - 将 qDebug 重定向到发出的信号
- javascript - 如何捕获禁用网络推送通知?
- rxjs - Angular 6:“typeof Observable”类型上不存在“of”属性
- ruby-on-rails - 当您可以在 Rails 应用程序中仅包含一行引导程序时,为什么要使用 ruby gem 进行引导程序?
- android - 任务“:app:compileDebugRenderscript”执行失败
- ruby-on-rails - rswag 嵌套对象,rswag 语法
- php - Laravel AWS 简单电子邮件服务错误 SignatureDoesNotMatch(客户端):我们计算的请求签名与您提供的签名不匹配。
- javascript - Angular - 如何获取 JSON 对象的结果?
- javascript - Firestore 规则 - 动态路径