import 'package:flutter/material.dart'; import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; import 'package:suguru/cubit/activity/activity_cubit.dart'; import 'package:suguru/models/activity/cell_location.dart'; import 'package:suguru/models/activity/activity.dart'; import 'package:suguru/ui/widgets/game/cell.dart'; class GameBoardWidget extends StatelessWidget { const GameBoardWidget({super.key}); @override Widget build(BuildContext context) { return BlocBuilder<ActivityCubit, ActivityState>( builder: (BuildContext context, ActivityState activityState) { final Activity currentActivity = activityState.currentActivity; final Color borderColor = Theme.of(context).colorScheme.onSurface; final Size size = MediaQuery.of(context).size; final double width = size.width; final double height = size.height; final Container board = Container( margin: const EdgeInsets.all(2), padding: const EdgeInsets.all(2), decoration: BoxDecoration( color: borderColor, borderRadius: BorderRadius.circular(2), border: Border.all( color: borderColor, width: 2, ), ), child: Column( children: [ Table( defaultColumnWidth: const IntrinsicColumnWidth(), children: [ for (int row = 0; row < currentActivity.boardSizeVertical; row++) TableRow( children: [ for (int col = 0; col < currentActivity.boardSizeHorizontal; col++) Column( children: [ CellWidget( cell: currentActivity.board.get(CellLocation.go(row, col)), hasBlockBorderBottom: row == currentActivity.boardSizeVertical || currentActivity.board .get(CellLocation.go(row, col)) .blockId != currentActivity.board .get(CellLocation.go(row + 1, col)) .blockId, hasBlockBorderLeft: col == 0 || currentActivity.board .get(CellLocation.go(row, col)) .blockId != currentActivity.board .get(CellLocation.go(row, col - 1)) .blockId, hasBlockBorderRight: col == currentActivity.boardSizeVertical || currentActivity.board .get(CellLocation.go(row, col)) .blockId != currentActivity.board .get(CellLocation.go(row, col + 1)) .blockId, hasBlockBorderTop: row == 0 || currentActivity.board .get(CellLocation.go(row, col)) .blockId != currentActivity.board .get(CellLocation.go(row - 1, col)) .blockId, ) ], ), ], ), ], ), ], ), ); return ConstrainedBox( constraints: BoxConstraints.tightFor( width: width, height: height * .6, ), child: FittedBox( child: board, ), //Text ); }, ); } }