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

View File

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