Skip to content

Commit

Permalink
fix(lazy_consumer): updated mapper type to handle dynamic values
Browse files Browse the repository at this point in the history
  • Loading branch information
HenriqueSFernandes committed Oct 31, 2024
1 parent 35d6329 commit df13b77
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
3 changes: 1 addition & 2 deletions packages/uni_app/lib/view/home/widgets/schedule_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -50,7 +49,7 @@ class ScheduleCard extends GenericCard {
),
),
contentLoadingWidget: const ScheduleCardShimmer().build(context),
mapper: (lectures) => lectures
mapper: (lectures) => (lectures as List<Lecture>)
.where(
(lecture) =>
lecture.endTime.isAfter(DateTime.now()) ||
Expand Down
7 changes: 4 additions & 3 deletions packages/uni_app/lib/view/lazy_consumer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class LazyConsumer<T1 extends StateProviderNotifier<T2>, 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>(T2 value) => value;
static T2 _defaultMapper<T2>(dynamic value) => value as T2;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -94,8 +94,9 @@ class LazyConsumer<T1 extends StateProviderNotifier<T2>, 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) {
Expand Down

0 comments on commit df13b77

Please sign in to comment.