初始化
This commit is contained in:
@@ -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,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
]
|
||||
],
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user