初始化

This commit is contained in:
谢宇宁
2026-09-15 15:44:13 +07:00
commit a23ba685e9
1065 changed files with 101122 additions and 0 deletions
@@ -0,0 +1,101 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class LoadingAlertWidget extends StatefulWidget {
final String? title;
final bool canCancel;
const LoadingAlertWidget({super.key, this.title, this.canCancel = false});
static GlobalKey<_LoadingAlertWidgetState>? _globalKey;
static int showCount = 0;
static show({String? title, bool canCancel = false}) {
_globalKey = GlobalKey<_LoadingAlertWidgetState>();
showCount++;
Get.dialog(
LoadingAlertWidget(key: _globalKey, title: title, canCancel: canCancel),
barrierColor: Colors.transparent,
);
}
static showExchangeTitle(String title) {
_globalKey?.currentState?._flushTitle(title);
}
static cancel() {
_globalKey = null;
if (showCount > 0) {
Get.back();
showCount--;
}
}
@override
State<StatefulWidget> createState() {
return _LoadingAlertWidgetState();
}
}
class _LoadingAlertWidgetState extends State<LoadingAlertWidget> {
late String title;
@override
void initState() {
super.initState();
title = widget.title ?? "加载中...";
}
void _flushTitle(String text) {
title = text;
setState(() {});
}
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
if (widget.canCancel == true) {
LoadingAlertWidget._globalKey = null;
return true;
}
return false;
},
child: Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
color: Colors.black45,
height: 100,
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: 36,
height: 36,
child: CircularProgressIndicator(
backgroundColor: Colors.grey[500],
valueColor: const AlwaysStoppedAnimation(Colors.white70),
strokeWidth: 2,
),
),
const SizedBox(height: 12),
Text(
title,
style: const TextStyle(
fontSize: 12,
color: Colors.white,
fontWeight: FontWeight.normal,
decoration: TextDecoration.none,
),
),
],
),
),
),
),
);
}
}
@@ -0,0 +1,121 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hgdj/assets_tool/app_colors.dart';
import 'package:hgdj/assets_tool/images.dart';
import 'package:hgdj/hj_utils/screen.dart';
import 'package:loading_animation_widget/loading_animation_widget.dart';
int logicMultiCount = 0;
class LoadingWidget extends StatelessWidget {
final double? width;
final double? height;
final double size;
const LoadingWidget(
{super.key, this.width = 40, this.height = 20, this.size = 40});
@override
Widget build(BuildContext context) {
return LoadingAnimationWidget.horizontalRotatingDots(
color: Colors.white, size: size);
}
}
class LoadingCenterWidget extends StatelessWidget {
final double? width;
final double? height;
static int showCount = 0;
const LoadingCenterWidget({super.key, this.width = 40, this.height = 20});
static show() async {
showCount++;
await Get.dialog(const LoadingCenterWidget());
showCount--;
}
static cancel() {
if (showCount > 0) {
Get.back();
}
}
@override
Widget build(BuildContext context) {
return Center(
child: LoadingWidget(
width: width,
height: height,
),
);
}
}
class CErrorWidget extends StatefulWidget {
final String? errorMsg;
final String? errorMsg2;
final VoidCallback? retryOnTap;
const CErrorWidget(
{super.key, this.errorMsg = "什么也没有...", this.errorMsg2, this.retryOnTap});
@override
State<CErrorWidget> createState() => _CErrorWidgetState();
}
class _CErrorWidgetState extends State<CErrorWidget> {
bool _isRetrying = false;
Future<void> _handleRetry() async {
if (_isRetrying || widget.retryOnTap == null) return;
setState(() => _isRetrying = true);
try {
final result = (widget.retryOnTap as dynamic Function())();
if (result is Future) {
await result;
}
} finally {
if (mounted) setState(() => _isRetrying = false);
}
}
@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (_, cons) {
if (cons.maxHeight < 146) return SizedBox.shrink();
if (_isRetrying) {
return const Center(child: LoadingWidget());
}
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset('ic_nodata.webp'.commonImgPath, height: 120),
4.sizeBoxH,
Text(
widget.errorMsg ?? '',
style: TextStyle(
color: Colors.white.withValues(alpha: 0.6), fontSize: 12),
),
if (widget.retryOnTap != null) ...[
4.sizeBoxH,
InkWell(
enableFeedback: false,
onTap: _handleRetry,
child: Container(
padding: const EdgeInsets.fromLTRB(12, 8, 12, 12),
child: Text(
"点击重试",
style: TextStyle(
color: AppColors.actionRed,
fontSize: 12,
),
),
),
),
]
],
),
);
});
}
}
@@ -0,0 +1,37 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hgdj/assets_tool/app_colors.dart';
import 'package:hgdj/hj_utils/screen.dart';
import 'package:hgdj/tools_base/loading/loading_center_widget.dart';
import '../../hj_utils/widget_util.dart';
class LoadingHelper {
static void showLoading({bool dismissiable = false, String msg = ''}) {
Get.dialog(
Scaffold(
backgroundColor: Colors.transparent,
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const LoadingCenterWidget(),
if (msg.isNotEmpty) ...[
4.sizeBoxH,
Text(
msg,
style:
textStyle(16, AppColors.mainTextColor33, FontWeight.w500),
),
]
],
),
),
),
barrierColor: Colors.transparent,
barrierDismissible: dismissiable,
);
}
static void dismissLoading() => Get.back();
}