mirror of
https://github.com/flutter/samples.git
synced 2025-11-14 11:28:36 +00:00
Flutter 3.29 beta (#2571)
This commit is contained in:
@@ -14,9 +14,8 @@ import '../../services/local/local_data_service.dart';
|
||||
import 'booking_repository.dart';
|
||||
|
||||
class BookingRepositoryLocal implements BookingRepository {
|
||||
BookingRepositoryLocal({
|
||||
required LocalDataService localDataService,
|
||||
}) : _localDataService = localDataService;
|
||||
BookingRepositoryLocal({required LocalDataService localDataService})
|
||||
: _localDataService = localDataService;
|
||||
|
||||
// Only create default booking once
|
||||
bool _isInitialized = false;
|
||||
@@ -72,10 +71,11 @@ class BookingRepositoryLocal implements BookingRepository {
|
||||
// create a default booking the first time
|
||||
if (_bookings.isEmpty) {
|
||||
final destination = (await _localDataService.getDestinations()).first;
|
||||
final activities = (await _localDataService.getActivities())
|
||||
.where((activity) => activity.destinationRef == destination.ref)
|
||||
.take(4)
|
||||
.toList();
|
||||
final activities =
|
||||
(await _localDataService.getActivities())
|
||||
.where((activity) => activity.destinationRef == destination.ref)
|
||||
.take(4)
|
||||
.toList();
|
||||
|
||||
_bookings.add(
|
||||
Booking(
|
||||
|
||||
@@ -12,9 +12,8 @@ import '../../services/api/model/booking/booking_api_model.dart';
|
||||
import 'booking_repository.dart';
|
||||
|
||||
class BookingRepositoryRemote implements BookingRepository {
|
||||
BookingRepositoryRemote({
|
||||
required ApiClient apiClient,
|
||||
}) : _apiClient = apiClient;
|
||||
BookingRepositoryRemote({required ApiClient apiClient})
|
||||
: _apiClient = apiClient;
|
||||
|
||||
final ApiClient _apiClient;
|
||||
|
||||
@@ -62,18 +61,21 @@ class BookingRepositoryRemote implements BookingRepository {
|
||||
|
||||
// Get destination for booking
|
||||
final destination = _cachedDestinations!.firstWhere(
|
||||
(destination) => destination.ref == booking.destinationRef);
|
||||
(destination) => destination.ref == booking.destinationRef,
|
||||
);
|
||||
|
||||
final resultActivities =
|
||||
await _apiClient.getActivityByDestination(destination.ref);
|
||||
final resultActivities = await _apiClient.getActivityByDestination(
|
||||
destination.ref,
|
||||
);
|
||||
switch (resultActivities) {
|
||||
case Error<List<Activity>>():
|
||||
return Result.error(resultActivities.error);
|
||||
case Ok<List<Activity>>():
|
||||
}
|
||||
final activities = resultActivities.value
|
||||
.where((activity) => booking.activitiesRef.contains(activity.ref))
|
||||
.toList();
|
||||
final activities =
|
||||
resultActivities.value
|
||||
.where((activity) => booking.activitiesRef.contains(activity.ref))
|
||||
.toList();
|
||||
|
||||
return Result.ok(
|
||||
Booking(
|
||||
@@ -96,16 +98,18 @@ class BookingRepositoryRemote implements BookingRepository {
|
||||
switch (result) {
|
||||
case Ok<List<BookingApiModel>>():
|
||||
final bookingsApi = result.value;
|
||||
return Result.ok(bookingsApi
|
||||
.map(
|
||||
(bookingApi) => BookingSummary(
|
||||
id: bookingApi.id!,
|
||||
name: bookingApi.name,
|
||||
startDate: bookingApi.startDate,
|
||||
endDate: bookingApi.endDate,
|
||||
),
|
||||
)
|
||||
.toList());
|
||||
return Result.ok(
|
||||
bookingsApi
|
||||
.map(
|
||||
(bookingApi) => BookingSummary(
|
||||
id: bookingApi.id!,
|
||||
name: bookingApi.name,
|
||||
startDate: bookingApi.startDate,
|
||||
endDate: bookingApi.endDate,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
case Error<List<BookingApiModel>>():
|
||||
return Result.error(result.error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user