@@ -91,6 +91,36 @@ Widget build(BuildContext context) {
91
91
However, this will not animate the effect. This will only wrap the widget with the specific effect and use the value
92
92
provided.
93
93
94
+ ### List of Effects
95
+
96
+ | Effect Name | Description |
97
+ | -------------| -------------------------------------------------------|
98
+ | Opacity | Changes the opacity of a widget. |
99
+ | Blur | Applies a blur effect to a widget. |
100
+ | Scale | Scales a widget. |
101
+ | TranslateX | Translates a widget along the X-axis. |
102
+ | TranslateY | Translates a widget along the Y-axis. |
103
+ | TranslateXY | Translates a widget along both the X and Y axes. |
104
+ | Rotate | Rotates a widget. |
105
+ | RotateX | Rotates a widget around the X-axis. |
106
+ | RotateY | Rotates a widget around the Y-axis. |
107
+ | RotateZ | Rotates a widget around the Z-axis. |
108
+ | SkewX | Skews a widget along the X-axis. |
109
+ | SkewY | Skews a widget along the Y-axis. |
110
+ | SkewXY | Skews a widget along both the X and Y axes. |
111
+ | ColorFilter | Applies a color filter to a widget. |
112
+ | Transform | Applies a transformation before painting the widget. |
113
+ | ClipRect | Clips its child using a rectangle. |
114
+ | ClipRRect | Clips its child using a rounded rectangle. |
115
+ | RollingText | Creates a rolling animation from one text to another. |
116
+ | Shake | Applies a shake effect to a widget. |
117
+ | Align | Changes the alignment of a widget. |
118
+
119
+ For details about each effect, please visit the source code of the effect.
120
+ Link: [ hyper_effects/lib/src/effects] ( https://github.com/hyper-designed/hyper_effects/tree/main/lib/src/effects )
121
+
122
+ ### Animations
123
+
94
124
To animate the effects, you need to call the ` animate ` method on the widget like so:
95
125
96
126
``` dart
@@ -100,13 +130,14 @@ Widget build(BuildContext context) {
100
130
color: Colors.blue,
101
131
)
102
132
.opacity(myCondition ? 0 : 1)
103
- .animate(toggle : myCondition);
133
+ .animate(trigger : myCondition);
104
134
}
105
135
```
106
136
107
- ` toggle ` is a parameter of type ` Object ` . It's inspired from SwiftUI's ` value ` parameter on its ` animation ` modifier.
108
- Whenever the value of ` toggle ` changes, the effect will animate to the new value. In this case, ` myCondition ` is the
109
- toggle value. You can use any object as a toggle value, but you will likely want to use the same object that you use to
137
+ ` trigger ` is a parameter of type ` Object ` . It's inspired from SwiftUI's ` value ` parameter on its ` animation ` modifier.
138
+ Whenever the value of ` trigger ` changes, the effect will animate to the new value. In this case, ` myCondition ` is the
139
+ trigger value. You can use any object as a trigger value, but you will likely want to use the same object that you use
140
+ to
110
141
control the condition of the effect as it is the point in which the effect should animate.
111
142
112
143
HyperEffects takes heavy inspiration from SwiftUI in that it attempts to provide Apple-like default values for
@@ -124,7 +155,7 @@ Widget build(BuildContext context) {
124
155
)
125
156
.opacity(myCondition ? 0 : 1)
126
157
.animate(
127
- toggle : myCondition,
158
+ trigger : myCondition,
128
159
duration: const Duration(milliseconds: 200),
129
160
curve: Curves.easeOutQuart,
130
161
);
@@ -143,7 +174,7 @@ Widget build(BuildContext context) {
143
174
.blur(myCondition ? 10 : 0)
144
175
.scale(myCondition ? 0.5 : 1)
145
176
.translateX(myCondition ? 100 : 0)
146
- .animate(toggle : myCondition);
177
+ .animate(trigger : myCondition);
147
178
}
148
179
```
149
180
@@ -178,6 +209,224 @@ Widget build(BuildContext context) {
178
209
}
179
210
```
180
211
212
+ #### Properties
213
+
214
+ * trigger: The value used to trigger the animation. As long as the value of trigger is the same, the animation will not
215
+ be triggered again.
216
+ * duration: The duration of the animation.
217
+ * curve: The curve of the animation.
218
+ * onEnd: A callback that is called when the animation ends.
219
+ * repeat: Determines how many times the animation should be repeated.
220
+ * reverse: A boolean property that determines whether the animation should be reversed after each repetition.
221
+ * delay: A delay before the animation starts.
222
+ * playIf: A callback that returns whether the animation should be played or skipped. If the callback returns false, the
223
+ animation will be skipped, even when it is explicitly triggered.
224
+
225
+ ### One Shot Animations
226
+
227
+ If you want to trigger an animation immediately, you can use the ` oneShot ` function which triggers a chain of effects
228
+ immediately without a trigger parameter.
229
+ This function is useful when you want to start an animation as soon as the widget is built, without waiting for a
230
+ specific trigger to change.
231
+
232
+ Here's an example of how to use the ` oneShot ` function:
233
+
234
+ ``` dart
235
+ @override
236
+ Widget build(BuildContext context) {
237
+ return Container(
238
+ color: Colors.blue,
239
+ ).slideInFromBottom()
240
+ .oneShot(
241
+ // All the normal parameters inside of .animate() but without the trigger parameter.
242
+ );
243
+ }
244
+ ```
245
+
246
+ ### Animate After Animations
247
+
248
+ The ` animateAfter ` function triggers the animation after the last animation in the chain ends.
249
+ It's useful when you want to create a sequence of animations where one animation starts after the previous one ends.
250
+
251
+ Here's an example of how to use the ` animateAfter ` function:
252
+
253
+ ``` dart
254
+ @override
255
+ Widget build(BuildContext context) {
256
+ return Center(
257
+ child: GestureDetector(
258
+ onTap: () {
259
+ setState(() {
260
+ trigger = !trigger;
261
+ });
262
+ },
263
+ child: Image.asset('assets/pin_ball_256x.png', width: 150, height: 150)
264
+ .shake()
265
+ .oneShot(
266
+ delay: const Duration(seconds: 1),
267
+ repeat: -1,
268
+ playIf: () => !trigger,
269
+ )
270
+ .translateY(300, from: 0)
271
+ .animate(
272
+ trigger: trigger,
273
+ curve: Curves.easeOutQuart,
274
+ duration: const Duration(milliseconds: 2000),
275
+ playIf: () => trigger,
276
+ )
277
+ .slideOut(const Offset(0, -300))
278
+ .animateAfter(
279
+ curve: Curves.elasticOut,
280
+ duration: const Duration(milliseconds: 450),
281
+ onEnd: () => setState(() => trigger = false),
282
+ )
283
+ .resetAll(),
284
+ ),
285
+ );
286
+ }
287
+ ```
288
+
289
+ See this example in action in the demo app: [ hyper-effects-demo.web.app] ( https://hyper-effects-demo.web.app/ )
290
+
291
+ ### Reset Animations
292
+
293
+ Using ` resetAll ` at the end of the chain of animations will reset all the effects in the chain to their original values.
294
+
295
+ When the animation is triggered again, all the effects will animate from their original values to the new values.
296
+
297
+ ### Delayed Animations
298
+
299
+ The ` delay ` parameter is used in the ` animate ` , ` animateAfter ` and ` oneShot ` methods. This parameter allows you to
300
+ specify a delay
301
+ before the animation starts.
302
+ The ` delay ` is specified as a ` Duration ` . Here's an example of how to use the ` delay ` parameter:
303
+
304
+ ``` dart
305
+ @override
306
+ Widget build(BuildContext context) {
307
+ return Container(
308
+ color: Colors.blue,
309
+ )
310
+ .opacity(myCondition ? 0 : 1)
311
+ .animate(
312
+ trigger: myCondition,
313
+ delay: const Duration(seconds: 1), // 1 second delay before the animation starts after the trigger changes.
314
+ );
315
+ }
316
+ ```
317
+
318
+ In this example, the opacity animation will start 1 second after the ` myCondition ` trigger changes.
319
+
320
+ ### Repeat Animations
321
+
322
+ The ` repeat ` parameter is used in the ` animate ` , ` animateAfter ` , and ` oneShot ` functions.
323
+ This parameter allows you to specify how many times the animation will be repeated.
324
+ The repeat parameter is an ` integer ` , where 0 (default) means the animation will only play once and not repeat.
325
+ Any positive integer specifies the number of times the animation will repeat.
326
+ If the ` repeat ` parameter is set to -1, the animation will repeat indefinitely.
327
+
328
+ Here's an example of how to use the ` repeat ` parameter:
329
+
330
+ ``` dart
331
+ @override
332
+ Widget build(BuildContext context) {
333
+ return Container(
334
+ color: Colors.blue,
335
+ )
336
+ .opacity(myCondition ? 0 : 1)
337
+ .animate(
338
+ trigger: myCondition,
339
+ repeat: 3, // The animation will repeat 3 times
340
+ );
341
+ }
342
+ ```
343
+
344
+ Note that if the ` reverse ` parameter is set to true, the repetition counter will count for each animation direction.
345
+ For example, if the ` repeat ` parameter is set to 3 and the ` reverse ` parameter is set to true, the animation will
346
+ play only 3 times, one of which is the reverse animation.
347
+
348
+ ` forwards -> backwards -> forwards -> done. `
349
+
350
+ ### Rolling Text
351
+
352
+ The Rolling Text feature in Hyper Effects allows you to create a rolling animation from one text to another. Each
353
+ character rolls individually to form the new text. This feature provides a visually appealing way to transition between
354
+ different text states in your application.
355
+
356
+ #### Usage
357
+
358
+ To use the Rolling Text feature, you can use the roll extension on any Text widget. Here's an example:
359
+
360
+ ``` dart
361
+ @override
362
+ Widget build(BuildContext context) {
363
+ return Text('Hello').roll('World');
364
+ }
365
+ ```
366
+
367
+ In this example, the text will roll from 'Hello' to 'World'. Each character in 'Hello' will roll until it changes to the
368
+ corresponding character in 'World'.
369
+
370
+ #### Customization
371
+
372
+ The Rolling Text feature provides several options for customization:
373
+
374
+ - padding: This option allows you to set the internal padding between the row of symbol tapes and the clipping mask.
375
+ - tapeStrategy: This option determines the string of characters to create and roll through for each character index
376
+ between the old and new text.
377
+ - tapeCurve: This option determines the curve each roll of symbol tape uses to slide up and down through its characters.
378
+ - tapeSlideDirection: This option determines the direction each roll of symbol tape slides through its characters.
379
+ - staggerTapes: This option determines whether the tapes should be staggered or not.
380
+ - staggerSoftness: This option determines how harsh the stagger effect is.
381
+ - reverseStaggerDirection: This option determines whether the stagger effect should be reversed or not.
382
+
383
+ Here's an example of how to use these options:
384
+
385
+ ``` dart
386
+ @override
387
+ Widget build(BuildContext context) {
388
+ return Text('Hello').roll(
389
+ 'World',
390
+ padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
391
+ tapeStrategy: TapeStrategy.random,
392
+ tapeCurve: Curves.easeInOutQuart,
393
+ tapeSlideDirection: TapeSlideDirection.down,
394
+ staggerTapes: true,
395
+ staggerSoftness: 0.5,
396
+ reverseStaggerDirection: true,
397
+ );
398
+ }
399
+ ```
400
+
401
+ To trigger the rolling text effect, you need to call the ` animate ` or ` oneShot ` functions as normal:
402
+
403
+ ``` dart
404
+ @override
405
+ Widget build(BuildContext context) {
406
+ return Text('Hello').roll('World').animate(trigger: myTrigger);
407
+ }
408
+ ```
409
+
410
+ When myTrigger changes, the text will roll from 'Hello' to 'World' or vice versa.
411
+ The animate method also accepts duration and curve parameters that allow you to customize the animation's duration
412
+ and easing curve.
413
+
414
+ Please note that if you specify a curve that goes outside the bounds of 0 and 1 like Curves.elasticIn/Out or
415
+ Curves.easeIn/OutBack, the UI will crash with a warning that the width cannot be negative. To resolve this,
416
+ simply specify a custom curve for the width. You can do so like this:
417
+
418
+ ``` dart
419
+ @override
420
+ Widget build(BuildContext context) {
421
+ return Text('Hello').roll('World').animate(
422
+ trigger: myTrigger,
423
+ curve: Curves.easeInOutQuart,
424
+ duration: const Duration(milliseconds: 500),
425
+ widthCurve: Curves.easeInOutQuart,
426
+ );
427
+ }
428
+ ```
429
+
181
430
### Transitions
182
431
183
432
Transitions are a special type of effect that allows you to control how your widgets look based on some continuous
0 commit comments