uninav/lib/components/colorful_chips.dart

58 lines
1.5 KiB
Dart
Raw Permalink Normal View History

2024-04-20 22:35:16 +00:00
import 'package:flutter/material.dart';
class ColorfulChip extends StatelessWidget {
final String label;
const ColorfulChip({Key? key, required this.label}) : super(key: key);
@override
Widget build(BuildContext context) {
final color = Color(((label.hashCode) & 0xFFFFFF) | 0xFF000000);
return Chip(
label: Text(label),
backgroundColor: color,
labelStyle: TextStyle(
color: color.computeLuminance() > 0.5 ? Colors.black : Colors.white,
),
2024-04-21 00:22:53 +00:00
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
side: BorderSide.none,
),
2024-04-20 22:35:16 +00:00
);
}
}
class ColorfulActionChip extends StatelessWidget {
final String label;
final VoidCallback onPressed;
2024-04-21 00:22:53 +00:00
final double? size;
2024-04-20 22:35:16 +00:00
const ColorfulActionChip({
Key? key,
required this.label,
required this.onPressed,
2024-04-21 00:22:53 +00:00
this.size,
2024-04-20 22:35:16 +00:00
}) : super(key: key);
@override
Widget build(BuildContext context) {
final color = Color(
((label.hashCode - 5 /* randomness - */) & 0xFFFFFF) | 0xFF000000);
return ActionChip(
label: Text(label),
backgroundColor: color,
labelStyle: TextStyle(
color: color.computeLuminance() > 0.5 ? Colors.black : Colors.white,
2024-04-21 00:22:53 +00:00
fontSize: size,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
side: BorderSide.none,
2024-04-20 22:35:16 +00:00
),
onPressed: onPressed,
2024-04-21 00:22:53 +00:00
padding: EdgeInsets.symmetric(
horizontal: (size ?? 16) / 2, vertical: (size ?? 8.0) / 2),
2024-04-20 22:35:16 +00:00
);
}
}