
我理解final关键字的作用.我不明白为什么用扩展Widget类的每个实例变量声明它.@H_403_4@解决方法 因为StatefulWidget继承了标记为@immutable的Widget,所以StatefulWidget的任何子类也必须是不可变的(即所有字段都是final).
如果使用非final字段创建StatefulWidget子类,则会产生此DartAnalysis警告:
info: This class inherits from a class marked as @immutable,and
therefore should be immutable (all instance fIElds must be final).
(must_be_immutable at […] lib….dart:23)
并解释如何使用StatefulWidget documentation中的StatefulWidget:
@H_403_4@ @H_403_4@ @H_403_4@ @H_403_4@ 总结StatefulWidget instances themselves are immutable and store their mutable state either in separate State objects that are created by the createState method,or in objects to which that State subscribes,for example Stream or ChangeNotifIEr objects,to which references are stored in final fIElds on the StatefulWidget itself.
以上是内存溢出为你收集整理的为什么某些变量在flutter自定义类中被标记为final?全部内容,希望文章能够帮你解决为什么某些变量在flutter自定义类中被标记为final?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)