欢迎去浏览原文:http://tryenough.com/flutter-wave
效果
你可以先简单理解下贝塞尔曲线的原理:
推荐这个关于贝塞尔的教程:http://www.html-js.com/article/1628
代码:
1.创建绘制波浪边界的代码
创建一个基础的绘制类,可接收动画的x和y值:
import 'package:flutter/material.dart';
abstract class BasePainter extends CustomPainter{
Animation<double> _xAnimation;
Animation<double> _yAnimation;
set XAnimation(Animation<double> value) {
_xAnimation = value;
}
set YAnimation(Animation<double> value) {
_yAnimation = value;
}
Animation<double> get YAnimation => _yAnimation;
Animation<double> get XAnimation => _xAnimation;
}
实现
欢迎去浏览原文:http://tryenough.com/flutter-wave
import 'dart:math';
import 'package:flutter_wave/painter_base.dart';
import 'package:flutter/material.dart';
class WavePainter extends BasePainter {
int waveCount;
int crestCount;
double waveHeight;
List<Color> waveColors;
double circleWidth;
Color circleColor;
Color circleBackgroundColor;
bool showProgressText;
TextStyle textStyle;
WavePainter(
{this.waveCount = 1,
this.crestCount = 2,
this.waveHeight,
this.waveColors,
this.circleColor = Colors.grey,
this.circleBackgroundColor = Colors.white,
this.circleWidth = 5.0,
this.showProgressText = true,
this.textStyle = const TextStyle(
fontSize: 60.0,
color: Colors.blue,
fontWeight: FontWeight.b