mirror of
https://github.com/stonega/tsacdop
synced 2025-02-17 20:10:37 +01:00
Add progress indicator on avatar.
This commit is contained in:
parent
f219ac9d3f
commit
1d334b58b2
@ -196,11 +196,45 @@ class _PlaylistHomeState extends State<PlaylistHome> {
|
||||
data.item4 != null
|
||||
? ClipRRect(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: SizedBox(
|
||||
width: 80,
|
||||
height: 80,
|
||||
child:
|
||||
Image(image: data.item4.avatarImage)),
|
||||
child: Stack(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 80,
|
||||
height: 80,
|
||||
child: Image(
|
||||
image: data.item4.avatarImage)),
|
||||
Selector<AudioPlayerNotifier, int>(
|
||||
selector: (_, audio) {
|
||||
if (!audio.playerRunning &&
|
||||
audio.episode.duration != 0) {
|
||||
return (audio.lastPosition ~/
|
||||
(audio.episode.duration * 10));
|
||||
} else if (audio.playerRunning &&
|
||||
audio.backgroundAudioDuration !=
|
||||
0) {
|
||||
return ((audio
|
||||
.backgroundAudioPosition *
|
||||
100) ~/
|
||||
audio.backgroundAudioDuration);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
builder: (_, progress, __) {
|
||||
return SizedBox(
|
||||
height: 80,
|
||||
width: 80,
|
||||
child: CustomPaint(
|
||||
painter: CircleProgressIndicator(
|
||||
progress,
|
||||
color: Colors.black38,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Container(
|
||||
decoration: BoxDecoration(
|
||||
|
@ -1450,3 +1450,31 @@ class _UpDownIndicatorState extends State<UpDownIndicator>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CircleProgressIndicator extends CustomPainter {
|
||||
final int progress;
|
||||
Paint _paint;
|
||||
CircleProgressIndicator(this.progress, {Color color}) {
|
||||
_paint = Paint()
|
||||
..color = color
|
||||
..strokeWidth = 2.0
|
||||
..style = PaintingStyle.fill
|
||||
..strokeCap = StrokeCap.round;
|
||||
}
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
var center = Offset(size.width / 2, size.height / 2);
|
||||
canvas.drawArc(
|
||||
Rect.fromCenter(center: center, height: size.height*2, width: size.width*2),
|
||||
-math.pi / 2,
|
||||
math.pi * 2 * (progress / 100),
|
||||
true,
|
||||
_paint);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(CircleProgressIndicator oldDelegate) {
|
||||
return oldDelegate.progress != progress;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user