import 'package:flutter/material.dart'; import '../settings_theme.dart'; import 'health_models.dart'; class HealthCard extends StatelessWidget { const HealthCard({super.key, required this.title, required this.child}); final String title; final Widget child; @override Widget build(BuildContext context) { final content = Padding( padding: const EdgeInsets.all(16), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Text(title, style: settingsTextStyle(context, title: true)), const SizedBox(height: 12), child, ], ), ); return Card(child: content); } } class HealthMeter extends StatelessWidget { const HealthMeter({super.key, required this.label, required this.value}); final String label; final double? value; @override Widget build(BuildContext context) { final scheme = Theme.of(context).colorScheme; final percent = value == null ? null : value! * 100; final color = percent == null ? scheme.outline : percent >= healthMeterCritical ? scheme.error : percent >= healthMeterHigh ? scheme.tertiary : scheme.primary; return Row( children: [ Expanded( child: ExcludeSemantics( excluding: value == null, child: LinearProgressIndicator( value: value?.clamp(0, 1) ?? 0, color: color, semanticsLabel: label, ), ), ), const SizedBox(width: 10), Flexible( child: Text( '$label ${percent == null ? '—' : '${percent.toStringAsFixed(1)}%'}', ), ), ], ); } } class HealthRows extends StatelessWidget { const HealthRows(this.rows, {super.key}); final List<(String, String)> rows; @override Widget build(BuildContext context) => Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ for (final row in rows) Padding( padding: const EdgeInsets.symmetric(vertical: 3), child: Wrap( alignment: WrapAlignment.spaceBetween, children: [Text(row.$1), Text(row.$2)], ), ), ], ); } class HealthAction extends StatelessWidget { const HealthAction({super.key, required this.label, this.onPressed}); final String label; final VoidCallback? onPressed; @override Widget build(BuildContext context) => TextButton(onPressed: onPressed, child: Text(label)); }