mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-20 11:08:03 +08:00
* opt: sized * fix: self send * feat: ctrl enter to send * opt: checked * opt: download notifier * opt: Future.syncValue * mod: account * mod: loading state * opt: DebounceStreamMixin * opt: report * opt: enum map * opt: file handler * opt: dyn color * opt: Uint8List subview * opt: FileExt * opt: computeLuminance * opt: isNullOrEmpty * opt: Get context * update [skip ci] Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me> * opt dynamicColor [skip ci] Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me> * fixes [skip ci] * update Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me> * update Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me> --------- Signed-off-by: My-Responsitories <107370289+My-Responsitories@users.noreply.github.com> Co-authored-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
75 lines
1.5 KiB
Dart
75 lines
1.5 KiB
Dart
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
|
|
sealed class LoadingState<T> {
|
|
const LoadingState();
|
|
|
|
factory LoadingState.loading() => const Loading._internal();
|
|
|
|
bool get isSuccess => this is Success<T>;
|
|
|
|
T get data => switch (this) {
|
|
Success(:var response) => response,
|
|
_ => throw this,
|
|
};
|
|
|
|
T? get dataOrNull => switch (this) {
|
|
Success(:var response) => response,
|
|
_ => null,
|
|
};
|
|
|
|
Future<void> toast() => SmartDialog.showToast(toString());
|
|
}
|
|
|
|
class Loading extends LoadingState<Never> {
|
|
const Loading._internal();
|
|
|
|
@override
|
|
String toString() {
|
|
return 'ApiException: loading';
|
|
}
|
|
}
|
|
|
|
class Success<T> extends LoadingState<T> {
|
|
final T response;
|
|
const Success(this.response);
|
|
|
|
@override
|
|
bool operator ==(Object other) {
|
|
if (identical(this, other)) {
|
|
return true;
|
|
}
|
|
if (other is Success<T>) {
|
|
return response == other.response;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@override
|
|
int get hashCode => response.hashCode;
|
|
}
|
|
|
|
class Error extends LoadingState<Never> {
|
|
final int? code;
|
|
final String? errMsg;
|
|
const Error(this.errMsg, {this.code});
|
|
|
|
@override
|
|
bool operator ==(Object other) {
|
|
if (identical(this, other)) {
|
|
return true;
|
|
}
|
|
if (other is Error) {
|
|
return errMsg == other.errMsg && code == other.code;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@override
|
|
int get hashCode => Object.hash(errMsg, code);
|
|
|
|
@override
|
|
String toString() {
|
|
return errMsg ?? code?.toString() ?? '';
|
|
}
|
|
}
|