Skip to content
Snippets Groups Projects
Select Git revision
  • d76fd876f2c1f280e7a6fea6a9dd9ab757729429
  • master default protected
  • 101-upgrade-framework-and-dependencies
  • 84-improve-app-metadata
  • 82-fix-colors
  • 23-add-timer
  • 65-update-icons
  • Release_0.10.0_87 protected
  • Release_0.9.2_86 protected
  • Release_0.9.1_85 protected
  • Release_0.9.0_84 protected
  • Release_0.8.0_83 protected
  • Release_0.7.0_82 protected
  • Release_0.6.0_81 protected
  • Release_0.5.2_80 protected
  • Release_0.5.1_79 protected
  • Release_0.5.0_78 protected
  • Release_0.4.1_77 protected
  • Release_0.4.0_76 protected
  • Release_0.3.1_75 protected
  • Release_0.3.0_74 protected
  • Release_0.2.1_73 protected
  • Release_0.2.0_72 protected
  • Release_0.1.22_71 protected
  • Release_0.1.21_70 protected
  • Release_0.1.20_69 protected
  • Release_0.1.19_68 protected
27 results

board.dart

Blame
  • 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) {