mobile-music/lib/widgets/block_progress_bar.dart
2026-07-29 14:14:18 -04:00

48 lines
1.3 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/material.dart';
import '../theme/tokens.dart';
/// The segmented block progress bar from Ratune's now-playing strip
/// (`progress_style = "██░"`). Discrete cells: filled cells use the accent,
/// empty cells the border grey, with hairline gaps between them.
class BlockProgressBar extends StatelessWidget {
const BlockProgressBar({
super.key,
required this.progress,
this.cells = 40,
this.height = 10,
this.color,
}) : assert(progress >= 0 && progress <= 1);
/// 0.0–1.0 elapsed fraction.
final double progress;
/// Number of block cells to render.
final int cells;
final double height;
/// Filled color; defaults to the theme accent.
final Color? color;
@override
Widget build(BuildContext context) {
final filledColor = color ?? Theme.of(context).colorScheme.primary;
final filled = (progress * cells).round();
return SizedBox(
height: height,
child: Row(
children: List.generate(cells, (i) {
return Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 0.5),
child: ColoredBox(
color: i < filled ? filledColor : RatuneColors.border,
),
),
);
}),
),
);
}
}