WallPaper_FSX_Flutter/lib/common/components/view_state_widget.dart
fengshengxiong 9caadfb09a 1.按照UI图修改
2.完善其他功能
2024-05-17 17:02:22 +08:00

80 lines
1.6 KiB
Dart

// Author: fengshengxiong
// Date: 2024/5/7
// Description: 状态视图
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
/// 四种视图状态
enum ViewState { normal, error, loading, empty }
class ViewStateWidget extends StatelessWidget {
const ViewStateWidget({
super.key,
required this.viewState,
required this.child,
});
final ViewState viewState;
final Widget child;
@override
Widget build(BuildContext context) {
switch (viewState) {
case ViewState.normal:
return child;
case ViewState.loading:
return loadingView();
case ViewState.empty:
return emptyView;
case ViewState.error:
return errorView;
}
}
}
/// 加载中视图
Widget loadingView({
Color? color,
Animation<Color?>? valueColor,
Color? backgroundColor,
double? value,
}) {
return Center(
child: CircularProgressIndicator(
color: color,
valueColor: valueColor,
backgroundColor: backgroundColor ?? Colors.grey,
value: value,
),
);
}
/// 空视图
Widget get emptyView {
return Center(
child: Text(
'No data available',
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(0xFF666666),
fontSize: 14.sp,
),
),
);
}
/// 错误视图
Widget get errorView {
return Center(
child: Text(
'An error occurred, please try again later',
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(0xFF666666),
fontSize: 14.sp,
),
),
);
}