β‘ Lightning Overlay
A Flutter package that adds a dynamic lightning overlay effect to any widget.
Itβs designed to create an elegant, animated highlight β similar to Skeletonizer, but without background blocks or shimmer effects.
Perfect for emphasizing UI elements, visual feedback, or attention-grabbing moments in your app.
π― Goal
The goal of this package is to provide a Skeletonizer-like animation, but:
- β without a static background or placeholder layer
- β without shimmer gradients
- β with a clean, lightning-style overlay animation that can be applied to any widget seamlessly
β¨ Features
- β‘ Beautiful lightning overlay animation
- πΉοΈ Three animation control modes
- π Optional infinite repeat mode
- π¨ Customizable overlay color, curves, and durations
- βοΈ Animation direction control (left β right or right β left)
- π¦ Supports rounded corners and any widget type
π Control Modes
The Lightning effect can be controlled in three different ways:
1. Auto-Start Mode
The animation automatically starts after a specified delay (delayDuration).
Lightning(
child: MyWidget(),
delayDuration: Duration(milliseconds: 800),
autoStart: true,
)
Tip:
Set both delayDuration and pauseDuration for smooth automatic playback.
If the reverse animation doesnβt start, try increasing the pauseDuration.
2. Controller Mode
Manually trigger the animation using a LightningController.
final controller = LightningController();
Lightning(
controller: controller,
child: MyWidget(),
);
// Later in your code:
controller.animateIn();
await Future.delayed(Duration(milliseconds: 500));
controller.animateOut();
| Function | Description |
|---|---|
animateIn() |
Starts the lightning overlay (cover) animation |
animateOut() |
Starts the uncovering (fade-out) animation |
β οΈ You must wait until animateIn() is finished before calling animateOut().
3. Gesture Mode
Let users trigger the animation by tapping the widget.
Lightning(
useGesture: true,
child: MyWidget(),
)
- Tap down β starts the lightning effect
- Tap up β reverses the effect
- Tap cancel β stops the effect
β οΈ Compatibility Notes
repeatInfinitycannot be used together withuseGesture = true,
since repeat animations run automatically without user input.- For automatic or repeat modes, make sure
autoStart = trueand a validdelayDurationis set. - When using rounded corners on your child widget, pass the same
borderRadiusto Lightning to ensure smooth edges.
π§ API Overview
| Property | Description | Required | Default |
|---|---|---|---|
child |
The widget to overlay | β | β |
delayDuration |
Delay before the first animation starts | β | 500 ms |
useGesture |
Enable user touch control | β | false |
borderRadius |
Rounded corners of the overlay | β | 0 |
controller |
Custom controller for manual control | β | null |
overlayColor |
Color of the lightning overlay | β | white (10% opacity) |
pauseDuration |
Delay before reverse animation | β | 200 ms |
durationIn |
Duration for appearing animation | β | 300 ms |
durationOut |
Duration for disappearing animation | β | 600 ms |
curveIn |
Curve for appearing animation | β | Curves.easeIn |
curveOut |
Curve for disappearing animation | β | Curves.linear |
direction |
Animation direction | β | LightningDirection.leftToRight |
repeatInfinity |
Repeats animation infinitely | β | false |
pauseRepeatInfinityDelay |
Pause between repeats | β | 2 seconds |
autoStart |
Start animation automatically | β | true |
π§ Example
Lightning(
child: Container(
width: 200,
height: 100,
color: Colors.blue,
alignment: Alignment.center,
child: Text('Tap me!', style: TextStyle(color: Colors.white)),
),
overlayColor: Colors.white.withOpacity(0.3),
useGesture: true,
borderRadius: 12,
)
πΈ Demo
https://github.com/Gastrolize/lightning_overlay/assets/72274345/14377764-7d17-4f6d-a30e-bc1c0a42013a
π§© Summary
| Mode | Trigger | Works With Repeat | Use Case |
|---|---|---|---|
| Auto | Automatically after delay | β Yes | Simple visual loops |
| Controller | Programmatically | β Yes | Controlled sequences |
| Gesture | User tap | β No | Interactive feedback |
πͺ Tips
- To make the lightning feel more natural, experiment with:
- Shorter
durationIn(fast entry) - Longer
durationOut(smooth fade) - Low-opacity overlay colors
- Shorter
- Combine repeat mode with different curves for unique effects.
π License
MIT License Β© Gastrolize
Libraries
- lightning_overlay
- A Flutter package that provides a lightning overlay effect for widgets.