-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsensor.dart
More file actions
43 lines (38 loc) · 1.09 KB
/
sensor.dart
File metadata and controls
43 lines (38 loc) · 1.09 KB
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
import 'dart:math';
class Sensor {
final int id;
final String name;
final String description;
/// Always in Fahrenheit for this demo
final double value;
Sensor({
required this.id,
required this.name,
required this.description,
required this.value,
});
factory Sensor.random() {
final random = Random();
final sensorNumber = random.nextInt(1000);
return Sensor(
id: Random().nextInt(1000),
name: 'Sensor $sensorNumber',
description: 'Some description of sensor: #$sensorNumber...',
value: Random().nextDouble() * 100,
);
}
// i was shown this early on and its become a habit for me for easy searchability
bool matchesSearchQuery(String query) {
String lowerQuery = query.toLowerCase();
return name.toLowerCase().contains(lowerQuery) ||
description.toLowerCase().contains(lowerQuery);
}
Sensor copyWith({double? value, String? name, String? description}) {
return Sensor(
id: id,
name: name ?? this.name,
description: description ?? this.description,
value: value ?? this.value,
);
}
}