mirror of
https://github.com/hmalik144/easy_cc_flutter.git
synced 2025-12-10 03:05:34 +00:00
32 lines
616 B
Dart
32 lines
616 B
Dart
import 'package:stacked/stacked.dart';
|
|
|
|
import 'Utils/view_state.dart';
|
|
|
|
abstract class BaseViewmodel extends BaseViewModel{
|
|
|
|
ViewState _viewState = Idle();
|
|
ViewState get viewState => _viewState;
|
|
|
|
void onStart() {
|
|
_viewState = HasStarted();
|
|
notifyListeners();
|
|
}
|
|
|
|
void onSuccess(dynamic data) {
|
|
_viewState = HasData(data);
|
|
notifyListeners();
|
|
}
|
|
|
|
void onError(String error) {
|
|
_viewState = HasError(error);
|
|
notifyListeners();
|
|
}
|
|
|
|
dynamic getData() {
|
|
if (viewState.runtimeType is HasData) {
|
|
return (viewState as HasData).data;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
} |