1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-10 14:58:34 +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:
Parker Lougheed
2024-12-05 21:38:14 +08:00
committed by GitHub
parent 33701ce1c5
commit c3c93a82f5
11 changed files with 26 additions and 26 deletions

View File

@@ -18,11 +18,11 @@
sealed class Result<T> {
const Result();
/// Creates an instance of Result containing a value
factory Result.ok(T value) => Ok(value);
/// Creates a successful [Result], completed with the specified [value].
const factory Result.ok(T value) = Ok._;
/// Create an instance of Result containing an error
factory Result.error(Exception error) => Error(error);
/// Creates an error [Result], completed with the specified [error].
const factory Result.error(Exception error) = Error._;
/// Convenience method to cast to Ok
Ok<T> get asOk => this as Ok<T>;
@@ -33,7 +33,7 @@ sealed class Result<T> {
/// Subclass of Result for values
final class Ok<T> extends Result<T> {
const Ok(this.value);
const Ok._(this.value);
/// Returned value in result
final T value;
@@ -44,7 +44,7 @@ final class Ok<T> extends Result<T> {
/// Subclass of Result for errors
final class Error<T> extends Result<T> {
const Error(this.error);
const Error._(this.error);
/// Returned error in result
final Exception error;