Skip to content
Snippets Groups Projects
Select Git revision
  • e2a96f94a02f07d2210aa52d025838defe3c782c
  • master default protected
  • 21-move-game-buttons-to-main-navbar
  • 22-fix-give-tip-if-selected-cell-has-no-easy-solution
  • 23-improve-easy-solver
  • 24-disable-select-cell-if-game-is-finished
  • 6-improve-app-metadata
  • Release_0.1.9_18 protected
  • Release_0.1.8_17 protected
  • Release_0.1.7_16 protected
  • Release_0.1.6_15 protected
  • Release_0.1.5_14 protected
  • Release_0.1.4_13 protected
  • Release_0.1.3_12 protected
  • Release_0.1.2_11 protected
  • Release_0.1.1_10 protected
  • Release_0.1.0_9 protected
  • Release_0.0.8_8 protected
  • Release_0.0.7_7 protected
  • Release_0.0.6_6 protected
  • Release_0.0.5_5 protected
  • Release_0.0.4_4 protected
  • Release_0.0.3_3 protected
  • Release_0.0.2_2 protected
  • Release_0.0.1_1 protected
25 results

cell.dart

  • cell.dart 5.75 KiB
    import 'package:flutter/material.dart';
    import 'package:flutter_custom_toolbox/flutter_toolbox.dart';
    
    import 'package:suguru/config/application_config.dart';
    
    import 'package:suguru/cubit/activity/activity_cubit.dart';
    import 'package:suguru/models/activity/cell.dart';
    import 'package:suguru/models/activity/activity.dart';
    import 'package:suguru/utils/color_theme_utils.dart';
    
    class CellWidget extends StatelessWidget {
      const CellWidget({
        super.key,
        required this.cell,
        required this.theme,
        required this.hasBlockBorderTop,
        required this.hasBlockBorderLeft,
        required this.hasBlockBorderBottom,
        required this.hasBlockBorderRight,
      });
    
      final Cell cell;
      final String theme;
      final bool hasBlockBorderTop;
      final bool hasBlockBorderLeft;
      final bool hasBlockBorderBottom;
      final bool hasBlockBorderRight;
    
      @override
      Widget build(BuildContext context) {
        return BlocBuilder<ActivityCubit, ActivityState>(
          builder: (BuildContext context, ActivityState activityState) {
            final Activity activity = activityState.currentActivity;
    
            final String imageAsset = getImageAssetName(activity);
    
            return Container(
              decoration: BoxDecoration(
                color: getBackgroundColor(activity),
                border: getCellBorders(activity),
              ),
              child: GestureDetector(
                child: AnimatedSwitcher(
                  duration: const Duration(milliseconds: 100),
                  transitionBuilder: (Widget child, Animation<double> animation) {
                    return ScaleTransition(scale: animation, child: child);
                  },
                  child: Image(
                    image: AssetImage(imageAsset),
                    fit: BoxFit.fill,
                    key: ValueKey<int>(imageAsset.hashCode),
                  ),
                ),
                onTap: () {
                  final ActivityCubit activityCubit = BlocProvider.of<ActivityCubit>(context);
    
                  if (cell.location.col != activity.selectedCell?.location.col ||
                      cell.location.row != activity.selectedCell?.location.row) {
                    activityCubit.selectCell(cell.location);
                  } else {
                    activityCubit.unselectCell();
                  }
                },
              ),
            );
          },
        );
      }
    
      /*