Files
app-flutter/lib/widgets/telltale.dart
T

73 lines
2.0 KiB
Dart
Raw Normal View History

// An on/off lamp in the boxed pattern (lib/widgets/stat_box.dart): the label is the
// lamp. Takes a [Reading] (lib/reading.dart) so missing and stale draw as they do elsewhere.
import 'package:flutter/material.dart';
import '../reading.dart';
import '../theme/palette.dart';
/// An on/off lamp in the boxed pattern: the label is the lamp. Lit in foreground
/// (alarm when [warn]), dark in subdued; missing shows as a dash.
class Telltale extends StatelessWidget {
const Telltale({
super.key,
required this.label,
required this.reading,
this.icon,
this.warn = false,
this.flex = 1,
});
final String label;
/// Drawn instead of the label when set. Glyphs like ◀ ▶ come out as emoji on Android.
final IconData? icon;
final Reading reading;
final bool warn;
final int flex;
@override
Widget build(BuildContext context) {
final p = AppTheme.of(context);
final missing = reading.value == null;
final lit = reading.on && !reading.dim;
final color = lit
? (warn ? p.alarm : p.foreground)
: p.subdued.withValues(alpha: missing ? 0.35 : 0.6);
return Expanded(
flex: flex,
child: LayoutBuilder(
builder: (context, c) {
final size = c.maxHeight * 0.3;
if (icon != null && !missing) {
return Center(
child: Icon(
icon,
size: c.maxHeight * 0.7,
color: color,
semanticLabel: label,
),
);
}
return Center(
child: FittedBox(
fit: BoxFit.scaleDown,
child: Text(
missing ? '—' : label,
maxLines: 1,
style: TextStyle(
fontFamily: hudFont,
fontSize: size,
fontWeight: lit ? FontWeight.w700 : FontWeight.w400,
color: color,
letterSpacing: 1,
),
),
),
);
},
),
);
}
}