Select Git revision
settings_activity_state.dart
-
Benoît Harrault authoredBenoît Harrault authored
game_board.dart 5.19 KiB
import 'package:flutter/material.dart';
import 'package:flutter_custom_toolbox/flutter_toolbox.dart';
import 'package:random/cubit/activity/activity_cubit.dart';
import 'package:random/models/activity/activity.dart';
import 'package:random/models/settings/settings_activity.dart';
import 'package:random/ui/painters/cell_painter.dart';
import 'package:random/ui/widgets/game/game_score.dart';
class GameBoardWidget extends StatefulWidget {
const GameBoardWidget({
super.key,
required this.activity,
required this.widgetSize,
});
final Activity activity;
final Size widgetSize;
@override
State<GameBoardWidget> createState() => _GameBoardWidget();
}
class _GameBoardWidget extends State<GameBoardWidget> with TickerProviderStateMixin {
List<List<Animation<double>?>> animations = [];
void resetAnimations(ActivitySettings activitySettings) {
final int boardSize = activitySettings.boardSizeValue;
animations = List.generate(
boardSize,
(i) => List.generate(
boardSize,
(i) => null,
),
);
}
void removeCell(BuildContext context, int x, int y) {
final ActivityCubit activityCubit = BlocProvider.of<ActivityCubit>(context);
final Activity updatedGame = activityCubit.state.currentActivity;
// "remove" cell, update counters
updatedGame.increaseScore(updatedGame.getCellValue(x, y));
updatedGame.increaseMovesCount();
updatedGame.updateCellValue(x, y, null);
setState(() {});
// "move down" cells
final controller = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 750),
)..addListener(() {
if (mounted) {
setState(() {});
}
});
if (mounted) {
setState(() {});
}
Animation<double> animation = Tween(
begin: 0.0,
end: 1.0,
).animate(CurvedAnimation(
curve: Curves.bounceOut,
parent: controller,
))
..addStatusListener((status) {