cyberhybridhub/lib/widgets/hub_toolbar_icon_button.dart
nathanAndrinoid 4459852f83
Some checks failed
Admin portal tests / test (push) Has been cancelled
spelling
2026-06-05 03:22:35 +00:00

83 lines
2.3 KiB
Dart

import 'package:flutter/material.dart';
import '../theme/app_theme.dart';
/// Toolbar icon button shared by the signed-in home app bar and admin actions.
class HubToolbarIconButton extends StatelessWidget {
const HubToolbarIconButton({
super.key,
required this.icon,
required this.onPressed,
required this.tooltip,
this.iconColor = AppColors.textPrimary,
this.badgeCount,
});
final IconData icon;
final VoidCallback? onPressed;
final String tooltip;
final Color iconColor;
final int? badgeCount;
static const double slotWidth = 36;
static ButtonStyle pillStyle({Color? foregroundColor}) {
final Color color = foregroundColor ?? AppColors.textPrimary;
return IconButton.styleFrom(
backgroundColor: Colors.transparent,
foregroundColor: color,
disabledForegroundColor: color.withValues(alpha: 0.38),
iconSize: 22,
padding: const EdgeInsets.all(8),
minimumSize: const Size(slotWidth, slotWidth),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
);
}
@override
Widget build(BuildContext context) {
final Widget button = IconButton(
onPressed: onPressed,
tooltip: tooltip,
style: pillStyle(foregroundColor: iconColor),
icon: Icon(icon),
);
final int count = badgeCount ?? 0;
if (count < 1) {
return button;
}
return Stack(
clipBehavior: Clip.none,
alignment: Alignment.center,
children: <Widget>[
button,
Positioned(
top: 4,
right: 0,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 2),
decoration: BoxDecoration(
color: AppColors.accent,
borderRadius: BorderRadius.circular(10),
border: Border.all(color: AppColors.surface, width: 1.5),
),
constraints: const BoxConstraints(minWidth: 18, minHeight: 18),
child: Text(
'$count',
textAlign: TextAlign.center,
style: const TextStyle(
color: AppColors.background,
fontSize: 11,
fontWeight: FontWeight.w700,
height: 1.1,
),
),
),
),
],
);
}
}