在Flutter中,我有一个下拉列表(我们可以称为maxim字段)来选择总长度。然后在索引字段中,我们可以添加具有相同长度的下拉列表的值。当我在索引字段中添加值时,我需要添加“ .000”。
我尝试使用masked package,但无法连接索引字段值。
代码类似于
int inputMaxValue=1;
var inputIndexValue = new MaskedTextController(mask: inputMaxValue.text+'.000');
返回
在初始化器中只能访问静态成员
¿有人知道我可以解决此问题吗?
答案 0 :(得分:0)
我认为MaskedTextController
在您的情况下是不必要的,只需将int inputMaxValue
更改为double inputMaxValue
并可能加.toStringAsFixed(3)
即可在点后添加3个小数。
例如
double inputMaxValue = 1.0;
String inputIndexValue = "${inputMaxValue.toStringAsFixed(3)}";
但是,如果要保留flutter_masked_text
包-应该避免为mask
属性使用动态字符串。错误Only static members can be accessed in initializers
的出现可能是因为您在类中而不是在其封闭方法(例如initState
)中声明了带掩码的控制器变量。
对于MaskedTextController
,mask
属性只能使用静态字符串。
例如这就是我用来格式化电话号码字段的方式:
MaskedTextController(mask: "(000) 000-0000")
答案 1 :(得分:0)
也许NumberFormat可以帮助
$response .= " <button id='toothEndo' class='toothEndo' name='toothEndo'> ENDO </button> "
import 'package:intl/intl.dart';
输出:123.00