/
seats_area.dart
116 lines (104 loc) · 3.56 KB
/
seats_area.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import 'package:flutter/material.dart';
//Models
import '../../../models/seat_model.dart';
//Widgets
import 'seat_widget.dart';
class SeatsArea extends StatelessWidget {
final double maxGridHeight, seatSize, seatGap;
final int numOfRows, maxRows, seatsPerRow;
final List<SeatModel> missing, blocked, booked;
final ScrollController screenScrollController;
const SeatsArea({
required this.maxGridHeight,
required this.seatSize,
required this.seatGap,
required this.numOfRows,
required this.maxRows,
required this.seatsPerRow,
required this.missing,
required this.blocked,
required this.booked,
required this.screenScrollController,
});
bool isMissing(SeatModel seat) => missing.contains(seat);
bool isBlocked(SeatModel seat) => blocked.contains(seat);
bool isBooked(SeatModel seat) => booked.contains(seat);
bool _onGlowNotification(OverscrollIndicatorNotification overScroll) {
overScroll.disallowIndicator();
return true;
}
bool _onScrollNotification(ScrollNotification scrollInfo) {
if (scrollInfo is ScrollUpdateNotification) {
screenScrollController.jumpTo(
scrollInfo.metrics.pixels,
);
}
return true;
}
@override
Widget build(BuildContext context) {
return SizedBox(
height: maxGridHeight * numOfRows / maxRows,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
//Seat letters' column
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
for (var i = 0; i < numOfRows; i++)
SizedBox(
height: 26.5,
child: Center(
child: Text(
String.fromCharCode(i + 65),
style: const TextStyle(color: Colors.white),
),
),
)
],
),
const SizedBox(width: 10),
//Seats
NotificationListener<OverscrollIndicatorNotification>(
onNotification: _onGlowNotification,
child: Flexible(
child: NotificationListener<ScrollNotification>(
onNotification: _onScrollNotification,
child: GridView.builder(
itemCount: numOfRows * seatsPerRow,
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.only(right: 20),
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: seatSize,
crossAxisSpacing: seatGap,
mainAxisSpacing: seatGap,
),
itemBuilder: (ctx, i) {
final seat = SeatModel(
seatRow: String.fromCharCode(i % numOfRows + 65),
seatNumber: i ~/ numOfRows,
);
if (isMissing(seat)) {
return const SizedBox.shrink();
} else if (isBlocked(seat) || isBooked(seat)) {
return const DecoratedBox(
decoration: BoxDecoration(
color: Color(0xFF5A5A5A),
borderRadius: BorderRadius.all(
Radius.circular(8),
),
),
);
}
return SeatWidget(seat: seat);
},
),
),
),
),
],
),
);
}
}