Newer
Older
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(
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
);