From a810f9ad2c399fb6d9495c0504fcf400f6b5bb3b Mon Sep 17 00:00:00 2001 From: Werner Fleischer <70745309+wfleischer@users.noreply.github.com> Date: Wed, 27 Nov 2024 07:55:12 +0100 Subject: [PATCH] schedules: change scheduleProviderFamily to throw if a schedule does not exist (#133) --- lib/src/schedules/entities/schedule.dart | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/src/schedules/entities/schedule.dart b/lib/src/schedules/entities/schedule.dart index 3bbba7b..afec5fb 100644 --- a/lib/src/schedules/entities/schedule.dart +++ b/lib/src/schedules/entities/schedule.dart @@ -3,10 +3,17 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:nwt_reading/src/schedules/entities/schedules.dart'; -final scheduleProviderFamily = FutureProviderFamily( - (ref, scheduleKey) async => - (await ref.watch(schedulesProvider.future)).schedules[scheduleKey], - name: 'scheduleProviderFamily'); +final scheduleProviderFamily = + FutureProviderFamily((ref, scheduleKey) async { + final schedules = await ref.watch(schedulesProvider.future); + final schedule = schedules.schedules[scheduleKey]; + + if (schedule == null) { + throw Exception('Schedule does not exist'); + } + + return schedule; +}, name: 'scheduleProviderFamily'); enum ScheduleType { chronological,