@@ -214,14 +214,14 @@ class WaveWidget extends StatefulWidget {
214
214
final double wavePhase;
215
215
final double waveFrequency;
216
216
final double heightPercentange;
217
- final int duration;
218
- final Color backgroundColor;
219
- final DecorationImage backgroundImage;
217
+ final int ? duration;
218
+ final Color ? backgroundColor;
219
+ final DecorationImage ? backgroundImage;
220
220
final bool isLoop;
221
221
222
222
WaveWidget ({
223
- @ required this .config,
224
- @ required this .size,
223
+ required this .config,
224
+ required this .size,
225
225
this .waveAmplitude = 20.0 ,
226
226
this .wavePhase = 10.0 ,
227
227
this .waveFrequency = 1.6 ,
@@ -237,17 +237,17 @@ class WaveWidget extends StatefulWidget {
237
237
}
238
238
239
239
class _WaveWidgetState extends State <WaveWidget > with TickerProviderStateMixin {
240
- List <AnimationController > _waveControllers;
241
- List <Animation <double >> _wavePhaseValues;
240
+ late List <AnimationController > _waveControllers;
241
+ late List <Animation <double >> _wavePhaseValues;
242
242
243
243
List <double > _waveAmplitudes = [];
244
- Map <Animation <double >, AnimationController > valueList;
245
- Timer _endAnimationTimer;
244
+ Map <Animation <double >, AnimationController >? valueList;
245
+ Timer ? _endAnimationTimer;
246
246
247
247
_initAnimations () {
248
248
if (widget.config.colorMode == ColorMode .custom) {
249
249
_waveControllers =
250
- (widget.config as CustomConfig ).durations.map ((duration) {
250
+ (widget.config as CustomConfig ).durations! .map ((duration) {
251
251
_waveAmplitudes.add (widget.waveAmplitude + 10 );
252
252
return AnimationController (
253
253
vsync: this , duration: Duration (milliseconds: duration));
@@ -280,7 +280,8 @@ class _WaveWidgetState extends State<WaveWidget> with TickerProviderStateMixin {
280
280
281
281
// If isLoop is false, stop the animation after the specified duration.
282
282
if (! widget.isLoop) {
283
- _endAnimationTimer = Timer (Duration (milliseconds: widget.duration), () {
283
+ _endAnimationTimer =
284
+ Timer (Duration (milliseconds: widget.duration! ), () {
284
285
for (AnimationController waveController in _waveControllers) {
285
286
waveController.stop ();
286
287
}
@@ -292,10 +293,10 @@ class _WaveWidgetState extends State<WaveWidget> with TickerProviderStateMixin {
292
293
_buildPaints () {
293
294
List <Widget > paints = [];
294
295
if (widget.config.colorMode == ColorMode .custom) {
295
- List <Color > _colors = (widget.config as CustomConfig ).colors;
296
- List <List <Color >> _gradients = (widget.config as CustomConfig ).gradients;
297
- Alignment begin = (widget.config as CustomConfig ).gradientBegin;
298
- Alignment end = (widget.config as CustomConfig ).gradientEnd;
296
+ List <Color >? _colors = (widget.config as CustomConfig ).colors;
297
+ List <List <Color >>? _gradients = (widget.config as CustomConfig ).gradients;
298
+ Alignment ? begin = (widget.config as CustomConfig ).gradientBegin;
299
+ Alignment ? end = (widget.config as CustomConfig ).gradientEnd;
299
300
for (int i = 0 ; i < _wavePhaseValues.length; i++ ) {
300
301
paints.add (
301
302
Container (
@@ -306,7 +307,7 @@ class _WaveWidgetState extends State<WaveWidget> with TickerProviderStateMixin {
306
307
gradientBegin: begin,
307
308
gradientEnd: end,
308
309
heightPercentange:
309
- (widget.config as CustomConfig ).heightPercentages[i],
310
+ (widget.config as CustomConfig ).heightPercentages! [i],
310
311
repaint: _waveControllers[i],
311
312
waveFrequency: widget.waveFrequency,
312
313
wavePhaseValue: _wavePhaseValues[i],
@@ -357,12 +358,12 @@ class _WaveWidgetState extends State<WaveWidget> with TickerProviderStateMixin {
357
358
358
359
/// Meta data of layer
359
360
class Layer {
360
- final Color color;
361
- final List <Color > gradient;
362
- final MaskFilter blur;
363
- final Path path;
364
- final double amplitude;
365
- final double phase;
361
+ final Color ? color;
362
+ final List <Color >? gradient;
363
+ final MaskFilter ? blur;
364
+ final Path ? path;
365
+ final double ? amplitude;
366
+ final double ? phase;
366
367
367
368
Layer ({
368
369
this .color,
@@ -375,20 +376,20 @@ class Layer {
375
376
}
376
377
377
378
class _CustomWavePainter extends CustomPainter {
378
- final ColorMode colorMode;
379
- final Color color;
380
- final List <Color > gradient;
381
- final Alignment gradientBegin;
382
- final Alignment gradientEnd;
383
- final MaskFilter blur;
379
+ final ColorMode ? colorMode;
380
+ final Color ? color;
381
+ final List <Color >? gradient;
382
+ final Alignment ? gradientBegin;
383
+ final Alignment ? gradientEnd;
384
+ final MaskFilter ? blur;
384
385
385
- double waveAmplitude;
386
+ double ? waveAmplitude;
386
387
387
- Animation <double > wavePhaseValue;
388
+ Animation <double >? wavePhaseValue;
388
389
389
- double waveFrequency;
390
+ double ? waveFrequency;
390
391
391
- double heightPercentange;
392
+ double ? heightPercentange;
392
393
393
394
double _tempA = 0.0 ;
394
395
double _tempB = 0.0 ;
@@ -406,7 +407,7 @@ class _CustomWavePainter extends CustomPainter {
406
407
this .waveFrequency,
407
408
this .wavePhaseValue,
408
409
this .waveAmplitude,
409
- Listenable repaint})
410
+ Listenable ? repaint})
410
411
: super (repaint: repaint);
411
412
412
413
_setPaths (double viewCenterY, Size size, Canvas canvas) {
@@ -415,50 +416,50 @@ class _CustomWavePainter extends CustomPainter {
415
416
color: color,
416
417
gradient: gradient,
417
418
blur: blur,
418
- amplitude: (- 1.6 + 0.8 ) * waveAmplitude,
419
- phase: wavePhaseValue.value * 2 + 30 ,
419
+ amplitude: (- 1.6 + 0.8 ) * waveAmplitude! ,
420
+ phase: wavePhaseValue! .value * 2 + 30 ,
420
421
);
421
422
422
- _layer.path.reset ();
423
- _layer.path.moveTo (
423
+ _layer.path! .reset ();
424
+ _layer.path! .moveTo (
424
425
0.0 ,
425
426
viewCenterY +
426
- _layer.amplitude * _getSinY (_layer.phase, waveFrequency, - 1 ));
427
+ _layer.amplitude! * _getSinY (_layer.phase! , waveFrequency! , - 1 ));
427
428
for (int i = 1 ; i < size.width + 1 ; i++ ) {
428
- _layer.path.lineTo (
429
+ _layer.path! .lineTo (
429
430
i.toDouble (),
430
431
viewCenterY +
431
- _layer.amplitude * _getSinY (_layer.phase, waveFrequency, i));
432
+ _layer.amplitude! * _getSinY (_layer.phase! , waveFrequency! , i));
432
433
}
433
434
434
- _layer.path.lineTo (size.width, size.height);
435
- _layer.path.lineTo (0.0 , size.height);
436
- _layer.path.close ();
435
+ _layer.path! .lineTo (size.width, size.height);
436
+ _layer.path! .lineTo (0.0 , size.height);
437
+ _layer.path! .close ();
437
438
if (_layer.color != null ) {
438
- _paint.color = _layer.color;
439
+ _paint.color = _layer.color! ;
439
440
}
440
441
if (_layer.gradient != null ) {
441
442
var rect = Offset .zero &
442
- Size (size.width, size.height - viewCenterY * heightPercentange);
443
+ Size (size.width, size.height - viewCenterY * heightPercentange! );
443
444
_paint.shader = LinearGradient (
444
445
begin: gradientBegin == null
445
446
? Alignment .bottomCenter
446
- : gradientBegin,
447
- end: gradientEnd == null ? Alignment .topCenter : gradientEnd,
448
- colors: _layer.gradient)
447
+ : gradientBegin! ,
448
+ end: gradientEnd == null ? Alignment .topCenter : gradientEnd! ,
449
+ colors: _layer.gradient! )
449
450
.createShader (rect);
450
451
}
451
452
if (_layer.blur != null ) {
452
453
_paint.maskFilter = _layer.blur;
453
454
}
454
455
455
456
_paint.style = PaintingStyle .fill;
456
- canvas.drawPath (_layer.path, _paint);
457
+ canvas.drawPath (_layer.path! , _paint);
457
458
}
458
459
459
460
@override
460
461
void paint (Canvas canvas, Size size) {
461
- double viewCenterY = size.height * (heightPercentange + 0.1 );
462
+ double viewCenterY = size.height * (heightPercentange! + 0.1 );
462
463
viewWidth = size.width;
463
464
_setPaths (viewCenterY, size, canvas);
464
465
}
0 commit comments