我收到此错误“NoSuchMethodError:方法'+'在null上调用。接收器:null尝试调用:+()”
但是在模拟器和手机上,我可以完美地看到页面,并且没有显示错误。当其他人在其设备上安装该应用程序时,他们会收到此错误。我不确定为什么不能在调试时重现它,但是不确定如何修复。
这是我使用+的唯一代码段
Text(AppLocalizations.of(context).translate("Member since_") + "${timeago.format(user.timestamp.toDate())}",
style: TextStyle(color: Colors.black45))
这样使用+组合字符串是否错误?它以前曾经工作过,现在仍然可以像我所说的那样在模拟器上工作。
最佳答案
我认为问题出在$ {timeago.format(user.timestamp.toDate())}上,因为这是唯一的变量(请确保您的JSON转换为“Member since_”),也许user.timestamp.toDate上为null ()
因此,您应该使用安全的null变量,如下所示:
final String timeRegist = user?.timestamp?.toDate() ?? '';
Text(AppLocalizations.of(context).translate("Member since_") + "$timeRegist )}",
style: TextStyle(color: Colors.black45))
关于flutter - 在某些设备上,方法 '+'在null上调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59037593/