dart 将textFieldConfiguration和maxLengthEnforced迁移到新版本的flutter

zpgglvta  于 2022-12-06  发布在  Flutter
关注(0)|答案(1)|浏览(525)

我的旧代码是

maxLengthEnforced: widget.textFieldConfiguration.maxLengthEnforced,

它会产生错误

Error: No named parameter with the name 'maxLengthEnforced'.

一些指南说我应该用maxLengthEnforcement替换maxLengthEnforced。但是新代码:

maxLengthEnforcement: widget.textFieldConfiguration.maxLengthEnforcement,

给出新错误:

The getter 'maxLengthEnforcement' isn't defined for the class 'TextFieldConfiguration<dynamic>'.

我该怎么办?

eblbsuwk

eblbsuwk1#

根据documentation
使用新的enum类型MaxLengthEnforcement添加了maxLengthEnforcement参数,以替换现已弃用的布尔型maxLengthEnforced参数
现在,当它是布尔值时,在代码中使用true/false就足够了,但现在它是enum,因此当您将maxLengthEnforced替换为maxLengthEnforcement时,还需要在 textFieldConfiguration 中进行更改以适应此更改。简单的替换将不起作用,因此出现错误。

相关问题