mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
结构初始化
This commit is contained in:
36
lib/core/provider_base.dart
Normal file
36
lib/core/provider_base.dart
Normal file
@@ -0,0 +1,36 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
class ProviderBase with ChangeNotifier {
|
||||
void setState(void Function() callback) {
|
||||
callback();
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
enum ProviderState {
|
||||
idle,
|
||||
busy,
|
||||
}
|
||||
|
||||
class BusyProvider extends ProviderBase {
|
||||
bool _isBusy = false;
|
||||
bool get isBusy => _isBusy;
|
||||
|
||||
setBusyState([bool isBusy = true]) {
|
||||
_isBusy = isBusy;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
FutureOr<T> busyRun<T>(FutureOr<T> Function() func) async {
|
||||
setBusyState(true);
|
||||
try {
|
||||
return await Future.sync(func);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
} finally {
|
||||
setBusyState(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user