Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions lib/shimmer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ enum ShimmerDirection { ltr, rtl, ttb, btt }
/// [enabled] controls if shimmer effect is active. When set to false the animation
/// is paused
///
/// [slanted] controls if shimmer effect is slanted or straight. When set to false,
/// the effect plays horizontally if direction is ShimmerDirection.ltr or ShimmerDirection.rtl,
/// or else, the effect plays vertically if direction is ShimmerDirection.ttb or ShimmerDirection.btt
///
/// ## Pro tips:
///
Expand All @@ -63,6 +66,7 @@ class Shimmer extends StatefulWidget {
final Gradient gradient;
final int loop;
final bool enabled;
final bool slanted;

const Shimmer({
Key? key,
Expand All @@ -72,6 +76,7 @@ class Shimmer extends StatefulWidget {
this.period = const Duration(milliseconds: 1500),
this.loop = 0,
this.enabled = true,
this.slanted = true,
}) : super(key: key);

///
Expand All @@ -88,9 +93,20 @@ class Shimmer extends StatefulWidget {
this.direction = ShimmerDirection.ltr,
this.loop = 0,
this.enabled = true,
this.slanted = true,
}) : gradient = LinearGradient(
begin: Alignment.topLeft,
end: Alignment.centerRight,
begin: slanted
? Alignment.topLeft
: direction == ShimmerDirection.ltr ||
direction == ShimmerDirection.rtl
? Alignment.centerLeft
: Alignment.topCenter,
end: slanted
? Alignment.centerRight
: direction == ShimmerDirection.ltr ||
direction == ShimmerDirection.rtl
? Alignment.centerRight
: Alignment.bottomCenter,
colors: <Color>[
baseColor,
baseColor,
Expand Down Expand Up @@ -143,9 +159,9 @@ class _ShimmerState extends State<Shimmer> with SingleTickerProviderStateMixin {
_controller.forward(from: 0.0);
}
});
if (widget.enabled) {
_controller.forward();
}
if (widget.enabled) {
_controller.forward();
}
}

@override
Expand Down