match_magic/lib/main.dart

60 lines
1.6 KiB
Dart
Raw Normal View History

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!;
return MatchMagicGame(sprites: sprites);
}
} else {
return const Center(child: CircularProgressIndicator());
}
},
2024-07-31 15:02:27 +00:00
);
}
}