【问题标题】:How to prefix two decimal number in textfield如何在文本字段中添加两个十进制数字
【发布时间】:2021-08-19 02:56:37
【问题描述】:

我是 Flutter 的新手,想知道是否可以在文本字段中为数字加上小数前缀。前缀编号为 0.00,不应删除。

<blockquote class="imgur-embed-pub" lang="en" data-id="VnFQQlo"><a href="https://imgur.com/VnFQQlo">View post on imgur.com</a></blockquote><script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script>

到目前为止,我已经尝试过类似有限的两位小数输入。

 CupertinoFormRow(
                  child: CupertinoTextFormFieldRow(
                    controller: controller.price,
                    onChanged: (value) {
                      controller.calTotal(controller.qty.text, value);
                    },
                    placeholder: "Enter item price",
                    inputFormatters: [
                      FilteringTextInputFormatter.allow(
                          RegExp(r'^\d+\.?\d{0,2}')),
                    ],
                  ),
                  prefix: Text('0.00'),
                ), 

【问题讨论】:

  • 我无法重现您的代码。请分享controller 变量的虚拟代码。

标签: flutter flutter-web


【解决方案1】:

使用currency_text_input_formatter

CupertinoFormRow(
      child: CupertinoTextFormFieldRow(
      controller: controller.price,
      onChanged: (value) {
         controller.calTotal(controller.qty.text, value);
           },
      placeholder: "Enter item price",
      inputFormatters: [
           CurrencyTextInputFormatter(decimalDigits: 2),
                  ],
              ),
       ),

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多