diet-guard/app/lib/widgets/body/body_section.dart
Krzysztof kuhy Rudnicki 49144a2c49 Move the app to material_ui for Flutter 3.50
Flutter 3.50 deprecates package:flutter/material.dart; 73 deprecation
infos failed flutter analyze --fatal-infos, and four Dart pins were
behind (crdt_sync_flutter 0.8.2, flutter_local_notifications 23.0.2,
github_device_auth 0.5.0, sync_settings_ui 0.8.2). Those UI packages
now sit on material_ui, so the app has to as well or their widgets lose
MaterialLocalizations.

Imports swap one-for-one and dart fix re-sorted the directives; no
behaviour change. analyze is clean and all six test shards pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWWfb63jncj9Lca2jeX
2026-11-16 09:25:34 +01:00

115 lines
3.2 KiB
Dart

/// A card, the building block of every Body screen section, plus the
/// icon-led stat rows the cards are made of. No headings: the overview tile
/// that opened the sheet already says what it is.
library;
import 'package:diet_guard_app/services/body_calc.dart';
import 'package:diet_guard_app/ui/theme.dart';
import 'package:material_ui/material_ui.dart';
/// A card with [children] stacked in it; [semanticLabel] names it for screen
/// readers and tests and is never painted.
class BodySection extends StatelessWidget {
/// Creates a section.
const BodySection({
required this.semanticLabel,
required this.children,
super.key,
});
/// Spoken name of the section.
final String semanticLabel;
/// Section content.
final List<Widget> children;
@override
Widget build(BuildContext context) {
return Semantics(
container: true,
label: semanticLabel,
child: Card(
margin: const EdgeInsets.only(bottom: AppSpacing.md),
child: Padding(
padding: const EdgeInsets.all(AppSpacing.md),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: children,
),
),
),
);
}
}
/// One line of a stats card: a leading mark on the left, a value on the right.
///
/// The mark is either a formula name ([BodyStatRow.named]: a proper noun such
/// as Devine or ACSM, shown as is) or an icon ([BodyStatRow.icon]).
class BodyStatRow extends StatelessWidget {
/// A row led by a formula's proper name.
const BodyStatRow.named(this.name, this.value, {this.color, super.key})
: icon = null,
semanticLabel = null;
/// A row led by [icon], spoken as [semanticLabel].
const BodyStatRow.icon(
IconData this.icon,
String this.semanticLabel,
this.value, {
this.color,
super.key,
}) : name = null;
/// Proper-noun lead, or null when an icon leads.
final String? name;
/// Icon lead, or null when a name leads.
final IconData? icon;
/// Spoken description of [icon].
final String? semanticLabel;
/// The formatted value.
final String value;
/// Optional value color (e.g. a warning).
final Color? color;
@override
Widget build(BuildContext context) {
final lead = icon;
return Padding(
padding: const EdgeInsets.symmetric(vertical: AppSpacing.xs / 2),
child: Row(
children: [
Expanded(
child: lead == null
? Text(name!)
: Align(
alignment: Alignment.centerLeft,
child: Icon(lead, size: 20, semanticLabel: semanticLabel),
),
),
Text(
value,
style: TextStyle(
color: color,
fontFeatures: const [FontFeature.tabularFigures()],
),
),
],
),
);
}
}
/// `74.99` -> `"75.0 kg"`, null -> a dash. Half-up, like the PC.
String formatKg(double? kg) => kg == null ? '—' : '${oneDecimal(kg)} kg';
/// [value] to one decimal, rounded half-up like the PC prints it.
String oneDecimal(double value) => halfUp(value, 1).toStringAsFixed(1);
/// [value] as a whole number, rounded half-up like the PC prints it.
String whole(double value) => halfUp(value).toInt().toString();