Kill every Flame's game processes

Viewed 494

I'm building a little Flutter app with 4 mini-games.

Every time I'm launching, then quit and re-launch a game, it's slower than before (less FPS, it's not even playable...). The only way to make it smooth again is restarting the entire app.

How can I be sure the game is not running anymore while I'm launching another game ? I think it's because one of my game is not killed properly that I losing FPS.

Here is my code's logic when I launch a game on SelectGame.dart:

Navigator.push(
  context,
  MaterialPageRoute(
    builder: (context) => Car(
      appLanguage: appLanguage,
      user: user,
      level: "${100 + level * 10 + ID_CAR_ACTIVITY}",
      message: inputMessage,
    ),
  ),
);

When I quit a game:

if (Navigator.canPop(context)) {
  Navigator.pop(context);
} else {
  Navigator.pushReplacement(
    context,
    MaterialPageRoute(
      builder: (context) => MainTitle(
        appLanguage: appLanguage,
        userIn: user,
        messageIn: "0",
      ),
    ),
    //(Route<dynamic> route) => route is MainTitle,
  );
}

Here is my Car.dart's dispose:

  @override
  void dispose() {
    timerConnexion?.cancel();
    timer?.cancel();
    _timer?.cancel();
    timerRedirection?.cancel();
    _controllerTopCenter?.dispose();
    pauseTimer?.cancel();
    game.timerPause?.cancel();
    gameUI?.state?.dispose();
    super.dispose();
  }

And when I'm restarting a game:

Navigator.pushAndRemoveUntil(
    context,
    MaterialPageRoute(
      builder: (context) => new Car(
        appLanguage: appLanguage,
        user: user,
        level: game.getStarLevel().toString(),
        message: "fromRestart",
      ),
    ),
    (Route<dynamic> route) => route is Car);

Is it the good way to exit a game or is there another way more optimised ?

Thanks

0 Answers
Related