@@ -21,6 +21,8 @@ enum SkeletonAnimation {
2121 wave
2222}
2323
24+ enum SkeletonStyle { box, circle, text }
25+
2426/// Creates a simple skeleton animation
2527///
2628/// The default colors works great in light mode but you need to changes them for dark mode.
@@ -38,15 +40,18 @@ class Skeleton extends StatefulWidget {
3840 final double width;
3941
4042 /// The height of the skeleton
43+ ///
44+ /// Height is ignored if the [style] is SkeletonStyle.circle
4145 final double height;
4246
43- /// The radius of the skeleton
44- final Radius radius;
45-
4647 /// Choose your style of animaion.
4748 /// The default is SkeletonAnimation.pulse
4849 final SkeletonAnimation animation;
4950
51+ /// Choose your look of the skeleton
52+ /// The default is SkeletonStyle.box
53+ final SkeletonStyle style;
54+
5055 Skeleton (
5156 {
5257 // Use default colors
@@ -55,10 +60,10 @@ class Skeleton extends StatefulWidget {
5560 // Use default size
5661 this .width = 200.0 ,
5762 this .height = 60.0 ,
58- // Use default radius
59- this .radius = const Radius .circular (0 ),
6063 // Use the default animation
61- this .animation = SkeletonAnimation .pulse});
64+ this .animation = SkeletonAnimation .pulse,
65+ // Use the default style
66+ this .style = SkeletonStyle .box});
6267
6368 @override
6469 _SkeletonState createState () => _SkeletonState ();
@@ -133,9 +138,19 @@ class _SkeletonState extends State<Skeleton>
133138 animation: _controller,
134139 builder: (context, child) => Container (
135140 width: widget.width,
136- height: widget.height,
141+ height: (widget.style == SkeletonStyle .circle)
142+ ? widget.width
143+ : widget.height,
137144 decoration: BoxDecoration (
138- borderRadius: BorderRadius .all (widget.radius),
145+ // Choose the correct border radius
146+ // box: none
147+ // text: 4
148+ // circle: widget.width / 2
149+ borderRadius: (widget.style == SkeletonStyle .box)
150+ ? BorderRadius .zero
151+ : (widget.style == SkeletonStyle .text)
152+ ? BorderRadius .all (Radius .circular (4 ))
153+ : BorderRadius .all (Radius .circular (widget.width / 2 )),
139154 // Import the correct animation
140155 color: (widget.animation == SkeletonAnimation .pulse)
141156 ? _baseColor.withOpacity (_controller.value) // Pulse
0 commit comments