40 lines
1.1 KiB
Dart
40 lines
1.1 KiB
Dart
import 'package:didvan/main.dart';
|
|
import 'package:didvan/models/enums.dart';
|
|
import 'package:didvan/utils/action_sheet.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
class CoreProvier with ChangeNotifier {
|
|
AppState _appState = AppState.busy;
|
|
|
|
/// وقتی provider dispose میشود این flag true میشود تا callback های
|
|
/// async (مثل fetch network) که بعد از dispose برمیگردند و `update()` را
|
|
/// صدا میزنند به جای throw، silently no-op شوند.
|
|
bool _disposed = false;
|
|
bool get isDisposed => _disposed;
|
|
|
|
@override
|
|
void dispose() {
|
|
_disposed = true;
|
|
super.dispose();
|
|
}
|
|
|
|
set appState(AppState newState) {
|
|
if (_disposed) return;
|
|
if (newState == AppState.isolatedBusy) {
|
|
ActionSheetUtils(navigatorKey.currentContext!).showLogoLoadingIndicator();
|
|
}
|
|
if (_appState == AppState.isolatedBusy) {
|
|
ActionSheetUtils(navigatorKey.currentContext!).pop();
|
|
}
|
|
_appState = newState;
|
|
notifyListeners();
|
|
}
|
|
|
|
void update() {
|
|
if (_disposed) return;
|
|
notifyListeners();
|
|
}
|
|
|
|
AppState get appState => _appState;
|
|
}
|