starwork_flutter/lib/common/widgets/custom_cell_widget.dart

100 lines
3.1 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
class CustomCellWidget extends StatelessWidget {
const CustomCellWidget({
super.key,
required this.leftText,
this.leftSubText,
this.leftIcon,
this.rightWidget,
this.onTap,
this.visible = true,
});
final String leftText;
final String? leftSubText;
final Icon? leftIcon;
final Widget? rightWidget;
final GestureTapCallback? onTap;
final bool visible; // 控制是否显示
@override
Widget build(BuildContext context) {
// 如果不显示,返回空
if (!visible) {
return const SizedBox.shrink();
}
return GestureDetector(
onTap: onTap,
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(8.r)),
),
margin: EdgeInsets.symmetric(vertical: 10.h),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: 1,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
if (leftIcon != null) leftIcon!,
if (leftIcon != null) SizedBox(width: 4.w),
Expanded(
child: Text(
leftText,
style: TextStyle(
fontSize: 14.sp,
color: Colors.black87,
fontWeight: FontWeight.w400,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
],
),
if (leftSubText != null)
SizedBox(
height: 4.h,
),
if (leftSubText != null)
Text(
leftSubText!,
style: TextStyle(
fontSize: 11.sp,
color: Colors.grey,
fontWeight: FontWeight.w400,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
],
),
),
rightWidget ??
Text(
'未填写',
style: TextStyle(
fontSize: 14.sp,
color: Colors.black54,
fontWeight: FontWeight.w400,
),
),
],
),
),
);
}
}