简体   繁体   中英

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.

This is my main.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.

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

Your GameWrapper class needs FlutterBirdGame instance in it's constructor, try to add it:

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

Your GameWrapper class requires FlutterBirdGame object: Try to do like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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