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
|
import 'dart:collection';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
enum SwitchId {
hvacLeftSeat,
hvacRigthSeat,
hvacAc,
hvacAuto,
hvacCirculation,
hvacFan,
hvacAirDown,
hvacAirUp,
hvacFront,
hvacRear,
}
enum TemperatureId { leftSeat, rightSeat }
class HomescreenModel extends ChangeNotifier {
// HVAC page
// fan speed
double _fanSpeed = 20;
double get fanSpeed => _fanSpeed;
set fanSpeed(double newhvacFanSpeed) {
_fanSpeed = newhvacFanSpeed;
notifyListeners();
}
// switch buttons
HashMap _switches = new HashMap<SwitchId, bool>();
bool getSwitchState(SwitchId id) => _switches[id] ?? false;
void setSwitchState(SwitchId id, bool newValue) {
_switches[id] = newValue;
notifyListeners();
}
void flipSwitch(SwitchId id) {
_switches[id] = !_switches[id];
notifyListeners();
}
// temperatures
HashMap _temperatures = new HashMap<TemperatureId, int>();
int getTemperature(TemperatureId id) => _temperatures[id] ?? 22;
void setTemperature(TemperatureId id, int newTemp) {
_temperatures[id] = newTemp;
notifyListeners();
}
HomescreenModel() {
// initialize the values
for (var id in SwitchId.values) {
_switches[id] = false;
}
for (var id in TemperatureId.values) {
_temperatures[id] = 22;
}
}
}
|