Files
smart-serow/pi/ui/lib/widgets/stat_box.dart

82 lines
2.3 KiB
Dart
Raw Normal View History

2026-01-25 18:47:35 +09:00
import 'package:flutter/material.dart';
import '../theme/app_theme.dart';
2026-01-26 15:47:59 +09:00
/// A labeled stat display box for the dashboard bottom row.
2026-01-25 18:47:35 +09:00
class StatBox extends StatelessWidget {
final String value;
2026-01-26 15:47:59 +09:00
final String? unit;
final String label;
final int flex;
2026-01-25 18:47:35 +09:00
2026-01-26 15:47:59 +09:00
const StatBox({
super.key,
required this.value,
this.unit,
required this.label,
this.flex = 1,
});
2026-01-25 18:47:35 +09:00
@override
Widget build(BuildContext context) {
final theme = AppTheme.of(context);
2026-01-26 11:35:17 +09:00
return Expanded(
2026-01-26 15:47:59 +09:00
flex: flex,
child: LayoutBuilder(
builder: (context, constraints) {
final baseSize = constraints.maxHeight * 0.4;
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// Value + optional unit
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: [
Text(
value,
style: TextStyle(
fontSize: baseSize,
fontWeight: FontWeight.w400,
fontFeatures: const [FontFeature.tabularFigures()],
color: theme.foreground,
height: 1,
),
),
SizedBox(width: baseSize * 0.1),
if (unit != null) ...[
const SizedBox(width: 4),
Text(
unit!,
style: TextStyle(
fontSize: baseSize * 0.5,
fontWeight: FontWeight.w400,
color: theme.subdued,
height: 1,
),
),
],
],
),
SizedBox(height: baseSize * 0.1),
// Label
Text(
label,
style: TextStyle(
fontSize: baseSize * 0.6,
fontWeight: FontWeight.w400,
color: theme.subdued,
letterSpacing: 1,
),
),
],
);
},
),
2026-01-25 18:47:35 +09:00
);
}
}