简体   繁体   English

当我使用 admob flutter 时,位置 arguments 太多

[英]Too many positional arguments when i use admob flutter

why i get this error Too many positional arguments: 0 expected, but 1 found.为什么我会收到此错误太多位置 arguments:预期为 0,但找到了 1。 (Documentation) Try removing the extra positional arguments, or specifying the name for named arguments (文档)尝试删除额外的位置 arguments,或指定名为 arguments 的名称

final ams = AdMobService();最终 ams = AdMobService();

here in this code: Too many positional arguments: 0 expected, but 1 found.在此代码中:太多位置 arguments:预期为 0,但找到了 1。 (Documentation) Try removing the extra positional arguments, or specifying the name for named arguments (文档)尝试删除额外的位置 arguments,或指定名为 arguments 的名称

@override void initState() { Admob.initialize(ams.getAdMobAppId()); }


  String getAdMobAppId() {
    if (Platform.isIOS) {
      return 'ca-app-pub-2334510780816542~6726672523';
    } else if (Platform.isAndroid) {
      return 'ca-app-pub-2334510780816542~7385148076';
    }
    return null;
  }

  String getInterstitialAdUnitId() {
    if (Platform.isIOS) {
      return 'ca-app-pub-3940256099942544/4411468910';
    } else if (Platform.isAndroid) {
      return 'ca-app-pub-3940256099942544/1033173712';
    }
    return null;
}```

Dart supports "positional" arguments and "named" arguments. Dart 支持“定位”arguments 和“命名”arguments。 Positional arguments are given by just using their position, but named arguments are provided like: name: value .位置 arguments 仅使用其 position 给出,但命名 arguments 提供如下: name: value For example:例如:

void myCustomFunction(
  String name,  // positional argument
  {int? age,}   // named argument
) {
  // function body
}

You could then call this function like:然后你可以这样称呼这个 function :

myCustomFunction("hello");  // "hello" is passed in to the parameter "name"
myCustomFunction(
  "hello",  // positional argument (1st argument in list)
  age: 10,  // named argument (we provide the name "age")
)

This error is saying "you gave me 1 positional argument, but the function didn't expect any positional arguments".这个错误是说“你给了我 1 个位置参数,但 function 没想到有任何位置参数”。 To fix it, you need to do one of two possible things:要修复它,您需要执行以下两种可能的操作之一:

  1. If Admob.initialize() has no parameters, just use Admob.initialize()如果Admob.initialize()没有参数,则使用Admob.initialize()
  2. If Admob.initialize() has a named parameter for the API key, you will have to use something like Admob.initialize(apiKey: "your api key") (note that the actual name apiKey might be different, take a look at the documentation for admob) If Admob.initialize() has a named parameter for the API key, you will have to use something like Admob.initialize(apiKey: "your api key") (note that the actual name apiKey might be different, take a look at the admob 的文档)

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

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