mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
refactor Result class, remove asOk and asError (#2542)
As discussed in the PR for the Result pattern implementation (https://github.com/flutter/website/pull/11444) @parlough recommended that `asError` and `asOk` should be not be used, and instead we should use proper exhaustiveness checking. This PR removes the two "convenience" methods and refactors code. In some cases, it was enough with writing a proper `if` clause, while in others it was necessary to use a `switch`. Still, they are present in the `testing` folder, as they can be useful for testing purposes. ## Pre-launch Checklist - [x] I read the [Flutter Style Guide] _recently_, and have followed its advice. - [x] I signed the [CLA]. - [x] I read the [Contributors Guide]. - [x] I have added sample code updates to the [changelog]. - [x] I updated/added relevant documentation (doc comments with `///`). If you need help, consider asking for advice on the #hackers-devrel channel on [Discord]. <!-- Links --> [Flutter Style Guide]: https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md [CLA]: https://cla.developers.google.com/ [Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md [Contributors Guide]: https://github.com/flutter/samples/blob/main/CONTRIBUTING.md [changelog]: ../CHANGELOG.md
This commit is contained in:
@@ -7,6 +7,8 @@ import 'package:compass_app/data/services/local/local_data_service.dart';
|
||||
import 'package:compass_app/utils/result.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../../../../testing/utils/result.dart';
|
||||
|
||||
void main() {
|
||||
group('ActivityRepositoryLocal tests', () {
|
||||
// To load assets
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:compass_app/utils/result.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../../../../testing/fakes/services/fake_api_client.dart';
|
||||
import '../../../../testing/utils/result.dart';
|
||||
|
||||
void main() {
|
||||
group('ActivityRepositoryRemote tests', () {
|
||||
|
||||
@@ -9,6 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../../../../testing/fakes/services/fake_api_client.dart';
|
||||
import '../../../../testing/models/booking.dart';
|
||||
import '../../../../testing/utils/result.dart';
|
||||
|
||||
void main() {
|
||||
group('BookingRepositoryRemote tests', () {
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:compass_app/utils/result.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../../../../testing/fakes/services/fake_api_client.dart';
|
||||
import '../../../../testing/utils/result.dart';
|
||||
|
||||
void main() {
|
||||
group('ContinentRepositoryRemote tests', () {
|
||||
|
||||
@@ -7,6 +7,8 @@ import 'package:compass_app/utils/result.dart';
|
||||
import 'package:compass_app/data/repositories/destination/destination_repository_local.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../../../../testing/utils/result.dart';
|
||||
|
||||
void main() {
|
||||
group('DestinationRepositoryLocal tests', () {
|
||||
// To load assets
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:compass_app/utils/result.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../../../../testing/fakes/services/fake_api_client.dart';
|
||||
import '../../../../testing/utils/result.dart';
|
||||
|
||||
void main() {
|
||||
group('DestinationRepositoryRemote tests', () {
|
||||
|
||||
@@ -12,6 +12,7 @@ import '../../../../testing/models/activity.dart';
|
||||
import '../../../../testing/models/booking.dart';
|
||||
import '../../../../testing/models/destination.dart';
|
||||
import '../../../../testing/models/user.dart';
|
||||
import '../../../../testing/utils/result.dart';
|
||||
|
||||
void main() {
|
||||
group('ApiClient', () {
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:compass_app/data/services/api/model/login_response/login_respons
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../../../../testing/mocks.dart';
|
||||
import '../../../../testing/utils/result.dart';
|
||||
|
||||
void main() {
|
||||
group('AuthApiClient', () {
|
||||
|
||||
@@ -12,6 +12,7 @@ import '../../../../testing/fakes/repositories/fake_destination_repository.dart'
|
||||
import '../../../../testing/models/activity.dart';
|
||||
import '../../../../testing/models/booking.dart';
|
||||
import '../../../../testing/models/destination.dart';
|
||||
import '../../../../testing/utils/result.dart';
|
||||
|
||||
void main() {
|
||||
group('BookingCreateUseCase tests', () {
|
||||
|
||||
@@ -6,6 +6,8 @@ import 'package:compass_app/utils/command.dart';
|
||||
import 'package:compass_app/utils/result.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../../testing/utils/result.dart';
|
||||
|
||||
void main() {
|
||||
group('Command0 tests', () {
|
||||
test('should complete void command', () async {
|
||||
@@ -89,7 +91,7 @@ void main() {
|
||||
test('should complete bool command, bool argument', () async {
|
||||
// Action that returns bool argument
|
||||
final command =
|
||||
Command1<bool, bool>((a) => Future.value(Result.ok(true)));
|
||||
Command1<bool, bool>((a) => Future.value(const Result.ok(true)));
|
||||
|
||||
// Run action with result and argument
|
||||
await command.execute(true);
|
||||
|
||||
Reference in New Issue
Block a user