简体   繁体   English

如何在 Flutter App 的文本域右侧添加美元符号

[英]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('$'),
                                  ),
                            ),
                          ),
                        ],
                      )

If your keyboard doesn't have a dollar sign then you could use the unicode character:\$如果您的键盘没有美元符号,那么您可以使用 unicode 字符:\$ 使用unicode后的结果

Container(
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height,
        color: Colors.white,
        child: Center(
          child: Text("\u0024 2500"),
        ),
      ),

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM