Skip to content

Commit ef7140c

Browse files
authored
Merge pull request #4 from wjtje/skeleton-styles
Added default styling options
2 parents 706814b + 8dd5c7a commit ef7140c

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## [0.0.3] - Fixed issues
22

33
* Fixed dark mode
4+
* Added default styling options
45

56
## [0.0.2] - New Animatios
67

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ import 'package:skeleton_animation/skeleton_animation.dart';
1717

1818
```dart
1919
Skeleton(
20-
width: 200,
2120
height: 12,
22-
radius: Radius.circular(6),
23-
animation: SkeletonAnimation.pulse
21+
style: SkeletonStyle.text
2422
),
2523
```

example/lib/main.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ class MyApp extends StatelessWidget {
2121
delegate: SliverChildBuilderDelegate(
2222
(context, i) => ListTile(
2323
title: Skeleton(
24-
width: 200,
25-
height: 14,
26-
radius: Radius.circular(6),
24+
style: SkeletonStyle.text,
25+
height: 14.0,
2726
),
2827
subtitle: Skeleton(
29-
width: 200,
30-
height: 10,
31-
radius: Radius.circular(6),
28+
style: SkeletonStyle.text,
29+
height: 10.0,
3230
),
31+
onTap: () {},
3332
),
3433
childCount: 20),
3534
)

lib/skeleton_animation.dart

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)