fetchOrganizations method

Future<void> fetchOrganizations()

Fetches organizations from the database and updates the state.

Implementation

Future<void> fetchOrganizations() async {
  try {
    final result = await fetchOrganizationsFromDb(db);
    emit(
      state.copyWith(
        organizationList:
            result.map((doc) {
              return {
                'id': doc.$id,
                'name': doc.data['organizationName']?.toString() ?? '',
              };
            }).toList(),
      ),
    );
  } catch (e) {
    emit(state.copyWith(errorMessage: 'Failed to load organizations: $e'));
  }
}