Files
xueguang_flutter_app/lib/widgets/base/empty/index.dart
zhutao b7239292d1 1
2025-11-20 18:00:34 +08:00

54 lines
1.2 KiB
Dart

import 'package:flutter/material.dart';
enum EmptyType {
data,
}
class Empty extends StatelessWidget {
final EmptyType type;
final String? text;
final Widget? child;
const Empty({
super.key,
this.type = EmptyType.data,
this.text,
this.child,
});
@override
Widget build(BuildContext context) {
var emptyImg = switch (type) {
EmptyType.data => Image.asset('assets/image/empty_data.png'),
};
var emptyText = switch (type) {
EmptyType.data => '暂无数据',
};
return Container(
padding: EdgeInsets.all(0),
child: Column(
children: [
FractionallySizedBox(
widthFactor: 0.5,
child: Container(
margin: EdgeInsets.only(bottom: 15),
child: emptyImg,
),
),
Text(
text ?? emptyText,
style: Theme.of(context).textTheme.labelLarge,
textAlign: TextAlign.center,
),
child != null
? Container(
margin: EdgeInsets.only(top: 15),
child: child,
)
: SizedBox(),
],
),
);
}
}