Files
MWClash/lib/widgets/chip.dart

51 lines
1.4 KiB
Dart
Raw Normal View History

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;
final VoidCallback? onPressed;
final ChipType type;
final Widget? avatar;
2024-04-30 23:38:49 +08:00
const CommonChip({
super.key,
required this.label,
this.onPressed,
this.avatar,
this.type = ChipType.action,
2024-04-30 23:38:49 +08:00
});
@override
Widget build(BuildContext context) {
if (type == ChipType.delete) {
return Chip(
avatar: avatar,
labelPadding: const EdgeInsets.symmetric(
vertical: 0,
horizontal: 4,
),
clipBehavior: Clip.antiAlias,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
onDeleted: onPressed ?? () {},
side:
BorderSide(color: Theme.of(context).dividerColor.withOpacity(0.2)),
labelStyle: Theme.of(context).textTheme.bodyMedium,
label: Text(label),
);
}
return ActionChip(
2024-04-30 23:38:49 +08:00
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
avatar: avatar,
clipBehavior: Clip.antiAlias,
labelPadding: const EdgeInsets.symmetric(
vertical: 0,
horizontal: 4,
),
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),
);
}
}