A simple view for different status: loading, success, empty, error, unauthorized.
loading | success | empty | error | unauthorized |
---|---|---|---|---|
Add the dependency in pubspec.yaml
:
dependencies:
...
load_status_view: ^0.0.1
///
LoadStatus loadStatus = LoadStatus.loading;
///
LoadStatusView(status: loadStatus,
errorCall: _retry,
child: const Center(
child: Text('content'),
),
)
/// init load data
_loadData() {
_setStatus(LoadStatus.loading);
Future.delayed(Duration(seconds: 2), () {
_setStatus(LoadStatus.success);
});
}
///
_retry() {
_loadData();
}
///
_setStatus(LoadStatus status) {
setState(() {
loadStatus = status;
});
}
see example