WT 1.1.13 Test Central bug fixes

This commit is contained in:
bossanyit
2021-04-19 00:16:07 +02:00
parent 4cde174a83
commit cc1117d8a1
39 changed files with 1114 additions and 214 deletions
@@ -0,0 +1,119 @@
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'wave.dart';
const double _twoPi = math.pi * 2.0;
const double _epsilon = .001;
const double _sweep = _twoPi - _epsilon;
class LiquidCircularProgressIndicator extends ProgressIndicator {
///The width of the border, if this is set [borderColor] must also be set.
final double borderWidth;
///The color of the border, if this is set [borderWidth] must also be set.
final Color borderColor;
///The widget to show in the center of the progress indicator.
final Widget? center;
///The direction the liquid travels.
final Axis direction;
LiquidCircularProgressIndicator({
Key? key,
double value = 0.5,
Color? backgroundColor,
Animation<Color>? valueColor,
required this.borderWidth,
required this.borderColor,
this.center,
this.direction = Axis.vertical,
}) : super(
key: key,
value: value,
backgroundColor: backgroundColor,
valueColor: valueColor,
);
Color _getBackgroundColor(BuildContext context) => backgroundColor ?? Theme.of(context).backgroundColor;
Color _getValueColor(BuildContext context) => valueColor?.value ?? Theme.of(context).accentColor;
@override
State<StatefulWidget> createState() => _LiquidCircularProgressIndicatorState();
}
class _LiquidCircularProgressIndicatorState extends State<LiquidCircularProgressIndicator> {
@override
Widget build(BuildContext context) {
return ClipPath(
clipper: _CircleClipper(),
child: CustomPaint(
painter: _CirclePainter(
color: widget._getBackgroundColor(context),
),
foregroundPainter: _CircleBorderPainter(
color: widget.borderColor,
width: widget.borderWidth,
),
child: Stack(
children: [
Wave(
value: widget.value!,
color: widget._getValueColor(context),
direction: widget.direction,
),
if (widget.center != null) Center(child: widget.center),
],
),
),
);
}
}
class _CirclePainter extends CustomPainter {
final Color color;
_CirclePainter({required this.color});
@override
void paint(Canvas canvas, Size size) {
final paint = Paint()..color = color;
canvas.drawArc(Offset.zero & size, 0, _sweep, false, paint);
}
@override
bool shouldRepaint(_CirclePainter oldDelegate) => color != oldDelegate.color;
}
class _CircleBorderPainter extends CustomPainter {
final Color color;
final double width;
_CircleBorderPainter({required this.color, required this.width});
@override
void paint(Canvas canvas, Size size) {
final borderPaint = Paint()
..color = color
..style = PaintingStyle.stroke
..strokeWidth = width;
final newSize = Size(size.width - width, size.height - width);
canvas.drawArc(Offset(width / 2, width / 2) & newSize, 0, _sweep, false, borderPaint);
}
@override
bool shouldRepaint(_CircleBorderPainter oldDelegate) => color != oldDelegate.color || width != oldDelegate.width;
}
class _CircleClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
final path = Path()..addArc(Offset.zero & size, 0, _sweep);
return path;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}
@@ -0,0 +1,101 @@
import 'package:flutter/material.dart';
import 'wave.dart';
class LiquidCustomProgressIndicator extends ProgressIndicator {
///The widget to show in the center of the progress indicator.
final Widget? center;
///The direction the liquid travels.
final Axis direction;
///The path used to draw the shape of the progress indicator. The size of the progress indicator is controlled by the bounds of this path.
final Path shapePath;
LiquidCustomProgressIndicator({
Key? key,
double value = 0.5,
Color? backgroundColor,
Animation<Color>? valueColor,
this.center,
required this.direction,
required this.shapePath,
}) : super(
key: key,
value: value,
backgroundColor: backgroundColor,
valueColor: valueColor,
);
Color _getBackgroundColor(BuildContext context) => backgroundColor ?? Theme.of(context).backgroundColor;
Color _getValueColor(BuildContext context) => valueColor?.value ?? Theme.of(context).accentColor;
@override
State<StatefulWidget> createState() => _LiquidCustomProgressIndicatorState();
}
class _LiquidCustomProgressIndicatorState extends State<LiquidCustomProgressIndicator> {
@override
Widget build(BuildContext context) {
final pathBounds = widget.shapePath.getBounds();
return SizedBox(
width: pathBounds.width + pathBounds.left,
height: pathBounds.height + pathBounds.top,
child: ClipPath(
clipper: _CustomPathClipper(
path: widget.shapePath,
),
child: CustomPaint(
painter: _CustomPathPainter(
color: widget._getBackgroundColor(context),
path: widget.shapePath,
),
child: Stack(
children: <Widget>[
Positioned.fill(
left: pathBounds.left,
top: pathBounds.top,
child: Wave(
value: widget.value!,
color: widget._getValueColor(context),
direction: widget.direction,
),
),
if (widget.center != null) Center(child: widget.center),
],
),
),
),
);
}
}
class _CustomPathPainter extends CustomPainter {
final Color color;
final Path path;
_CustomPathPainter({required this.color, required this.path});
@override
void paint(Canvas canvas, Size size) {
final paint = Paint()..color = color;
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(_CustomPathPainter oldDelegate) => color != oldDelegate.color || path != oldDelegate.path;
}
class _CustomPathClipper extends CustomClipper<Path> {
final Path path;
_CustomPathClipper({required this.path});
@override
Path getClip(Size size) {
return path;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}
@@ -0,0 +1,152 @@
import 'package:flutter/material.dart';
import 'wave.dart';
class LiquidLinearProgressIndicator extends ProgressIndicator {
///The width of the border, if this is set [borderColor] must also be set.
final double? borderWidth;
///The color of the border, if this is set [borderWidth] must also be set.
final Color? borderColor;
///The radius of the border.
final double? borderRadius;
///The widget to show in the center of the progress indicator.
final Widget? center;
///The direction the liquid travels.
final Axis direction;
LiquidLinearProgressIndicator({
Key? key,
double value = 0.5,
Color? backgroundColor,
Animation<Color>? valueColor,
this.borderWidth,
this.borderColor,
this.borderRadius,
this.center,
this.direction = Axis.horizontal,
}) : super(
key: key,
value: value,
backgroundColor: backgroundColor,
valueColor: valueColor,
) {
if (borderWidth != null && borderColor == null || borderColor != null && borderWidth == null) {
throw ArgumentError("borderWidth and borderColor should both be set.");
}
}
Color _getBackgroundColor(BuildContext context) => backgroundColor ?? Theme.of(context).backgroundColor;
Color _getValueColor(BuildContext context) => valueColor?.value ?? Theme.of(context).accentColor;
@override
State<StatefulWidget> createState() => _LiquidLinearProgressIndicatorState();
}
class _LiquidLinearProgressIndicatorState extends State<LiquidLinearProgressIndicator> {
@override
Widget build(BuildContext context) {
return ClipPath(
clipper: _LinearClipper(
radius: widget.borderRadius!,
),
child: CustomPaint(
painter: _LinearPainter(
color: widget._getBackgroundColor(context),
radius: widget.borderRadius!,
),
foregroundPainter: _LinearBorderPainter(
color: widget.borderColor!,
width: widget.borderWidth!,
radius: widget.borderRadius!,
),
child: Stack(
children: <Widget>[
Wave(
value: widget.value!,
color: widget._getValueColor(context),
direction: widget.direction,
),
if (widget.center != null) Center(child: widget.center),
],
),
),
);
}
}
class _LinearPainter extends CustomPainter {
final Color color;
final double radius;
_LinearPainter({required this.color, required this.radius});
@override
void paint(Canvas canvas, Size size) {
final paint = Paint()..color = color;
canvas.drawRRect(
RRect.fromRectAndRadius(
Rect.fromLTWH(0, 0, size.width, size.height),
Radius.circular(radius),
),
paint);
}
@override
bool shouldRepaint(_LinearPainter oldDelegate) => color != oldDelegate.color;
}
class _LinearBorderPainter extends CustomPainter {
final Color color;
final double width;
final double? radius;
_LinearBorderPainter({
required this.color,
required this.width,
required this.radius,
});
@override
void paint(Canvas canvas, Size size) {
final paint = Paint()
..color = color
..style = PaintingStyle.stroke
..strokeWidth = width;
final alteredRadius = radius ?? 0;
canvas.drawRRect(
RRect.fromRectAndRadius(
Rect.fromLTWH(width / 2, width / 2, size.width - width, size.height - width),
Radius.circular(alteredRadius - width),
),
paint);
}
@override
bool shouldRepaint(_LinearBorderPainter oldDelegate) =>
color != oldDelegate.color || width != oldDelegate.width || radius != oldDelegate.radius;
}
class _LinearClipper extends CustomClipper<Path> {
final double? radius;
_LinearClipper({required this.radius});
@override
Path getClip(Size size) {
final path = Path()
..addRRect(
RRect.fromRectAndRadius(
Rect.fromLTWH(0, 0, size.width, size.height),
Radius.circular(radius ?? 0),
),
);
return path;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}
@@ -0,0 +1,5 @@
library liquid_progress_indicator;
export 'liquid_circular_progress_indicator.dart';
//export 'liquid_linear_progress_indicator.dart';
//export 'liquid_custom_progress_indicator.dart';
@@ -0,0 +1,114 @@
import 'dart:math' as math;
import 'package:flutter/material.dart';
class Wave extends StatefulWidget {
final double value;
final Color color;
final Axis direction;
const Wave({
Key? key,
required this.value,
required this.color,
required this.direction,
}) : super(key: key);
@override
_WaveState createState() => _WaveState();
}
class _WaveState extends State<Wave> with SingleTickerProviderStateMixin {
late AnimationController _animationController;
@override
void initState() {
super.initState();
_animationController = AnimationController(
vsync: this,
duration: Duration(seconds: 2),
);
_animationController.repeat();
}
@override
void dispose() {
_animationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: CurvedAnimation(
parent: _animationController,
curve: Curves.easeInOut,
),
builder: (context, child) => ClipPath(
child: Container(
color: widget.color,
),
clipper: _WaveClipper(
animationValue: _animationController.value,
value: widget.value,
direction: widget.direction,
),
),
);
}
}
class _WaveClipper extends CustomClipper<Path> {
final double animationValue;
final double value;
final Axis direction;
_WaveClipper({
required this.animationValue,
required this.value,
required this.direction,
});
@override
Path getClip(Size size) {
if (direction == Axis.horizontal) {
Path path = Path()
..addPolygon(_generateHorizontalWavePath(size), false)
..lineTo(0.0, size.height)
..lineTo(0.0, 0.0)
..close();
return path;
}
Path path = Path()
..addPolygon(_generateVerticalWavePath(size), false)
..lineTo(size.width, size.height)
..lineTo(0.0, size.height)
..close();
return path;
}
List<Offset> _generateHorizontalWavePath(Size size) {
final waveList = <Offset>[];
for (int i = -2; i <= size.height.toInt() + 2; i++) {
final waveHeight = (size.width / 20);
final dx = math.sin((animationValue * 360 - i) % 360 * (math.pi / 180)) * waveHeight + (size.width * value);
waveList.add(Offset(dx, i.toDouble()));
}
return waveList;
}
List<Offset> _generateVerticalWavePath(Size size) {
final waveList = <Offset>[];
for (int i = -2; i <= size.width.toInt() + 2; i++) {
final waveHeight = (size.height / 20);
final dy = math.sin((animationValue * 360 - i) % 360 * (math.pi / 180)) * waveHeight + (size.height - (size.height * value));
waveList.add(Offset(i.toDouble(), dy));
}
return waveList;
}
@override
bool shouldReclip(_WaveClipper oldClipper) => animationValue != oldClipper.animationValue;
}