简体   繁体   English

位置参数过多! OneSignal,颤振

[英]Too many positional arguments! OneSignal, Flutter

I am making an app using Flutter, Dart and Firebase. 我正在使用Flutter,Dart和Firebase制作应用程序。 Now I am doing some research on how to implement push-notifications and I have been recommended to use OneSignal's SDK for flutter. 现在,我正在研究如何实现push-notifications并建议使用OneSignal的SDK进行抖动。

When trying to Initialise the notification I am getting a positional argument error, but the methods have been defined correctly with the exact number of parameters. 尝试初始化通知时,出现位置参数错误,但是使用正确的参数数量正确定义了方法。

OneSignal.shared.init("App ID", {
  OSiOSSettings.autoPrompt: false,
  OSiOSSettings.inAppLaunchUrl: true
});
  OneSignal.shared.setInFocusDisplayType(OSNotificationDisplayType.notification);

This is the corresponding Init method: 这是相应的Init方法:

  Future<void> init(String appId,
  {Map<OSiOSSettings, dynamic> iOSSettings}) async {
  _onesignalLog(OSLogLevel.verbose,
    "Initializing the OneSignal Flutter SDK ($sdkVersion)");

  var finalSettings = _processSettings(iOSSettings);

  await _channel.invokeMethod(
    'OneSignal#init', {'appId': appId, 'settings': finalSettings});
}

All help is appreciated. 感谢所有帮助。

That method has a named parameter: 该方法具有一个命名参数:

 Future<void> init(String appId,
  {Map<OSiOSSettings, dynamic> iOSSettings})

You forgot the name (iOSSettings) 您忘记了该名称(iOS设置)

Change this: 更改此:

OneSignal.shared.init("App ID", {
  OSiOSSettings.autoPrompt: false,
  OSiOSSettings.inAppLaunchUrl: true
});

To this : 对此:

OneSignal.shared.init("App ID", iOSSettings: {
  OSiOSSettings.autoPrompt: false,
 OSiOSSettings.inAppLaunchUrl: true
});

You can read more about that : https://www.dartlang.org/guides/language/language-tour#optional-parameters 您可以阅读有关此内容的更多信息: https : //www.dartlang.org/guides/language/language-tour#optional-parameters

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM