声明同一类的多个对象?

时间:2020-03-23 00:09:55

标签: flutter dart

有没有更好的方式编写此代码:

  TextEditingController ectrl = TextEditingController();
  TextEditingController passctrl = TextEditingController();
  TextEditingController fnamectrl = TextEditingController();
  TextEditingController lnamectrl = TextEditingController();

我的意思是快来吧!

1 个答案:

答案 0 :(得分:2)

    var ectrl = TextEditingController(),
        passctrl = TextEditingController(),
        fnamectrl = TextEditingController(),
        lnamectrl = TextEditingController();

    var ctrls = List.generate(4, (index) => TextEditingController());