The instance member 'params' can't be accessed in an initializer

最后都变了- 提交于 2020-12-07 03:51:29

问题


class LevelUp extends GetxController {
  Map<String, String> params = Get.arguments;

  var myTest = params.[comLevel];
}

Error report--"The instance member 'params' can't be accessed in an initializer." I am new to programming and this is being called directly from a widget. I checked the LevelUp map and it has contents. The error occurs where I am trying to assign the param value to myTest. It doesn't matter if I put the key in quotes or provide an integer. Any advice would be greatly appreciated.


回答1:


You can't access params before you've initialized the object. To fix your example, move your myTest initialization into a constructor.

Also, I don't believe you should have a period before [comLevel].

class LevelUp extends GetxController {
  Map<String, String> params = Get.arguments;
  String myTest;
  
  LevelUp() {
    myTest = params[comLevel];
  }
}


来源:https://stackoverflow.com/questions/63542776/the-instance-member-params-cant-be-accessed-in-an-initializer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!