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
|
enum HybridState {
idle,
engineOutput,
regenerativeBreaking,
baterryOutput,
}
enum ArrowState { blue, red, green, yellow }
enum BatteryState { white, red, green, yellow, orange }
class Hybrid {
final HybridState hybridState;
final ArrowState topArrowState;
final ArrowState leftArrowState;
final ArrowState rightArrowState;
final BatteryState batteryState;
Hybrid({
required this.hybridState,
required this.topArrowState,
required this.leftArrowState,
required this.rightArrowState,
required this.batteryState,
});
const Hybrid.initial()
: hybridState = HybridState.idle,
topArrowState = ArrowState.blue,
leftArrowState = ArrowState.blue,
rightArrowState = ArrowState.blue,
batteryState = BatteryState.white;
Hybrid copyWith({
HybridState? hybridState,
ArrowState? topArrowState,
ArrowState? leftArrowState,
ArrowState? rightArrowState,
BatteryState? batteryState,
}) {
return Hybrid(
hybridState: hybridState ?? this.hybridState,
topArrowState: topArrowState ?? this.topArrowState,
leftArrowState: leftArrowState ?? this.leftArrowState,
rightArrowState: rightArrowState ?? this.rightArrowState,
batteryState: batteryState ?? this.batteryState,
);
}
// Map<String, dynamic> toMap() {
// return {
// 'hybridState': hybridState.toMap(),
// 'topArrowState': topArrowState.toMap(),
// 'leftArrowState': leftArrowState.toMap(),
// 'rightArrowState': rightArrowState.toMap(),
// 'batteryState': batteryState.toMap(),
// };
// }
// factory Hybrid.fromMap(Map<String, dynamic> map) {
// return Hybrid(
// hybridState: HybridState.fromMap(map['hybridState']),
// topArrowState: ArrowState.fromMap(map['topArrowState']),
// leftArrowState: ArrowState.fromMap(map['leftArrowState']),
// rightArrowState: ArrowState.fromMap(map['rightArrowState']),
// batteryState: BatteryState.fromMap(map['batteryState']),
// );
// }
// String toJson() => json.encode(toMap());
// factory Hybrid.fromJson(String source) => Hybrid.fromMap(json.decode(source));
@override
String toString() {
return 'Hybrid(hybridState: $hybridState, topArrowState: $topArrowState, leftArrowState: $leftArrowState, rightArrowState: $rightArrowState, batteryState: $batteryState)';
}
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is Hybrid &&
other.hybridState == hybridState &&
other.topArrowState == topArrowState &&
other.leftArrowState == leftArrowState &&
other.rightArrowState == rightArrowState &&
other.batteryState == batteryState;
}
@override
int get hashCode {
return hybridState.hashCode ^
topArrowState.hashCode ^
leftArrowState.hashCode ^
rightArrowState.hashCode ^
batteryState.hashCode;
}
}
|