match-three/lib/screens/menu_screen.dart
savinmax 64053d1d58 Refactor game state management to use level-based architecture
Remove legacy GamePlaying states and consolidate all gameplay logic
to use the GameLevelPlaying state system. This simplifies state
management by eliminating duplicate code paths and ensures consistent
behavior across all game modes including Free Play.
2025-09-21 17:26:51 +02:00

81 lines
2.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../bloc/game_bloc.dart';
import 'game_screen.dart';
import 'level_selection_screen.dart';
class MenuScreen extends StatelessWidget {
const MenuScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Colors.purple, Colors.deepPurple],
),
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'Match Three',
style: TextStyle(
fontSize: 48,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
const SizedBox(height: 60),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => BlocProvider.value(
value: context.read<GameBloc>(),
child: const LevelSelectionScreen(),
),
),
);
},
style: ElevatedButton.styleFrom(
padding:
const EdgeInsets.symmetric(horizontal: 40, vertical: 16),
),
child:
const Text('Play Levels', style: TextStyle(fontSize: 20)),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: () {
// Start Free Play level (ID: 0)
context.read<GameBloc>().add(StartLevel(0));
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => BlocProvider.value(
value: context.read<GameBloc>(),
child: GameScreen(),
),
),
);
},
style: ElevatedButton.styleFrom(
padding:
const EdgeInsets.symmetric(horizontal: 40, vertical: 16),
),
child: const Text('Free Play', style: TextStyle(fontSize: 20)),
),
],
),
),
),
);
}
}