Hi I tried to implement Flame Game using the flutter Flame package, however, after compiling properly once, now it does not compile at all, and is showing the error, listed below:
I am running MacOS Moneterey Androud Studio: Arctic Fox 2020.3.1 Flutter env. environment: sdk: ">=2.15.0 <3.0.0" flame: ^1.0.0
Launching lib/main.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome...
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/flame_game.dart:19:40: Error: Type 'Game' not found.
class FlameGame extends Component with Game {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/game_widget/game_widget.dart:21:40: Error: Type 'Game' not found.
typedef OverlayWidgetBuilder<T extends Game> = Widget Function(
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/game_widget/game_widget.dart:28:28: Error: Type 'Game' not found.
class GameWidget<T extends Game> extends StatefulWidget {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/game_widget/game_widget.dart:136:34: Error: Type 'Game' not found.
class _GameWidgetState<T extends Game> extends State<GameWidget<T>> {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/game_widget/game_widget.dart:373:9: Error: Type 'Game' not found.
final Game game;
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/mixins/fps_counter.dart:9:21: Error: Type 'Game' not found.
mixin FPSCounter on Game {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/mixins/keyboard.dart:48:25: Error: Type 'Game' not found.
mixin KeyboardEvents on Game {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/detectors.dart:4:32: Error: Type 'Game' not found.
mixin MultiTouchTapDetector on Game {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/detectors.dart:12:33: Error: Type 'Game' not found.
mixin MultiTouchDragDetector on Game {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/detectors.dart:20:22: Error: Type 'Game' not found.
mixin TapDetector on Game {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/detectors.dart:27:31: Error: Type 'Game' not found.
mixin SecondaryTapDetector on Game {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/detectors.dart:33:28: Error: Type 'Game' not found.
mixin DoubleTapDetector on Game {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/detectors.dart:39:28: Error: Type 'Game' not found.
mixin LongPressDetector on Game {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/detectors.dart:47:31: Error: Type 'Game' not found.
mixin VerticalDragDetector on Game {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/detectors.dart:55:33: Error: Type 'Game' not found.
mixin HorizontalDragDetector on Game {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/detectors.dart:63:29: Error: Type 'Game' not found.
mixin ForcePressDetector on Game {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/detectors.dart:70:22: Error: Type 'Game' not found.
mixin PanDetector on Game {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/detectors.dart:78:24: Error: Type 'Game' not found.
mixin ScaleDetector on Game {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/detectors.dart:84:32: Error: Type 'Game' not found.
mixin MouseMovementDetector on Game {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/detectors.dart:88:25: Error: Type 'Game' not found.
mixin ScrollDetector on Game {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:18:9: Error: Type 'Game' not found.
final Game _game;
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:46:9: Error: Type 'Game' not found.
final Game _game;
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:74:9: Error: Type 'Game' not found.
final Game _game;
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:88:5: Error: Type 'Game' not found.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:95:5: Error: Type 'Game' not found.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:102:5: Error: Type 'Game' not found.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:112:5: Error: Type 'Game' not found.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:119:5: Error: Type 'Game' not found.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:128:5: Error: Type 'Game' not found.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:137:5: Error: Type 'Game' not found.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:144:5: Error: Type 'Game' not found.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:151:5: Error: Type 'Game' not found.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:158:5: Error: Type 'Game' not found.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:167:5: Error: Type 'Game' not found.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:173:9: Error: Type 'Game' not found.
final Game _game;
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:188:5: Error: Type 'Game' not found.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:194:9: Error: Type 'Game' not found.
final Game _game;
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:217:5: Error: Type 'Game' not found.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/parallax.dart:16:32: Error: Type 'Game' not found.
extension ParallaxExtension on Game {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/sprite_batch.dart:10:35: Error: Type 'Game' not found.
extension SpriteBatchExtension on Game {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/game_render_box.dart:15:3: Error: Type 'Game' not found.
Game game;
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/game_widget/gestures.dart:12:31: Error: Type 'Game' not found.
bool hasBasicGestureDetectors(Game game) =>
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/game_widget/gestures.dart:23:35: Error: Type 'Game' not found.
bool hasAdvancedGesturesDetectors(Game game) =>
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/game_widget/gestures.dart:29:24: Error: Type 'Game' not found.
bool hasMouseDetectors(Game game) =>
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/game_widget/gestures.dart:34:36: Error: Type 'Game' not found.
Widget applyBasicGesturesDetectors(Game game, Widget child) {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/game_widget/gestures.dart:182:39: Error: Type 'Game' not found.
Widget applyAdvancedGesturesDetectors(Game game, Widget child) {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/game_widget/gestures.dart:277:28: Error: Type 'Game' not found.
Widget applyMouseDetectors(Game game, Widget child) {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/game_widget/gestures.dart:294:9: Error: Type 'Game' not found.
final Game gameRef;
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/flame_game.dart:19:7: Error: The type 'Game' can't be mixed in.
class FlameGame extends Component with Game {
^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/components/component.dart:334:20: Error: The getter 'hasLayout' isn't defined for the class 'FlameGame'.
- 'FlameGame' is from 'package:flame/src/game/flame_game.dart' ('../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/flame_game.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'hasLayout'.
parentGame.hasLayout,
^^^^^^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/game_widget/game_widget.dart:373:9: Error: 'Game' isn't a type.
final Game game;
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:18:9: Error: 'Game' isn't a type.
final Game _game;
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:46:9: Error: 'Game' isn't a type.
final Game _game;
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:74:9: Error: 'Game' isn't a type.
final Game _game;
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:88:5: Error: 'Game' isn't a type.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:95:5: Error: 'Game' isn't a type.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:102:5: Error: 'Game' isn't a type.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:112:5: Error: 'Game' isn't a type.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:119:5: Error: 'Game' isn't a type.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:128:5: Error: 'Game' isn't a type.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:137:5: Error: 'Game' isn't a type.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:144:5: Error: 'Game' isn't a type.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:151:5: Error: 'Game' isn't a type.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:158:5: Error: 'Game' isn't a type.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:167:5: Error: 'Game' isn't a type.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:173:9: Error: 'Game' isn't a type.
final Game _game;
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:188:5: Error: 'Game' isn't a type.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:194:9: Error: 'Game' isn't a type.
final Game _game;
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/gestures/events.dart:217:5: Error: 'Game' isn't a type.
Game game,
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/game_render_box.dart:15:3: Error: 'Game' isn't a type.
Game game;
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/game_widget/gestures.dart:12:31: Error: 'Game' isn't a type.
bool hasBasicGestureDetectors(Game game) =>
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/game_widget/gestures.dart:23:35: Error: 'Game' isn't a type.
bool hasAdvancedGesturesDetectors(Game game) =>
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/game_widget/gestures.dart:29:24: Error: 'Game' isn't a type.
bool hasMouseDetectors(Game game) =>
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/game_widget/gestures.dart:34:36: Error: 'Game' isn't a type.
Widget applyBasicGesturesDetectors(Game game, Widget child) {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/game_widget/gestures.dart:182:39: Error: 'Game' isn't a type.
Widget applyAdvancedGesturesDetectors(Game game, Widget child) {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/game_widget/gestures.dart:203:26: Error: 'Game' isn't a type.
void addDragRecognizer(Game game, Drag Function(int, DragStartInfo) config) {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/game_widget/gestures.dart:277:28: Error: 'Game' isn't a type.
Widget applyMouseDetectors(Game game, Widget child) {
^^^^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flame-1.0.0/lib/src/game/game_widget/gestures.dart:294:9: Error: 'Game' isn't a type.
final Game gameRef;
^^^^
Failed to compile application.
This is the code that I wrote (copied from the Flame website):
import 'dart:math' as math;
import 'dart:ui';
import 'package:flame/components.dart';
import 'package:flame/extensions.dart';
import 'package:flame/game.dart';
import 'package:flame/input.dart';
import 'package:flame/palette.dart';
import 'package:flutter/material.dart';
void main() {
runApp(
GameWidget(
game: MyGame(),
),
);
}
class Square extends PositionComponent {
static const speed = 0.25;
static const squareSize = 128.0;
static Paint white = BasicPalette.white.paint();
static Paint red = BasicPalette.red.paint();
static Paint blue = BasicPalette.blue.paint();
@override
void render(Canvas c) {
c.drawRect(size.toRect(), white);
c.drawRect(const Rect.fromLTWH(0, 0, 3, 3), red);
c.drawRect(Rect.fromLTWH(width / 2, height / 2, 3, 3), blue);
}
@override
void update(double dt) {
super.update(dt);
angle += speed * dt;
angle %= 2 * math.pi;
}
@override
Future<void> onLoad() async {
super.onLoad();
size.setValues(squareSize, squareSize);
anchor = Anchor.center;
}
}
class MyGame extends FlameGame with DoubleTapDetector, TapDetector {
bool running = true;
@override
Future<void> onLoad() async {
await super.onLoad();
add(
Square()
..x = 100
..y = 100,
);
}
@override
void onTapUp(TapUpInfo info) {
final touchPoint = info.eventPosition.game;
final handled = children.any((c) {
if (c is PositionComponent && c.containsPoint(touchPoint)) {
remove(c);
return true;
}
return false;
});
if (!handled) {
add(Square()..position = touchPoint);
}
}
@override
void onDoubleTap() {
if (running) {
// pauseEngine();
} else {
// resumeEngine();
}
running = !running;
}
}
It sounds like something is wrong with the Flame version in your cache. Run:
flutter pub cache clean
flutter pub get
In the directory of your application, and then try to run the example again.