Skip to content

Commit

Permalink
Add valueToOption helper
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedLSayed9 committed Dec 25, 2022
1 parent 74ba9d6 commit 496d54c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 4 additions & 0 deletions lib/core/presentation/helpers/option_helper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import 'package:fpdart/fpdart.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

Option<T> valueToOption<T>(AsyncValue<T> v) => v.valueOrNull.toOption();
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:deliverzler/core/presentation/extensions/auto_dispose_ref_extension.dart';
import 'package:deliverzler/core/presentation/helpers/option_helper.dart';
import 'package:deliverzler/features/map/domain/entities/place_autocomplete.dart';
import 'package:deliverzler/features/map/domain/entities/place_details.dart';
import 'package:deliverzler/features/map/domain/use_cases/get_place_details_uc.dart';
Expand All @@ -20,11 +21,8 @@ Option<PlaceDetails> currentPlaceDetails(CurrentPlaceDetailsRef ref) {
));

return selectedPlaceId.flatMap(
(placeId) => ref.watch(
getPlaceDetailsProvider(placeId).select(
(value) => Option.fromNullable(value.valueOrNull),
),
),
(placeId) =>
ref.watch(getPlaceDetailsProvider(placeId).select(valueToOption)),
);
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ packages:
name: fpdart
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
version: "0.4.0"
freezed:
dependency: "direct dev"
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies:
get_it: ^7.2.0

#FP
fpdart: ^0.3.0
fpdart: ^0.4.0
rxdart: ^0.27.7

#Connectivity
Expand Down

0 comments on commit 496d54c

Please sign in to comment.