Skip to content

Commit b714cfb

Browse files
fix: RangeError when cancelling install notifications for an empty app list
Co-Authored-By: Omer I.S. <omeritzicschwartz@gmail.com>
1 parent 663d1dc commit b714cfb

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

lib/providers/notifications_provider.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ class SilentUpdateNotification extends UpdatiumNotification {
7171
'appsUpdatedNotifDescription'.t(),
7272
Importance.defaultImportance,
7373
) {
74-
message = updates.length == 1
74+
message = updates.isEmpty
75+
? ''
76+
: updates.length == 1
7577
? t(
7678
succeeded ? 'xWasUpdatedToY' : 'xWasNotUpdatedToY',
7779
args: [updates[0].finalName, updates[0].latestVersion],
@@ -95,7 +97,9 @@ class SilentUpdateAttemptNotification extends UpdatiumNotification {
9597
'appsPossiblyUpdatedNotifDescription'.t(),
9698
Importance.defaultImportance,
9799
) {
98-
message = updates.length == 1
100+
message = updates.isEmpty
101+
? ''
102+
: updates.length == 1
99103
? t(
100104
'xWasPossiblyUpdatedToY',
101105
args: [updates[0].finalName, updates[0].latestVersion],

test/providers_test.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter_test/flutter_test.dart';
22
import 'package:updatium/app_sources/html.dart';
33
import 'package:updatium/providers/apps_provider.dart';
4+
import 'package:updatium/providers/notifications_provider.dart';
45
import 'package:updatium/providers/settings_provider.dart';
56
import 'package:updatium/providers/source_provider.dart';
67

@@ -291,4 +292,13 @@ void main() {
291292
expect(filtered.first.key, contains('x86'));
292293
});
293294
});
295+
296+
group('Notification Tests', () {
297+
test('Update notifications can be built with no apps', () {
298+
// Used to grab notification IDs for cancellation after an install
299+
expect(() => UpdateNotification([]), returnsNormally);
300+
expect(() => SilentUpdateNotification([], true), returnsNormally);
301+
expect(() => SilentUpdateAttemptNotification([], id: 1), returnsNormally);
302+
});
303+
});
294304
}

0 commit comments

Comments
 (0)