2024-08-05 08:04:54 +00:00
|
|
|
import 'package:flame/sprite.dart';
|
2024-07-31 15:02:27 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-08-05 08:04:54 +00:00
|
|
|
import 'package:match_magic/game/sprite_loader.dart';
|
2024-08-02 10:53:40 +00:00
|
|
|
import 'package:provider/provider.dart';
|
2024-08-05 08:04:54 +00:00
|
|
|
import 'game/match_magic_game.dart';
|
|
|
|
import 'game/swap_notifier.dart';
|
2024-07-31 15:02:27 +00:00
|
|
|
|
|
|
|
void main() {
|
|
|
|
runApp(
|
2024-08-05 08:04:54 +00:00
|
|
|
MultiProvider(
|
|
|
|
providers: [
|
|
|
|
ChangeNotifierProvider(create: (_) => SwapNotifier()),
|
|
|
|
],
|
2024-07-31 15:02:27 +00:00
|
|
|
child: const MyApp(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
const MyApp({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
|
|
|
title: 'Match Magic',
|
|
|
|
theme: ThemeData(
|
|
|
|
primarySwatch: Colors.blue,
|
|
|
|
),
|
2024-08-05 08:04:54 +00:00
|
|
|
home: const Scaffold(
|
|
|
|
body: MatchMagicGameScreen(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class MatchMagicGameScreen extends StatelessWidget {
|
|
|
|
const MatchMagicGameScreen({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return FutureBuilder<List<Sprite>>(
|
|
|
|
future: SpriteLoader.loadSprites(),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.connectionState == ConnectionState.done) {
|
|
|
|
if (snapshot.hasError) {
|
|
|
|
return Center(child: Text('Error: ${snapshot.error}'));
|
|
|
|
} else if (!snapshot.hasData || snapshot.data == null) {
|
|
|
|
return const Center(child: Text('No sprites found'));
|
|
|
|
} else {
|
|
|
|
final sprites = snapshot.data!;
|
2024-08-06 18:00:51 +00:00
|
|
|
return Center(
|
|
|
|
child: AspectRatio(
|
|
|
|
aspectRatio: 1,
|
|
|
|
child: MatchMagicGame(sprites: sprites),
|
|
|
|
),
|
|
|
|
);
|
2024-08-05 08:04:54 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return const Center(child: CircularProgressIndicator());
|
|
|
|
}
|
|
|
|
},
|
2024-07-31 15:02:27 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|