Add minwidth constraint to volume, split bottom bar rebuilder

This commit is contained in:
Oystein Kristoffer Tveit 2024-12-19 15:09:15 +01:00
parent 5911778b0a
commit 150e8e4b87
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146

View File

@ -58,17 +58,38 @@ class PlayerUIBottomBar extends StatelessWidget {
}, },
), ),
Expanded( Expanded(
child: LayoutBuilder(
builder: (context, constraint) {
return Row(
children: [
playerBlocBuilder(
buildProps: (p) => [p.currentPercentPosition, p.duration],
builder: (context, playerState) {
final milliseconds =
(playerState.currentPercentPosition! *
playerState.duration.inMilliseconds *
0.01)
.round();
return Text(
formatTime(
Duration(milliseconds: milliseconds),
),
);
},
),
Flexible(
flex: 5,
child: playerBlocBuilder( child: playerBlocBuilder(
buildProps: (p) => [ buildProps: (p) => [
p.cachedTimestamp, p.cachedTimestamp,
p.duration,
p.currentPercentPosition, p.currentPercentPosition,
p.volume, p.duration,
], ],
builder: (context, playerState) { builder: (context, playerState) {
// NOTE: slider throws if the value is over 100, so 99.999 is used to avoid // NOTE: slider throws if the value is over 100, so 99.999 is used to avoid
// hitting the limit with floating point errors. // hitting the limit with floating point errors.
double cachedPercent = playerState.cachedTimestamp != null double cachedPercent = playerState.cachedTimestamp !=
null
? ((playerState.cachedTimestamp! / ? ((playerState.cachedTimestamp! /
max(playerState.duration.inMilliseconds, max(playerState.duration.inMilliseconds,
0.00000000000001)) * 0.00000000000001)) *
@ -78,29 +99,7 @@ class PlayerUIBottomBar extends StatelessWidget {
if (0 < cachedPercent || cachedPercent > 100) { if (0 < cachedPercent || cachedPercent > 100) {
cachedPercent = 0; cachedPercent = 0;
} }
return Flex( return Slider(
direction: Axis.horizontal,
children: [
Text(
formatTime(
Duration(
milliseconds:
playerState.currentPercentPosition != null
? (playerState.currentPercentPosition! *
playerState.duration.inMilliseconds *
0.01)
.round()
: 0,
),
),
),
// Text(((playerState.currentPercentPosition ?? 0.0) *
// 0.01 *
// playerState.duration)
// .toString()),
Expanded(
flex: 5,
child: Slider(
value: playerState.currentPercentPosition ?? 0, value: playerState.currentPercentPosition ?? 0,
max: 100.0, max: 100.0,
secondaryTrackValue: cachedPercent, secondaryTrackValue: cachedPercent,
@ -109,13 +108,20 @@ class PlayerUIBottomBar extends StatelessWidget {
BlocProvider.of<ConnectionStateBloc>(context) BlocProvider.of<ConnectionStateBloc>(context)
.add(Command.time(value)); .add(Command.time(value));
}, },
);
},
), ),
), ),
playerBlocBuilder(
buildProps: (p) => [p.duration],
builder: (context, playerState) =>
Text(formatTime(playerState.duration)), Text(formatTime(playerState.duration)),
// TODO: set minimum width for this slider ),
Expanded( SizedBox(
flex: 1, width: max(constraint.maxWidth / 6, 200),
child: Slider( child: playerBlocBuilder(
buildProps: (p) => [p.volume],
builder: (context, playerState) => Slider(
value: playerState.volume, value: playerState.volume,
max: 130.0, max: 130.0,
secondaryTrackValue: 100.0, secondaryTrackValue: 100.0,
@ -125,7 +131,7 @@ class PlayerUIBottomBar extends StatelessWidget {
}, },
), ),
), ),
Text('${playerState.volume.round()}%'), )
], ],
); );
}, },