From df13b7706a2540ac2e7815183178c8c6a45a99b3 Mon Sep 17 00:00:00 2001 From: HenriqueSFernandes Date: Thu, 31 Oct 2024 11:42:10 +0000 Subject: [PATCH] fix(lazy_consumer): updated mapper type to handle dynamic values --- packages/uni_app/lib/view/home/widgets/schedule_card.dart | 3 +-- packages/uni_app/lib/view/lazy_consumer.dart | 7 ++++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/uni_app/lib/view/home/widgets/schedule_card.dart b/packages/uni_app/lib/view/home/widgets/schedule_card.dart index bdfecde3c..477ed4904 100644 --- a/packages/uni_app/lib/view/home/widgets/schedule_card.dart +++ b/packages/uni_app/lib/view/home/widgets/schedule_card.dart @@ -10,7 +10,6 @@ import 'package:uni/model/utils/time/week.dart'; import 'package:uni/utils/navigation_items.dart'; import 'package:uni/view/common_widgets/date_rectangle.dart'; import 'package:uni/view/common_widgets/generic_card.dart'; -import 'package:uni/view/exams/exams.dart'; import 'package:uni/view/home/widgets/schedule_card_shimmer.dart'; import 'package:uni/view/lazy_consumer.dart'; import 'package:uni/view/locale_notifier.dart'; @@ -50,7 +49,7 @@ class ScheduleCard extends GenericCard { ), ), contentLoadingWidget: const ScheduleCardShimmer().build(context), - mapper: (lectures) => lectures + mapper: (lectures) => (lectures as List) .where( (lecture) => lecture.endTime.isAfter(DateTime.now()) || diff --git a/packages/uni_app/lib/view/lazy_consumer.dart b/packages/uni_app/lib/view/lazy_consumer.dart index 97a7a5283..11f797343 100644 --- a/packages/uni_app/lib/view/lazy_consumer.dart +++ b/packages/uni_app/lib/view/lazy_consumer.dart @@ -36,9 +36,9 @@ class LazyConsumer, T2> final bool Function(T2) hasContent; final Widget onNullContent; final Widget? contentLoadingWidget; - final T2 Function(T2)? mapper; + final T2 Function(dynamic)? mapper; - static T2 _defaultMapper(T2 value) => value; + static T2 _defaultMapper(dynamic value) => value as T2; @override Widget build(BuildContext context) { @@ -94,8 +94,9 @@ class LazyConsumer, T2> Widget requestDependantWidget(BuildContext context, T1 provider) { final mappedState = provider.state != null - ? (mapper ?? _defaultMapper)(provider.state as T2) + ? (mapper ?? _defaultMapper)(provider.state as dynamic) : null; + final showContent = provider.state != null && hasContent(mappedState as T2); if (provider.requestStatus == RequestStatus.busy && !showContent) {