48 lines
1.3 KiB
Dart
48 lines
1.3 KiB
Dart
import 'package:flutter/material.dart';
|
||
|
||
import '../theme/tokens.dart';
|
||
|
||
/// The segmented block progress bar from Timbre'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 : TimbreColors.border,
|
||
),
|
||
),
|
||
);
|
||
}),
|
||
),
|
||
);
|
||
}
|
||
}
|