【问题标题】:Migrating textFieldConfiguration and maxLengthEnforced to new version of flutter将 textFieldConfiguration 和 maxLengthEnforced 迁移到新版本的 flutter
【发布时间】:2022-11-27 05:18:54
【问题描述】:

我的旧代码是

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>'.

我应该怎么办?

【问题讨论】:

    标签: flutter dart migration


    【解决方案1】:

    根据documentation

    使用新的 enum 类型添加了 maxLengthEnforcement 参数 MaxLengthEnforcement,作为现已弃用的布尔值的替代品 maxLengthEnforced 参数

    现在当它是一个布尔值时,在你的代码中 true/false 就足够了,但现在它是一个 enum 所以当你替换最大长度强制最大长度执行,您还需要更改文本字段配置以适应这种变化。简单的替换将不起作用,因此会出现错误。

    【讨论】:

      猜你喜欢
      • 2022-11-10
      • 1970-01-01
      • 2022-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-06
      相关资源
      最近更新 更多