118 lines
3.4 KiB
Dart
118 lines
3.4 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
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,
|
|
],
|
|
),
|
|
);
|
|
if (!usesCupertinoControls(context)) return Card(child: content);
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
child: DecoratedBox(
|
|
decoration: BoxDecoration(
|
|
color: CupertinoColors.secondarySystemGroupedBackground.resolveFrom(
|
|
context,
|
|
),
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: DefaultTextStyle(
|
|
style: settingsTextStyle(context),
|
|
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 cupertino = usesCupertinoControls(context);
|
|
final normal = cupertino
|
|
? CupertinoTheme.of(context).primaryColor
|
|
: scheme.primary;
|
|
final high = cupertino
|
|
? CupertinoColors.systemOrange.resolveFrom(context)
|
|
: scheme.tertiary;
|
|
final critical = cupertino
|
|
? CupertinoColors.systemRed.resolveFrom(context)
|
|
: scheme.error;
|
|
final color = percent == null
|
|
? scheme.outline
|
|
: percent >= healthMeterCritical
|
|
? critical
|
|
: percent >= healthMeterHigh
|
|
? high
|
|
: normal;
|
|
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) => usesCupertinoControls(context)
|
|
? CupertinoButton(onPressed: onPressed, child: Text(label))
|
|
: TextButton(onPressed: onPressed, child: Text(label));
|
|
}
|