123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- 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,
- );
- }
- }
|