Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feature to hide the shimmer effect #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
22 changes: 15 additions & 7 deletions lib/shimmer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ enum ShimmerDirection { ltr, rtl, ttb, btt }
/// forever.
///
/// [enabled] controls if shimmer effect is active. When set to false the animation
/// is paused
/// is paused.
///
/// [hideOnDisabled] hides the shimmer effect when [enabled] is `false`.
///
///
/// ## Pro tips:
Expand All @@ -63,6 +65,7 @@ class Shimmer extends StatefulWidget {
final Gradient gradient;
final int loop;
final bool enabled;
final bool hideOnDisabled;

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

///
Expand All @@ -88,6 +92,7 @@ class Shimmer extends StatefulWidget {
this.direction = ShimmerDirection.ltr,
this.loop = 0,
this.enabled = true,
this.hideOnDisabled = false,
}) : gradient = LinearGradient(
begin: Alignment.topLeft,
end: Alignment.centerRight,
Expand Down Expand Up @@ -163,12 +168,15 @@ class _ShimmerState extends State<Shimmer> with SingleTickerProviderStateMixin {
return AnimatedBuilder(
animation: _controller,
child: widget.child,
builder: (BuildContext context, Widget child) => _Shimmer(
child: child,
direction: widget.direction,
gradient: widget.gradient,
percent: _controller.value,
),
builder: (BuildContext context, Widget child) =>
widget.hideOnDisabled && !widget.enabled
? child
: _Shimmer(
child: child,
direction: widget.direction,
gradient: widget.gradient,
percent: _controller.value,
),
);
}

Expand Down