[英]How to Add Dollar Sign on the RIght hand Side of the Textfield in Flutter App
how can we achieve like... Added Below Example for it..我们怎样才能实现...为其添加了下面的示例..
https://i.imgur.com/fzwvHte.mp4 https://i.imgur.com/fzwvHte.mp4
This is the Code I am Working on it.这是我正在处理的代码。
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("Exchange"),
SizedBox(width: 20),
Container(
width: width / 2,
child: TextFormField(
textAlign: TextAlign.right,
keyboardType: TextInputType.number,
textDirection: TextDirection.rtl,
decoration: const InputDecoration(
border: InputBorder.none,
hintText: "0",
isDense: true,
prefix: Text(
"\$",
textAlign: TextAlign.right,
textDirection: TextDirection.rtl,
),
prefixStyle: TextStyle()),
),
),
],
),
你不能只使用 suffixIcon 属性吗?
suffixIcon: Text('$')
**This is how can u do it on your code . thanks**
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("Exchange"),
SizedBox(width: 20),
Container(
width: width / 2,
child: TextFormField(
textAlign: TextAlign.right,
keyboardType: TextInputType.number,
textDirection: TextDirection.rtl,
decoration: const InputDecoration(
border: InputBorder.none,
hintText: "0",
isDense: true,
suffixIcon: Text('$'),
),
),
),
],
)
I think you can use the inputFormatters to achieve this as follows:我认为您可以使用 inputFormatters 来实现此目的,如下所示:
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("Exchange"),
SizedBox(width: 20),
Container(
width: width / 2,
child: TextFormField(
textAlign: TextAlign.right,
keyboardType: TextInputType.number,
textDirection: TextDirection.rtl,
inputFormatters: [
TextInputFormatter.withFunction(oldValue,newValue)=>
newValue.copyWith(text:newValue.text.contains("$") ?newValue.text : "\$ ${newValue.text}")
]
),
],
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.