import 'package:flutter/material.dart'; import '../../../../core/models/sensor_defs.dart'; import '../../../../core/protocol/sensor_state.dart'; import '../../../theme/app_colors.dart'; /// Colour of an active flag. Faults red, warnings amber, status green/blue. Color flagColor(String id) { switch (id) { case 'mil': case 'knock': case 'o2error': case 'iaterror': case 'ecterror': return Colors.red; case 'revlimit': case 'igncut': case 'boostcut': case 'launch': case 'launchretard': case 'shiftcut': return Colors.orange; case 'vtec': case 'vtp': return Colors.blue; default: return Colors.green; } } class FlagPill extends StatelessWidget { final String label; final bool active; final Color color; const FlagPill({ super.key, required this.label, required this.active, required this.color, }); @override Widget build(BuildContext context) { final c = AppColors.of(context); return AnimatedContainer( duration: const Duration(milliseconds: 100), height: 30, alignment: Alignment.center, padding: const EdgeInsets.symmetric(horizontal: 6), decoration: BoxDecoration( color: active ? color.withAlpha(200) : c.surface, borderRadius: BorderRadius.circular(6), border: Border.all( color: active ? color : c.accent.withAlpha(90), width: 1.2, ), ), child: FittedBox( fit: BoxFit.scaleDown, child: Text( label, style: TextStyle( color: active ? Colors.white : c.onSurfaceMuted, fontSize: 12, fontWeight: active ? FontWeight.bold : FontWeight.normal, ), ), ), ); } } /// The 4 selectable flags of the dashboard. Long-press a pill to change it. class FlagRow extends StatelessWidget { final SensorState state; final List flagIds; final void Function(int index) onLongPress; const FlagRow({ super.key, required this.state, required this.flagIds, required this.onLongPress, }); @override Widget build(BuildContext context) { return Row( children: [ for (var i = 0; i < flagIds.length; i++) ...[ if (i > 0) const SizedBox(width: 6), Expanded( child: GestureDetector( onLongPress: () => onLongPress(i), child: FlagPill( label: flagDef(flagIds[i]).displayName, active: flagDef(flagIds[i]).read(state), color: flagColor(flagIds[i]), ), ), ), ], ], ); } }