mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-23 20:12:35 +08:00
opt: common ctr
opt: state Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user