首页 > 解决方案 > 如何在方法中编辑最终类字段?

问题描述

我想用这样的方法编辑我的字段:

class Test extends StatefulWidget{
  Test({this.firstField, this.secondField});

  final String firstField ;
  final String secondField ;
  @override
  _TestState createState() => _TestState();
}

class _TestState extends State<Test> {


  @override
  Widget build(BuildContext context) {
  return null;
  }


  editField( field, newValue){
    //edit any field of the class in a single function here
  }
}

如果我将widget.firstField其用作方法的第一个参数,我将能够在本地(在方法中)进行编辑,但不能在字段中进行编辑。

标签: flutterdart

解决方案


推荐阅读