|
8 | 8 | [](https://pub.dev/packages/wave) |
9 | 9 |  |
10 | 10 |
|
11 | | -A Flutter package for displaying waves. |
| 11 | +A Flutter package for displaying animated wave backgrounds. |
12 | 12 |
|
13 | 13 | ## Demo |
14 | 14 |
|
15 | 15 | | Platform | URL | |
16 | 16 | | -: | -: | |
17 | 17 | | Web | [wave.glorylab.xyz](https://wave.glorylab.xyz "The demo page of the wave package.") | |
18 | 18 |
|
| 19 | +The web demo is an interactive generator. Adjust the config mode, palette, |
| 20 | +layer count, height, amplitude, speed, and loop behavior, then copy the |
| 21 | +generated `WaveWidget` code into your app. |
| 22 | + |
19 | 23 | ## Deployment |
20 | 24 |
|
21 | 25 | The web demo is built from `example/` and deployed with Cloudflare Workers Static Assets. See [docs/cloudflare-workers.md](docs/cloudflare-workers.md) for the GitHub Actions and migration setup. |
22 | 26 |
|
| 27 | +## Install |
| 28 | + |
| 29 | +```yaml |
| 30 | +dependencies: |
| 31 | + wave: ^0.2.3 |
| 32 | +``` |
23 | 33 |
|
| 34 | +## Minimal Example |
24 | 35 |
|
25 | | -## Getting Started |
| 36 | +```dart |
| 37 | +import 'package:flutter/material.dart'; |
| 38 | +import 'package:wave/wave.dart'; |
26 | 39 |
|
27 | | -``` Dart |
| 40 | +class WaveBackground extends StatelessWidget { |
| 41 | + const WaveBackground({Key? key}) : super(key: key); |
| 42 | + |
| 43 | + @override |
| 44 | + Widget build(BuildContext context) { |
| 45 | + return WaveWidget( |
| 46 | + config: SingleConfig( |
| 47 | + color: Color(0xFF00BBF9), |
| 48 | + layers: 3, |
| 49 | + ), |
| 50 | + size: Size(double.infinity, double.infinity), |
| 51 | + ); |
| 52 | + } |
| 53 | +} |
| 54 | +``` |
28 | 55 |
|
29 | | -static const _backgroundColor = Color(0xFFF15BB5); |
| 56 | +Use `WaveWidget` anywhere a normal widget can be painted. Give it a bounded |
| 57 | +parent, such as `SizedBox.expand`, `Positioned.fill`, or a fixed-height |
| 58 | +container. |
30 | 59 |
|
31 | | -static const _colors = [ |
32 | | - Color(0xFFFEE440), |
33 | | - Color(0xFF00BBF9), |
34 | | -]; |
| 60 | +## Config Modes |
35 | 61 |
|
36 | | -static const _durations = [ |
37 | | - 5000, |
38 | | - 4000, |
39 | | -]; |
| 62 | +### Single color |
40 | 63 |
|
41 | | -static const _heightPercentages = [ |
42 | | - 0.65, |
43 | | - 0.66, |
44 | | -]; |
| 64 | +`SingleConfig` creates layered waves from one base color. |
45 | 65 |
|
| 66 | +```dart |
46 | 67 | WaveWidget( |
47 | | - config: CustomConfig( |
48 | | - colors: _colors, |
49 | | - durations: _durations, |
50 | | - heightPercentages: _heightPercentages, |
51 | | - ), |
52 | | - backgroundColor: _backgroundColor, |
53 | | - size: Size(double.infinity, double.infinity), |
54 | | - waveAmplitude: 0, |
55 | | -), |
| 68 | + config: SingleConfig( |
| 69 | + color: const Color(0xFF00BBF9), |
| 70 | + layers: 3, |
| 71 | + ), |
| 72 | + size: const Size(double.infinity, double.infinity), |
| 73 | +) |
56 | 74 | ``` |
57 | 75 |
|
58 | | -## Config modes |
| 76 | +### Seeded random colors |
59 | 77 |
|
60 | | -`CustomConfig` is the most explicit mode. Use it when you want full control over |
61 | | -each wave layer's colors or gradients, duration, and height. |
| 78 | +`RandomConfig` creates generated colors for each layer. Provide `seed` when |
| 79 | +deterministic output is useful for tests, demos, or copyable examples. Omit |
| 80 | +`seed` only when you really want a new generated palette for each config |
| 81 | +construction. |
62 | 82 |
|
63 | | -``` Dart |
| 83 | +```dart |
64 | 84 | WaveWidget( |
65 | | - config: CustomConfig( |
66 | | - gradients: [ |
67 | | - [Color(0xFF00BBF9), Color(0xFF9B5DE5)], |
68 | | - [Color(0xFFFEE440), Color(0xFFF15BB5)], |
69 | | - ], |
70 | | - durations: [5000, 4000], |
71 | | - heightPercentages: [0.65, 0.66], |
72 | | - ), |
73 | | - size: Size(double.infinity, double.infinity), |
| 85 | + config: RandomConfig( |
| 86 | + seed: 7, |
| 87 | + layers: 4, |
| 88 | + ), |
| 89 | + size: const Size(double.infinity, double.infinity), |
74 | 90 | ) |
75 | 91 | ``` |
76 | 92 |
|
77 | | -`SingleConfig` creates layered waves from one color. `RandomConfig` creates |
78 | | -layer colors for you, with an optional `seed` when deterministic output is |
79 | | -useful for tests or demos. |
| 93 | +### Custom colors or gradients |
| 94 | + |
| 95 | +`CustomConfig` is the most explicit mode. Use it when you want full control over |
| 96 | +each layer's color or gradient, duration, and height. |
80 | 97 |
|
81 | | -``` Dart |
| 98 | +```dart |
82 | 99 | WaveWidget( |
83 | | - config: SingleConfig( |
84 | | - color: Color(0xFF00BBF9), |
85 | | - layers: 3, |
86 | | - ), |
87 | | - size: Size(double.infinity, double.infinity), |
| 100 | + config: CustomConfig( |
| 101 | + gradients: const [ |
| 102 | + [Color(0xFF00BBF9), Color(0xFF9B5DE5)], |
| 103 | + [Color(0xFFFEE440), Color(0xFFF15BB5)], |
| 104 | + ], |
| 105 | + durations: const [5000, 4000], |
| 106 | + heightPercentages: const [0.65, 0.66], |
| 107 | + ), |
| 108 | + size: const Size(double.infinity, double.infinity), |
88 | 109 | ) |
| 110 | +``` |
89 | 111 |
|
90 | | -WaveWidget( |
91 | | - config: RandomConfig( |
92 | | - seed: 7, |
93 | | - layers: 4, |
94 | | - ), |
95 | | - size: Size(double.infinity, double.infinity), |
| 112 | +## Parameters |
| 113 | + |
| 114 | +### WaveWidget |
| 115 | + |
| 116 | +| Parameter | Type | Default | Description | |
| 117 | +| --- | --- | --- | --- | |
| 118 | +| `config` | `Config` | required | Layer colors, durations, heights, and blur. | |
| 119 | +| `size` | `Size` | required | Paint size for the wave stack. | |
| 120 | +| `waveAmplitude` | `double` | `20.0` | Base vertical movement of the wave path. | |
| 121 | +| `wavePhase` | `double` | `10.0` | Initial phase offset for the animation. | |
| 122 | +| `waveFrequency` | `double` | `1.6` | Horizontal frequency of the wave path. | |
| 123 | +| `duration` | `int?` | `6000` | Total runtime in milliseconds when `isLoop` is false. | |
| 124 | +| `backgroundColor` | `Color?` | `null` | Background color behind the waves. | |
| 125 | +| `backgroundImage` | `DecorationImage?` | `null` | Background image behind the waves. | |
| 126 | +| `isLoop` | `bool` | `true` | Whether animations repeat indefinitely. | |
| 127 | + |
| 128 | +### Config classes |
| 129 | + |
| 130 | +| Class | Best for | Key parameters | |
| 131 | +| --- | --- | --- | |
| 132 | +| `SingleConfig` | One-color layered waves | `color`, `layers`, `opacityPercentages`, `durations`, `heightPercentages` | |
| 133 | +| `RandomConfig` | Fast generated palettes | `layers`, `seed`, `colors`, `durations`, `heightPercentages` | |
| 134 | +| `CustomConfig` | Exact colors or gradients | `colors` or `gradients`, `durations`, `heightPercentages`, `gradientBegin`, `gradientEnd` | |
| 135 | + |
| 136 | +## Common Errors |
| 137 | + |
| 138 | +`CustomConfig` requires exactly one of `colors` or `gradients`. |
| 139 | + |
| 140 | +```dart |
| 141 | +CustomConfig( |
| 142 | + colors: const [Color(0xFF00BBF9)], |
| 143 | + gradients: const [ |
| 144 | + [Color(0xFF00BBF9), Color(0xFF9B5DE5)], |
| 145 | + ], |
| 146 | + durations: const [5000], |
| 147 | + heightPercentages: const [0.65], |
96 | 148 | ) |
97 | 149 | ``` |
| 150 | + |
| 151 | +All per-layer lists must have the same length. |
| 152 | + |
| 153 | +```dart |
| 154 | +CustomConfig( |
| 155 | + colors: const [Color(0xFF00BBF9), Color(0xFF9B5DE5)], |
| 156 | + durations: const [5000], |
| 157 | + heightPercentages: const [0.65, 0.66], |
| 158 | +) |
| 159 | +``` |
| 160 | + |
| 161 | +`heightPercentages` and `opacityPercentages` values must be between `0` and |
| 162 | +`1`, and every `duration` must be positive. |
0 commit comments