2024-03-18 13:23:58 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:get/get.dart';
|
2024-03-19 08:59:08 +08:00
|
|
|
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';
|
2024-03-18 13:23:58 +08:00
|
|
|
|
2024-03-26 15:30:43 +08:00
|
|
|
class LoadingUtil extends GetxService {
|
2024-03-19 10:02:20 +08:00
|
|
|
static LoadingUtil get to => Get.find();
|
|
|
|
OverlayEntry? _loadingOverlay;
|
|
|
|
|
|
|
|
Future<LoadingUtil> init() async {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> show({String? status}) async {
|
|
|
|
return showLoading(status: status);
|
2024-03-18 13:23:58 +08:00
|
|
|
}
|
|
|
|
|
2024-03-19 10:02:20 +08:00
|
|
|
Future<void> dismiss() async {
|
2024-03-18 13:23:58 +08:00
|
|
|
return hideLoading();
|
|
|
|
}
|
|
|
|
|
2024-03-19 10:02:20 +08:00
|
|
|
showLoading({String? status}) async {
|
|
|
|
hideLoading();
|
|
|
|
|
|
|
|
_loadingOverlay = OverlayEntry(
|
2024-03-19 08:59:08 +08:00
|
|
|
builder: (BuildContext context) {
|
2024-03-31 17:13:29 +08:00
|
|
|
return PopScope(
|
|
|
|
onPopInvoked: (_) {
|
|
|
|
hideLoading();
|
|
|
|
},
|
2024-03-19 10:02:20 +08:00
|
|
|
child: Stack(
|
|
|
|
children: <Widget>[
|
|
|
|
ModalBarrier(dismissible: false, color: AppTheme.barrierColor),
|
|
|
|
Center(
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
LoadingAnimationWidget.fourRotatingDots(
|
|
|
|
color: AppTheme.primaryColor,
|
2024-03-28 17:18:46 +08:00
|
|
|
size: ScreenAdaper.height(50),
|
2024-03-19 10:02:20 +08:00
|
|
|
),
|
|
|
|
if (status != null)
|
|
|
|
SizedBox(width: ScreenAdaper.width(20)),
|
|
|
|
if (status != null)
|
|
|
|
Text(status,
|
|
|
|
style: TextStyle(
|
2024-03-29 14:42:15 +08:00
|
|
|
decoration: TextDecoration.none,
|
2024-03-19 10:02:20 +08:00
|
|
|
color: AppTheme.primaryColor,
|
2024-03-29 14:42:15 +08:00
|
|
|
fontSize: ScreenAdaper.height(25)))
|
2024-03-19 10:02:20 +08:00
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
));
|
2024-03-19 08:59:08 +08:00
|
|
|
},
|
2024-03-18 13:23:58 +08:00
|
|
|
);
|
2024-03-26 15:30:43 +08:00
|
|
|
if (Get.overlayContext != null) {
|
|
|
|
Overlay.of(Get.overlayContext!).insert(_loadingOverlay!);
|
|
|
|
}
|
2024-03-18 13:23:58 +08:00
|
|
|
}
|
|
|
|
|
2024-03-19 10:02:20 +08:00
|
|
|
hideLoading() {
|
|
|
|
_loadingOverlay?.remove();
|
|
|
|
_loadingOverlay = null;
|
2024-03-18 13:23:58 +08:00
|
|
|
}
|
|
|
|
}
|