1
0
mirror of https://github.com/flutter/samples.git synced 2026-05-13 10:27:09 +00:00

Flutter 3.29 beta (#2571)

This commit is contained in:
Eric Windmill
2025-02-12 18:08:01 -05:00
committed by GitHub
parent d62c784789
commit 719fd72c38
685 changed files with 76244 additions and 53721 deletions

View File

@@ -10,18 +10,18 @@ import 'activity_repository.dart';
/// Local implementation of ActivityRepository
/// Uses data from assets folder
class ActivityRepositoryLocal implements ActivityRepository {
ActivityRepositoryLocal({
required LocalDataService localDataService,
}) : _localDataService = localDataService;
ActivityRepositoryLocal({required LocalDataService localDataService})
: _localDataService = localDataService;
final LocalDataService _localDataService;
@override
Future<Result<List<Activity>>> getByDestination(String ref) async {
try {
final activities = (await _localDataService.getActivities())
.where((activity) => activity.destinationRef == ref)
.toList();
final activities =
(await _localDataService.getActivities())
.where((activity) => activity.destinationRef == ref)
.toList();
return Result.ok(activities);
} on Exception catch (error) {

View File

@@ -11,9 +11,8 @@ import 'activity_repository.dart';
/// Implements basic local caching.
/// See: https://docs.flutter.dev/get-started/fwe/local-caching
class ActivityRepositoryRemote implements ActivityRepository {
ActivityRepositoryRemote({
required ApiClient apiClient,
}) : _apiClient = apiClient;
ActivityRepositoryRemote({required ApiClient apiClient})
: _apiClient = apiClient;
final ApiClient _apiClient;

View File

@@ -12,10 +12,7 @@ abstract class AuthRepository extends ChangeNotifier {
Future<bool> get isAuthenticated;
/// Perform login
Future<Result<void>> login({
required String email,
required String password,
});
Future<Result<void>> login({required String email, required String password});
/// Perform logout
Future<Result<void>> logout();

View File

@@ -17,9 +17,9 @@ class AuthRepositoryRemote extends AuthRepository {
required ApiClient apiClient,
required AuthApiClient authApiClient,
required SharedPreferencesService sharedPreferencesService,
}) : _apiClient = apiClient,
_authApiClient = authApiClient,
_sharedPreferencesService = sharedPreferencesService {
}) : _apiClient = apiClient,
_authApiClient = authApiClient,
_sharedPreferencesService = sharedPreferencesService {
_apiClient.authHeaderProvider = _authHeaderProvider;
}
@@ -64,10 +64,7 @@ class AuthRepositoryRemote extends AuthRepository {
}) async {
try {
final result = await _authApiClient.login(
LoginRequest(
email: email,
password: password,
),
LoginRequest(email: email, password: password),
);
switch (result) {
case Ok<LoginResponse>():

View File

@@ -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(

View File

@@ -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);
}

View File

@@ -9,9 +9,8 @@ import 'continent_repository.dart';
/// Local data source with all possible continents.
class ContinentRepositoryLocal implements ContinentRepository {
ContinentRepositoryLocal({
required LocalDataService localDataService,
}) : _localDataService = localDataService;
ContinentRepositoryLocal({required LocalDataService localDataService})
: _localDataService = localDataService;
final LocalDataService _localDataService;

View File

@@ -11,9 +11,8 @@ import 'continent_repository.dart';
/// Implements basic local caching.
/// See: https://docs.flutter.dev/get-started/fwe/local-caching
class ContinentRepositoryRemote implements ContinentRepository {
ContinentRepositoryRemote({
required ApiClient apiClient,
}) : _apiClient = apiClient;
ContinentRepositoryRemote({required ApiClient apiClient})
: _apiClient = apiClient;
final ApiClient _apiClient;

View File

@@ -10,9 +10,8 @@ import 'destination_repository.dart';
/// Local implementation of DestinationRepository
/// Uses data from assets folder
class DestinationRepositoryLocal implements DestinationRepository {
DestinationRepositoryLocal({
required LocalDataService localDataService,
}) : _localDataService = localDataService;
DestinationRepositoryLocal({required LocalDataService localDataService})
: _localDataService = localDataService;
final LocalDataService _localDataService;

View File

@@ -11,9 +11,8 @@ import 'destination_repository.dart';
/// Implements basic local caching.
/// See: https://docs.flutter.dev/get-started/fwe/local-caching
class DestinationRepositoryRemote implements DestinationRepository {
DestinationRepositoryRemote({
required ApiClient apiClient,
}) : _apiClient = apiClient;
DestinationRepositoryRemote({required ApiClient apiClient})
: _apiClient = apiClient;
final ApiClient _apiClient;

View File

@@ -8,9 +8,8 @@ import '../../services/local/local_data_service.dart';
import 'user_repository.dart';
class UserRepositoryLocal implements UserRepository {
UserRepositoryLocal({
required LocalDataService localDataService,
}) : _localDataService = localDataService;
UserRepositoryLocal({required LocalDataService localDataService})
: _localDataService = localDataService;
final LocalDataService _localDataService;

View File

@@ -9,9 +9,7 @@ import '../../services/api/model/user/user_api_model.dart';
import 'user_repository.dart';
class UserRepositoryRemote implements UserRepository {
UserRepositoryRemote({
required ApiClient apiClient,
}) : _apiClient = apiClient;
UserRepositoryRemote({required ApiClient apiClient}) : _apiClient = apiClient;
final ApiClient _apiClient;