-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid.dart
41 lines (38 loc) · 1.02 KB
/
grid.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import 'package:flutter/material.dart';
class GridDrawer extends StatelessWidget {
const GridDrawer(this.grid, this.width, {Key? key}) : super(key: key);
final List<GridCell> grid;
final int width;
int get height => grid.length ~/ width;
@override
Widget build(BuildContext context) {
return CustomPaint(
painter: GridPainter(
width,
height,
grid,
),
);
}
}
class GridPainter extends CustomPainter {
GridPainter(this.width, this.height, this.grid);
final int width;
final int height;
final List<GridCell> grid;
@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
@override
void paint(Canvas canvas, Size size) {
double cellDim = 10;
Size cellSize = Size(cellDim, cellDim);
for (int y = 0; y < height; y += 1) {
for (int x = 0; x < width; x += 1) {
grid[x + (y * width)].paint(canvas, cellSize, Offset(x * cellDim, y * cellDim));
}
}
}
}
abstract class GridCell {
void paint(Canvas canvas, Size size, Offset offset);
}