-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpattern2tiles.dart
52 lines (43 loc) · 1.11 KB
/
pattern2tiles.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
42
43
44
45
46
47
48
49
50
51
52
import 'package:flutter/rendering.dart';
import 'pattern.dart';
/// Create 2 tiles, width is defined by a ratio between tile 1 and tile 2
class Pattern2Tiles extends Pattern {
double _tileWidth1 = 0;
double _tileWidth2 = 0;
/// Height of a tile
double tileHeight;
/// Width ratio between tile 1 and tile 2
double ratio;
Pattern2Tiles({
required this.ratio,
required this.tileHeight,
});
@override
void init(double crossAxisExtentConstraint) {
_tileWidth1 = crossAxisExtentConstraint * ratio;
_tileWidth2 = crossAxisExtentConstraint - _tileWidth1;
}
@override
double get height {
return tileHeight;
}
@override
int get nbTiles {
return 2;
}
@override
SliverGridGeometry getGeometry(int index) {
if (index == 0) {
return SliverGridGeometry(
scrollOffset: 0,
crossAxisOffset: 0,
crossAxisExtent: _tileWidth1,
mainAxisExtent: tileHeight);
}
return SliverGridGeometry(
scrollOffset: 0,
crossAxisOffset: _tileWidth1,
crossAxisExtent: _tileWidth2,
mainAxisExtent: tileHeight);
}
}