69 lines
2.1 KiB
Dart
69 lines
2.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:loading_animation_widget/loading_animation_widget.dart';
|
|
import 'package:sk_base_mobile/app_theme.dart';
|
|
import 'package:sk_base_mobile/util/screen_adaper_util.dart';
|
|
|
|
class LoadingUtil extends GetxService {
|
|
static LoadingUtil get to => Get.find();
|
|
// must use LoadingUtil.to.show() instead of LoadingUtil().show()
|
|
OverlayEntry? _loadingOverlay;
|
|
|
|
Future<LoadingUtil> init() async {
|
|
return this;
|
|
}
|
|
|
|
Future<void> show({String? status}) async {
|
|
return showLoading(status: status);
|
|
}
|
|
|
|
Future<void> dismiss() async {
|
|
return _hideLoading();
|
|
}
|
|
|
|
showLoading({String? status}) async {
|
|
_hideLoading();
|
|
|
|
_loadingOverlay = OverlayEntry(
|
|
builder: (BuildContext context) {
|
|
return PopScope(
|
|
onPopInvoked: (_) {
|
|
_hideLoading();
|
|
},
|
|
child: Stack(
|
|
children: <Widget>[
|
|
ModalBarrier(dismissible: false, color: AppTheme.barrierColor),
|
|
Center(
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
LoadingAnimationWidget.fourRotatingDots(
|
|
color: AppTheme.primaryColor,
|
|
size: ScreenAdaper.height(50),
|
|
),
|
|
if (status != null)
|
|
SizedBox(width: ScreenAdaper.width(20)),
|
|
if (status != null)
|
|
Text(status,
|
|
style: TextStyle(
|
|
decoration: TextDecoration.none,
|
|
color: AppTheme.primaryColor,
|
|
fontSize: ScreenAdaper.height(25)))
|
|
],
|
|
),
|
|
)
|
|
],
|
|
));
|
|
},
|
|
);
|
|
if (Get.overlayContext != null) {
|
|
Overlay.of(Get.overlayContext!).insert(_loadingOverlay!);
|
|
}
|
|
}
|
|
|
|
_hideLoading() {
|
|
_loadingOverlay?.remove();
|
|
_loadingOverlay = null;
|
|
}
|
|
}
|