gameAppCreator method

void gameAppCreator()

Implementation

void gameAppCreator() {
  var gameAppContent = '''
import 'package:flame/game.dart' as flame;
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

import '../game.dart';
import '../config.dart';
import 'overlay_screen.dart';
import 'score_card.dart';

class GameApp extends StatefulWidget {
// Constructor for the GameApp widget.
const GameApp({super.key});

// Creates the mutable state for this widget.
@override
State<GameApp> createState() => _GameAppState();
}

// The state class for GameApp.
class _GameAppState extends State<GameApp> {
late final Game game;

// initState is a lifecycle method that is called when the state is initialized.
// You can perform any initialization tasks here.
@override
void initState() {
  super.initState();
  game = Game(); // Create a new instance of the Game class.
}

@override
Widget build(BuildContext context) {
  return MaterialApp(
    debugShowCheckedModeBanner: false,
    theme: ThemeData(
      useMaterial3: true,
      textTheme: GoogleFonts.pressStart2pTextTheme().apply(
        bodyColor: const Color(0xff184e77),
        displayColor: const Color(0xff184e77),
      ),
    ),
    home: Scaffold(
      body: Container(
        decoration: const BoxDecoration(
          gradient: LinearGradient(
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
            colors: [
              Color(0xffa9d6e5),
              Color(0xfff2e8cf),
            ],
          ),
        ),
        child: SafeArea(
          child: Padding(
            padding: const EdgeInsets.all(16),
            child: Center(
              child: Column(
                children: [
                  ScoreCard(score: game.score),
                  Expanded(
                    child: FittedBox(
                      child: SizedBox(
                        width: gameWidth,
                        height: gameHeight,
                        child: flame.GameWidget(
                          game: game,
                          overlayBuilderMap: {
                            PlayState.welcome.name: (context, game) =>
                                const OverlayScreen(
                                  title: 'TAP TO PLAY',
                                  subtitle: 'Use arrow keys or swipe',
                                ),
                            PlayState.gameOver.name: (context, game) =>
                                const OverlayScreen(
                                  title: 'G A M E   O V E R',
                                  subtitle: 'Tap to Play Again',
                                ),
                            PlayState.won.name: (context, game) =>
                                const OverlayScreen(
                                  title: 'Y O U   W O N ! ! !',
                                  subtitle: 'Tap to Play Again',
                                ),
                          },
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    ),
  );
}
}

''';

  var gameAppFile = File('$name/lib/src/widgets/game_app.dart');

  gameAppFile.createSync(recursive: true);
  gameAppFile.writeAsStringSync(gameAppContent);
}