Skip to content

Commit 3168c99

Browse files
committed
probably fix log shit
1 parent 8309675 commit 3168c99

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

lib/screens/logs.dart

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ class LogScreenState extends State<LogScreen> {
3232
super.initState();
3333
initialLoading = true;
3434
manager.reloadShockerLogs = () {
35+
List<ShockerLog> newLogs = [];
36+
for (var shocker in shockers)
37+
newLogs.addAll(manager.shockerLog[shocker.id] ?? []);
38+
newLogs.sort((a, b) => b.createdOn.compareTo(a.createdOn));
3539
setState(() {
36-
for (var shocker in shockers)
37-
logs.addAll(manager.shockerLog[shocker.id] ?? []);
38-
logs.sort((a, b) => b.createdOn.compareTo(a.createdOn));
40+
logs = newLogs;
3941
});
4042
if(reloadShockerLogs != null) {
4143
reloadShockerLogs!();
@@ -74,11 +76,11 @@ class LogScreenState extends State<LogScreen> {
7476
onPressed: showStats,
7577
child: Text("Show stats"),
7678
key: ValueKey("stats")));
77-
for (ShockerLog log in logs) {
79+
for (ShockerLog log in logs.toList()) {
7880
widgets.add(ShockerLogEntry(
7981
log: log,
8082
key: ValueKey(
81-
"${log.createdOn}-${log.controlledBy.id}-${log.intensity}-${log.duration}-${log.type}-${log.shockerReference?.id}"),
83+
log.id),
8284
));
8385
}
8486

@@ -105,9 +107,24 @@ class LogScreenState extends State<LogScreen> {
105107
onRefresh: () async {
106108
return loadLogs();
107109
},
108-
child: ListView(
109-
children: widgets
110-
)))));
110+
child: ListView.builder(
111+
itemCount: logs.length + 1, // +1 for the button
112+
itemBuilder: (context, index) {
113+
if (index == 0) {
114+
return FilledButton(
115+
onPressed: showStats,
116+
child: Text("Show stats"),
117+
key: ValueKey("stats"),
118+
);
119+
}
120+
121+
final log = logs[index - 1]; // Adjust index since 0 is the button
122+
return ShockerLogEntry(
123+
log: log,
124+
key: ValueKey(log.id),
125+
);
126+
},
127+
),))));
111128
}
112129
}
113130

lib/stores/alarm_store.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class AlarmShocker {
178178
..shockerId = shocker["ShockerId"]
179179
..intensity = shocker["Intensity"]
180180
..duration = shocker["Duration"]
181-
..type = ControlType.values[shocker["ControlType"]]
181+
..type = shocker["ControlType"] != -1 ? ControlType.values[shocker["ControlType"]] : null
182182
..enabled = shocker["Enabled"];
183183
if(shocker["ToneId"] != null) {
184184
s.serverToneId = shocker["ToneId"];
@@ -200,6 +200,7 @@ class AlarmShocker {
200200
break;
201201
}
202202
}
203+
if(toneId == null) serverToneId = null;
203204
return {
204205
"ShockerId": shockerId,
205206
"Intensity": intensity,

0 commit comments

Comments
 (0)