Skip to content

Commit a19d810

Browse files
committed
fix(demo): handle empty user content preferences fixtures data
- Add a check for empty userContentPreferencesFixturesData before cloning the first item - Throw a StateError if the fixtures data is empty, preventing potential runtime errors
1 parent 20981f9 commit a19d810

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/app/services/demo_data_initializer_service.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,14 @@ class DemoDataInitializerService {
120120
);
121121
// Clone the first item from the fixture data, assigning the new user's ID.
122122
// This provides new demo users with pre-populated saved filters and other preferences.
123+
if (userContentPreferencesFixturesData.isEmpty) {
124+
throw StateError(
125+
'Cannot create preferences from fixture: userContentPreferencesFixturesData is empty.',
126+
);
127+
}
123128
final fixturePreferences = userContentPreferencesFixturesData.first
124129
.copyWith(id: userId);
130+
125131
await _userContentPreferencesRepository.create(
126132
item: fixturePreferences,
127133
userId: userId,

0 commit comments

Comments
 (0)