import 'package:flutter/material.dart'; import 'package:lszlgl/config/colors.dart'; import 'package:lszlgl/widget/button.dart'; enum PageState { loading, success, error, } class PageLoadingWidget extends StatelessWidget { final AlignmentGeometry? alignment; final bool isLoading; final String? title; final String? message; final String? btnText; final VoidCallback? onTap; final EdgeInsetsGeometry? padding; const PageLoadingWidget({ super.key, this.alignment, this.isLoading = false, this.title, this.message, this.btnText, this.onTap, this.padding = const EdgeInsets.only(top: 150), }); const PageLoadingWidget.loading({ super.key, this.alignment, this.message, this.padding = const EdgeInsets.only(top: 150), }) : isLoading = true, title = null, onTap = null, btnText = null; const PageLoadingWidget.empty({ super.key, this.alignment, this.message = '暂无数据', this.padding = const EdgeInsets.only(top: 150), }) : isLoading = false, title = null, onTap = null, btnText = null; const PageLoadingWidget.error({ super.key, this.alignment, this.title = '加载失败, 请重试', this.onTap, this.btnText = '点击重试', this.padding = const EdgeInsets.only(top: 150), }) : isLoading = false, message = null; @override Widget build(BuildContext context) { return Container( alignment: alignment ?? Alignment.center, padding: padding, child: Column( children: [ buildLoading(), buildTitle(), buildMessage(), buildButton(), ], ), ); } Widget buildLoading() { if (!isLoading) return const SizedBox.shrink(); return const Padding( padding: EdgeInsets.only(bottom: 12), child: CircularProgressIndicator(strokeWidth: 3), ); } Widget buildTitle() { if (title == null) return const SizedBox.shrink(); return Padding( padding: const EdgeInsets.only(bottom: 12), child: Text( title!, style: const TextStyle(fontSize: 16, color: MyColor.c_333333), ), ); } Widget buildMessage() { if (message == null) return const SizedBox.shrink(); return Padding( padding: const EdgeInsets.only(bottom: 12), child: Text( message!, style: const TextStyle(fontSize: 16, color: MyColor.c_666666), ), ); } Widget buildButton() { if (btnText == null) return const SizedBox.shrink(); return MyButton( btnText!, onTap: onTap, alignment: null, ); } }