hondavert-dev/lib/ui/screens/graph/widgets/graph_time_selector.dart
2026-10-13 00:34:11 +00:00

50 lines
1.5 KiB
Dart

import 'package:flutter/material.dart';
class GraphTimeSelector extends StatelessWidget {
final int windowSeconds;
final void Function(int seconds) onChanged;
static const _options = [30, 60, 120, 300];
const GraphTimeSelector({
super.key,
required this.windowSeconds,
required this.onChanged,
});
@override
Widget build(BuildContext context) {
final accent = Theme.of(context).colorScheme.primary;
return Row(
mainAxisSize: MainAxisSize.min,
children: _options.map((s) {
final selected = s == windowSeconds;
return GestureDetector(
onTap: () => onChanged(s),
child: AnimatedContainer(
duration: const Duration(milliseconds: 120),
margin: const EdgeInsets.only(left: 4),
padding:
const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
decoration: BoxDecoration(
color: selected ? accent.withAlpha(30) : Colors.transparent,
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: selected ? accent : Colors.white24,
),
),
child: Text(
s >= 60 ? '${s ~/ 60}m' : '${s}s',
style: TextStyle(
color: selected ? accent : Colors.white54,
fontSize: 12,
fontWeight: selected ? FontWeight.bold : FontWeight.normal,
),
),
),
);
}).toList(),
);
}
}