mirror of
https://github.com/flutter/samples.git
synced 2025-11-11 07:18:15 +00:00
[compass_app] Standardize on Result factories rather than constructors (#2538)
From my review of the recipes PR in https://github.com/flutter/website/pull/11444#pullrequestreview-2480423811.
This commit is contained in:
@@ -16,12 +16,12 @@ class AuthRepositoryDev extends AuthRepository {
|
||||
required String email,
|
||||
required String password,
|
||||
}) async {
|
||||
return Result.ok(null);
|
||||
return const Result.ok(null);
|
||||
}
|
||||
|
||||
/// Logout is always successful in dev scenarios
|
||||
@override
|
||||
Future<Result<void>> logout() async {
|
||||
return Result.ok(null);
|
||||
return const Result.ok(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class BookingRepositoryLocal implements BookingRepository {
|
||||
// Bookings created come without id, we need to assign one
|
||||
final bookingWithId = booking.copyWith(id: _sequentialId++);
|
||||
_bookings.add(bookingWithId);
|
||||
return Result.ok(null);
|
||||
return const Result.ok(null);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -92,6 +92,6 @@ class BookingRepositoryLocal implements BookingRepository {
|
||||
@override
|
||||
Future<Result<void>> delete(int id) async {
|
||||
_bookings.removeWhere((booking) => booking.id == id);
|
||||
return Result.ok(null);
|
||||
return const Result.ok(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,6 @@ class ItineraryConfigRepositoryMemory implements ItineraryConfigRepository {
|
||||
ItineraryConfig itineraryConfig,
|
||||
) async {
|
||||
_itineraryConfig = itineraryConfig;
|
||||
return Result.ok(true);
|
||||
return const Result.ok(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class ApiClient {
|
||||
return Result.ok(
|
||||
json.map((element) => Continent.fromJson(element)).toList());
|
||||
} else {
|
||||
return Result.error(const HttpException("Invalid response"));
|
||||
return const Result.error(HttpException("Invalid response"));
|
||||
}
|
||||
} on Exception catch (error) {
|
||||
return Result.error(error);
|
||||
@@ -74,7 +74,7 @@ class ApiClient {
|
||||
return Result.ok(
|
||||
json.map((element) => Destination.fromJson(element)).toList());
|
||||
} else {
|
||||
return Result.error(const HttpException("Invalid response"));
|
||||
return const Result.error(HttpException("Invalid response"));
|
||||
}
|
||||
} on Exception catch (error) {
|
||||
return Result.error(error);
|
||||
@@ -97,7 +97,7 @@ class ApiClient {
|
||||
json.map((element) => Activity.fromJson(element)).toList();
|
||||
return Result.ok(activities);
|
||||
} else {
|
||||
return Result.error(const HttpException("Invalid response"));
|
||||
return const Result.error(HttpException("Invalid response"));
|
||||
}
|
||||
} on Exception catch (error) {
|
||||
return Result.error(error);
|
||||
@@ -119,7 +119,7 @@ class ApiClient {
|
||||
json.map((element) => BookingApiModel.fromJson(element)).toList();
|
||||
return Result.ok(bookings);
|
||||
} else {
|
||||
return Result.error(const HttpException("Invalid response"));
|
||||
return const Result.error(HttpException("Invalid response"));
|
||||
}
|
||||
} on Exception catch (error) {
|
||||
return Result.error(error);
|
||||
@@ -139,7 +139,7 @@ class ApiClient {
|
||||
final booking = BookingApiModel.fromJson(jsonDecode(stringData));
|
||||
return Result.ok(booking);
|
||||
} else {
|
||||
return Result.error(const HttpException("Invalid response"));
|
||||
return const Result.error(HttpException("Invalid response"));
|
||||
}
|
||||
} on Exception catch (error) {
|
||||
return Result.error(error);
|
||||
@@ -160,7 +160,7 @@ class ApiClient {
|
||||
final booking = BookingApiModel.fromJson(jsonDecode(stringData));
|
||||
return Result.ok(booking);
|
||||
} else {
|
||||
return Result.error(const HttpException("Invalid response"));
|
||||
return const Result.error(HttpException("Invalid response"));
|
||||
}
|
||||
} on Exception catch (error) {
|
||||
return Result.error(error);
|
||||
@@ -180,7 +180,7 @@ class ApiClient {
|
||||
final user = UserApiModel.fromJson(jsonDecode(stringData));
|
||||
return Result.ok(user);
|
||||
} else {
|
||||
return Result.error(const HttpException("Invalid response"));
|
||||
return const Result.error(HttpException("Invalid response"));
|
||||
}
|
||||
} on Exception catch (error) {
|
||||
return Result.error(error);
|
||||
@@ -197,9 +197,9 @@ class ApiClient {
|
||||
final response = await request.close();
|
||||
// Response 204 "No Content", delete was successful
|
||||
if (response.statusCode == 204) {
|
||||
return Result.ok(null);
|
||||
return const Result.ok(null);
|
||||
} else {
|
||||
return Result.error(const HttpException("Invalid response"));
|
||||
return const Result.error(HttpException("Invalid response"));
|
||||
}
|
||||
} on Exception catch (error) {
|
||||
return Result.error(error);
|
||||
|
||||
@@ -32,7 +32,7 @@ class AuthApiClient {
|
||||
final stringData = await response.transform(utf8.decoder).join();
|
||||
return Result.ok(LoginResponse.fromJson(jsonDecode(stringData)));
|
||||
} else {
|
||||
return Result.error(const HttpException("Login error"));
|
||||
return const Result.error(HttpException("Login error"));
|
||||
}
|
||||
} on Exception catch (error) {
|
||||
return Result.error(error);
|
||||
|
||||
@@ -32,7 +32,7 @@ class SharedPreferencesService {
|
||||
_log.finer('Replaced token');
|
||||
await sharedPreferences.setString(_tokenKey, token);
|
||||
}
|
||||
return Result.ok(null);
|
||||
return const Result.ok(null);
|
||||
} on Exception catch (e) {
|
||||
_log.warning('Failed to set token', e);
|
||||
return Result.error(e);
|
||||
|
||||
Reference in New Issue
Block a user