-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Davide Bianco <[email protected]>
- Loading branch information
1 parent
89ed1ff
commit c29c80d
Showing
11 changed files
with
268 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'theme.dart'; | ||
|
||
// Code by @HrX03 | ||
class AudioTypeIsPlayingIndicator extends StatefulWidget { | ||
final Color? color; | ||
final double thickness; | ||
|
||
const AudioTypeIsPlayingIndicator({ | ||
this.color, | ||
this.thickness = 2.0, | ||
super.key, | ||
}); | ||
|
||
@override | ||
State<AudioTypeIsPlayingIndicator> createState() => | ||
_AudioTypeIsPlayingIndicatorState(); | ||
} | ||
|
||
class _AudioTypeIsPlayingIndicatorState | ||
extends State<AudioTypeIsPlayingIndicator> with TickerProviderStateMixin { | ||
static const _delayInMills = [770, 290, 280, 740]; | ||
static const _durationInMills = [1260, 430, 1010, 730]; | ||
static final TweenSequence<double> _seq = TweenSequence([ | ||
TweenSequenceItem(tween: Tween(begin: 1.0, end: 0.5), weight: 1), | ||
TweenSequenceItem(tween: Tween(begin: 0.5, end: 1.0), weight: 1), | ||
]); | ||
|
||
final List<AnimationController> _controllers = []; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
for (int i = 0; i < 4; i++) { | ||
_controllers.add( | ||
AnimationController( | ||
value: _delayInMills[i] / _durationInMills[i], | ||
vsync: this, | ||
duration: Duration(milliseconds: _durationInMills[i]), | ||
), | ||
); | ||
_controllers[i].repeat(); | ||
} | ||
} | ||
|
||
@override | ||
void dispose() { | ||
for (final AnimationController e in _controllers) { | ||
e.dispose(); | ||
} | ||
|
||
super.dispose(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return RepaintBoundary( | ||
child: Padding( | ||
padding: const EdgeInsets.only(left: 3, right: 1), | ||
child: SizedBox( | ||
width: iconSize - 2, | ||
height: iconSize, | ||
child: AnimatedBuilder( | ||
animation: Listenable.merge(_controllers), | ||
builder: (context, _) { | ||
return CustomPaint( | ||
painter: _MusicIndicatorPainter( | ||
animations: _controllers | ||
.map(_seq.animate) | ||
.map((e) => e.value) | ||
.toList(), | ||
color: widget.color ?? Theme.of(context).colorScheme.primary, | ||
thickness: widget.thickness, | ||
), | ||
); | ||
}, | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
class _MusicIndicatorPainter extends CustomPainter { | ||
final List<double> animations; | ||
final Color? color; | ||
final double thickness; | ||
|
||
const _MusicIndicatorPainter({ | ||
required this.animations, | ||
this.color, | ||
this.thickness = 2.0, | ||
}); | ||
|
||
@override | ||
void paint(Canvas canvas, Size size) { | ||
for (int i = 0; i < animations.length; i++) { | ||
final double dx = (size.width - thickness * animations.length) / | ||
(animations.length - 1) * | ||
i + | ||
thickness / 2; | ||
|
||
canvas.drawLine( | ||
Offset(dx, 0.5 * animations[i] * size.height), | ||
Offset(dx, size.height - 0.5 * animations[i] * size.height), | ||
Paint() | ||
..color = color ?? Colors.black | ||
..style = PaintingStyle.stroke | ||
..strokeWidth = thickness | ||
..strokeCap = StrokeCap.round, | ||
); | ||
} | ||
} | ||
|
||
@override | ||
bool shouldRepaint(covariant _MusicIndicatorPainter old) { | ||
return !listEquals(animations, old.animations) || | ||
color != old.color || | ||
thickness != old.thickness; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.