fix: excessive repaints caused by Player progress bar

This commit is contained in:
Kingkor Roy Tirtho 2023-06-10 14:22:19 +06:00
parent 4ec04240a5
commit 09b24cf1fd
2 changed files with 287 additions and 276 deletions

View File

@ -89,7 +89,8 @@ class PlayerControls extends HookConsumerWidget {
iconSize: compact ? 18 : 24,
);
return GestureDetector(
return RepaintBoundary(
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
if (focusNode.canRequestFocus) {
@ -146,7 +147,8 @@ class PlayerControls extends HookConsumerWidget {
// than total duration. Keeping it resolved
value: progress.value.toDouble(),
secondaryTrackValue: bufferProgress,
onChanged: playlist.isFetching == true || buffering
onChanged:
playlist.isFetching == true || buffering
? null
: (v) {
progress.value = v;
@ -154,12 +156,14 @@ class PlayerControls extends HookConsumerWidget {
onChangeEnd: (value) async {
await audioPlayer.seek(
Duration(
seconds: (value * duration.inSeconds).toInt(),
seconds:
(value * duration.inSeconds).toInt(),
),
);
},
activeColor: sliderColor,
secondaryActiveColor: sliderColor.withOpacity(0.2),
secondaryActiveColor:
sliderColor.withOpacity(0.2),
inactiveColor: sliderColor.withOpacity(0.15),
),
),
@ -172,7 +176,8 @@ class PlayerControls extends HookConsumerWidget {
color: palette?.dominantColor?.bodyTextColor,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text("$currentMinutes:$currentSeconds"),
Text("$totalMinutes:$totalSeconds"),
@ -251,7 +256,8 @@ class PlayerControls extends HookConsumerWidget {
StreamBuilder<PlaybackLoopMode>(
stream: audioPlayer.loopModeStream,
builder: (context, snapshot) {
final loopMode = snapshot.data ?? PlaybackLoopMode.none;
final loopMode =
snapshot.data ?? PlaybackLoopMode.none;
return IconButton(
tooltip: loopMode == PlaybackLoopMode.one
? context.l10n.loop_track
@ -294,6 +300,7 @@ class PlayerControls extends HookConsumerWidget {
),
),
),
),
);
}
}

View File

@ -62,6 +62,7 @@ class PlayerOverlay extends HookConsumerWidget {
child: AnimatedOpacity(
duration: const Duration(milliseconds: 250),
opacity: canShow ? 1 : 0,
child: RepaintBoundary(
child: Material(
type: MaterialType.transparency,
child: Column(
@ -123,7 +124,8 @@ class PlayerOverlay extends HookConsumerWidget {
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(),
child:
CircularProgressIndicator(),
)
: Icon(
playing
@ -131,7 +133,8 @@ class PlayerOverlay extends HookConsumerWidget {
: SpotubeIcons.play,
color: textColor,
),
onPressed: Actions.handler<PlayPauseIntent>(
onPressed:
Actions.handler<PlayPauseIntent>(
context,
PlayPauseIntent(ref),
),
@ -157,6 +160,7 @@ class PlayerOverlay extends HookConsumerWidget {
),
),
),
),
);
}
}