opt: common ctr

opt: state

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-05-11 12:21:42 +08:00
parent 5bff1747e6
commit 574bf861f0
129 changed files with 1065 additions and 1058 deletions

View File

@@ -1,23 +1,19 @@
import 'dart:core' hide Error;
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
sealed class LoadingState<T> {
const LoadingState();
factory LoadingState.loading() = Loading;
factory LoadingState.success(T response) = Success<T>;
factory LoadingState.error(String errMsg) = Error;
bool get isSuccess => this is Success<T>;
T get data => switch (this) {
Success(response: final res) => res,
Success(:var response) => response,
_ => throw this,
};
T? get dataOrNull => switch (this) {
Success(response: final res) => res,
Success(:var response) => response,
_ => null,
};
@@ -57,7 +53,7 @@ class Success<T> extends LoadingState<T> {
}
class Error extends LoadingState<Never> {
final String errMsg;
final String? errMsg;
const Error(this.errMsg);
@override