实例成员"params"无法在初始化程序中访问 [英] The instance member 'params' can't be accessed in an initializer

查看:35
本文介绍了实例成员"params"无法在初始化程序中访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  var myTest = params.[comLevel];
}

错误报告-无法在初始化程序中访问实例成员'params'."我是编程新手,可以直接从小部件中调用它.我检查了LevelUp地图,它具有内容.我尝试将参数值分配给myTest时发生错误.我将密钥放在引号中还是提供整数都没有关系.任何建议将不胜感激.

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.

推荐答案

在初始化对象之前,您无法访问 params .要修复您的示例,请将 myTest 初始化移动到构造函数中.

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

此外,我认为您不应该在 [comLevel] 前加句点.

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];
  }
}

这篇关于实例成员"params"无法在初始化程序中访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆