2024-06-19 13:13:31 +08:00
|
|
|
import 'package:fl_clash/enum/enum.dart';
|
2024-04-30 23:38:49 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
|
|
class CommonChip extends StatelessWidget {
|
|
|
|
|
final String label;
|
2024-06-19 13:13:31 +08:00
|
|
|
final VoidCallback? onPressed;
|
|
|
|
|
final ChipType type;
|
|
|
|
|
final Widget? avatar;
|
2024-04-30 23:38:49 +08:00
|
|
|
|
|
|
|
|
const CommonChip({
|
|
|
|
|
super.key,
|
|
|
|
|
required this.label,
|
2024-06-19 13:13:31 +08:00
|
|
|
this.onPressed,
|
|
|
|
|
this.avatar,
|
|
|
|
|
this.type = ChipType.action,
|
2024-04-30 23:38:49 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2024-06-23 00:26:24 +08:00
|
|
|
if (type == ChipType.delete) {
|
2024-06-19 13:13:31 +08:00
|
|
|
return Chip(
|
|
|
|
|
avatar: avatar,
|
2025-02-03 23:32:00 +08:00
|
|
|
labelPadding: const EdgeInsets.symmetric(
|
2024-06-23 00:26:24 +08:00
|
|
|
vertical: 0,
|
|
|
|
|
horizontal: 4,
|
|
|
|
|
),
|
2025-02-03 23:32:00 +08:00
|
|
|
clipBehavior: Clip.antiAlias,
|
2024-06-19 13:13:31 +08:00
|
|
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
|
|
|
onDeleted: onPressed ?? () {},
|
2024-06-23 00:26:24 +08:00
|
|
|
side:
|
|
|
|
|
BorderSide(color: Theme.of(context).dividerColor.withOpacity(0.2)),
|
2024-06-19 13:13:31 +08:00
|
|
|
labelStyle: Theme.of(context).textTheme.bodyMedium,
|
|
|
|
|
label: Text(label),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return ActionChip(
|
2024-04-30 23:38:49 +08:00
|
|
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
2024-06-19 13:13:31 +08:00
|
|
|
avatar: avatar,
|
2025-02-03 23:32:00 +08:00
|
|
|
clipBehavior: Clip.antiAlias,
|
|
|
|
|
labelPadding: const EdgeInsets.symmetric(
|
2024-06-23 00:26:24 +08:00
|
|
|
vertical: 0,
|
|
|
|
|
horizontal: 4,
|
|
|
|
|
),
|
2024-06-19 13:13:31 +08:00
|
|
|
onPressed: onPressed ?? () {},
|
2024-04-30 23:38:49 +08:00
|
|
|
side: BorderSide(color: Theme.of(context).dividerColor.withOpacity(0.2)),
|
|
|
|
|
labelStyle: Theme.of(context).textTheme.bodyMedium,
|
|
|
|
|
label: Text(label),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|