Skip to content

Commit 20981f9

Browse files
committed
fix(demo): handle empty userAppSettingsFixturesData
- Add a check to ensure userAppSettingsFixturesData is not empty before cloning the first item - Throw a StateError with a descriptive message if the list is empty - This prevents potential runtime errors when initializing demo data for new users
1 parent af305d7 commit 20981f9

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
@@ -79,9 +79,15 @@ class DemoDataInitializerService {
7979
);
8080
// Clone the first item from the fixture data, assigning the new user's ID.
8181
// This ensures every new demo user gets a rich, pre-populated set of settings.
82+
if (userAppSettingsFixturesData.isEmpty) {
83+
throw StateError(
84+
'Cannot create settings from fixture: userAppSettingsFixturesData is empty.',
85+
);
86+
}
8287
final fixtureSettings = userAppSettingsFixturesData.first.copyWith(
8388
id: userId,
8489
);
90+
8591
await _userAppSettingsRepository.create(
8692
item: fixtureSettings,
8793
userId: userId,

0 commit comments

Comments
 (0)