简体   繁体   English

Flutter `需要 1 个位置参数,但找到 0 个。`

[英]Flutter `1 positional argument(s) expected, but 0 found.`

I've downloaded project from github and this is the error, 1 positional argument(s) expected, but 0 found.我从 github 下载了项目,这是错误,预期 1 个位置参数,但找到了 0 个。

This is my main.dart这是我的主要。dart

class GameWrapper extends StatelessWidget {
  final FlutterBirdGame flutterBirdGame;
  GameWrapper(this.flutterBirdGame);

  @override
  Widget build(BuildContext context) {
    return flutterBirdGame.widget;
  }
}

class Singleton {
  Size screenSize;
  Singleton._privateConstructor();
  static final Singleton instance = Singleton._privateConstructor();
}

void main() async {
  // initial settings
  WidgetsFlutterBinding.ensureInitialized();
  Flame.audio.disableLog();
  SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
  SystemChrome.setEnabledSystemUIOverlays([]);

  var sprite = await Flame.images.loadAll(["sprite.png"]);
  var screenSize = await Flame.util.initialDimensions();
  Singleton.instance.screenSize = screenSize;
  var flutterBirdGame = FlutterBirdGame(sprite[0], screenSize);
  runApp(MaterialApp(
    title: 'myfirstgame',
    home: GestureDetector(
      onTapDown: (TapDownDetails evt) => flutterBirdGame.onTap(),
      child: Scaffold(
        body: GameWrapper(flutterBirdGame),
      ),
    ),
  ));
}

widget_test.dart i am getting error from this line, its say Try adding the missing arguments.dart(not_enough_positional_arguments) but i dont know how to pass argument. widget_test.dart 我从这行得到错误,它说尝试添加缺少的 arguments.dart(not_enough_positional_arguments) 但我不知道如何传递参数。

await tester.pumpWidget(GameWrapper()); //

Your GameWrapper class needs FlutterBirdGame instance in it's constructor, try to add it:您的GameWrapper class 在其构造函数中需要FlutterBirdGame实例,尝试添加它:

final birdGame = // init FlutterBirdGame variable
await tester.pumpWidget(GameWrapper(birdGame));

Your GameWrapper class requires FlutterBirdGame object: Try to do like this:您的GameWrapper class 需要FlutterBirdGame object:尝试这样做:

final flutterBirdGame = new FlutterBirdGame();
await tester.pumpWidget(GameWrapper(flutterBirdGame));

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

相关问题 预期 2 个位置参数,但找到 0 个。 Flutter - 2 positional argument(s) expected, but 0 found. Flutter 需要 3 个位置参数,但找到了 0 个。 1 - 3 positional argument(s) expected, but 0 found. 1 Flutter 需要 3 个位置参数,但找到了 2 个。 尝试添加缺少的 arguments - Flutter 3 positional argument(s) expected, but 2 found. Try adding the missing arguments 我收到“预期有 1 个位置参数,但找到 0 个”。 使用 Dart 和 Cloud Firestore 在 Flutter 中出错? - I'm getting a "1 positional argument(s) expected, but 0 found." error in Flutter using Dart with Cloud Firestore? Flutter `预期有 6 个位置参数,但找到 1 个。` 尝试添加缺少的参数 - Flutter `6 positional argument(s) expected, but 1 found.` Try adding the missing arguments 颤振块; 预期有 1 个位置参数,但找到 0 个 - Flutter Bloc; 1 positional argument(s) expected, but 0 found Flutter:预期有 3 个位置参数,但发现 0 个 - Flutter: 3 positional argument(s) expected, but 0 found Flutter '需要 {1} 个位置参数,但找到 {0} - Flutter '{1} positional argument(s) expected, but {0} found 预期有 1 个位置参数,但找到 0 个(Flutter) - 1 positional argument(s) expected, but 0 found (Flutter) Flutter:1 个位置参数,但发现 0 - Flutter:1 positional argument(s) expected, but 0 found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM