Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement - Wave amplitude and frequency #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Liquid progress indicator for Flutter.
borderWidth: 5.0,
direction: Axis.horizontal, // The direction the liquid moves (Axis.vertical = bottom to top, Axis.horizontal = left to right). Defaults to Axis.vertical.
center: Text("Loading..."),
waveCount: 2.0, //Defaults to 1.0
amplitude: 4.0, //Defaults to 2.0
);

### LiquidLinearProgressIndicator
Expand All @@ -43,6 +45,8 @@ Liquid progress indicator for Flutter.
borderRadius: 12.0,
direction: Axis.vertical, // The direction the liquid moves (Axis.vertical = bottom to top, Axis.horizontal = left to right). Defaults to Axis.horizontal.
center: Text("Loading..."),
waveCount: 2.0, //Defaults to 1.0
amplitude: 4.0, //Defaults to 2.0
);

### LiquidCustomProgressIndicator
Expand All @@ -53,6 +57,8 @@ Liquid progress indicator for Flutter.
backgroundColor: Colors.white, // Defaults to the current Theme's backgroundColor.
direction: Axis.vertical, // The direction the liquid moves (Axis.vertical = bottom to top, Axis.horizontal = left to right).
shapePath: _buildBoatPath(), // A Path object used to draw the shape of the progress indicator. The size of the progress indicator is created from the bounds of this path.
waveCount: 2.0, //Defaults to 1.0
amplitude: 4.0, //Defaults to 2.0
)


13 changes: 13 additions & 0 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=C:\src\flutter"
export "FLUTTER_APPLICATION_PATH=D:\Krishworks\liquid_progress_indicator\example"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=false"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=.dart_tool/package_config.json"
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Example extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Liquid Progress Indicator Examples"),
title: Text("Liquid Progress Indicator - Subhopriyo"),
),
body: Padding(
padding: const EdgeInsets.all(28.0),
Expand Down
14 changes: 12 additions & 2 deletions lib/src/liquid_circular_progress_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class LiquidCircularProgressIndicator extends ProgressIndicator {
///The direction the liquid travels.
final Axis direction;

///The number of waves that will be shown in one time frame
final double waveCount;

///The amplitude of the waves
final double amplitude;

LiquidCircularProgressIndicator({
Key? key,
double value = 0.5,
Expand All @@ -29,6 +35,8 @@ class LiquidCircularProgressIndicator extends ProgressIndicator {
this.borderColor,
this.center,
this.direction = Axis.vertical,
this.waveCount = 1,
this.amplitude = 2,
}) : super(
key: key,
value: value,
Expand Down Expand Up @@ -72,6 +80,8 @@ class _LiquidCircularProgressIndicatorState
value: widget.value,
color: widget._getValueColor(context),
direction: widget.direction,
waveCount: widget.waveCount,
amplitude: widget.amplitude,
),
if (widget.center != null) Center(child: widget.center),
],
Expand Down Expand Up @@ -113,8 +123,8 @@ class _CircleBorderPainter extends CustomPainter {
..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);
canvas.drawArc(Offset(width! / 2, width! / 2) & newSize, 0, _sweep, false,
borderPaint);
}

@override
Expand Down
10 changes: 10 additions & 0 deletions lib/src/liquid_custom_progress_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ class LiquidCustomProgressIndicator extends ProgressIndicator {
///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;

///The number of waves that will be shown in one time frame
final double waveCount;

///The amplitude of the waves
final double amplitude;

LiquidCustomProgressIndicator({
Key? key,
double value = 0.5,
Expand All @@ -19,6 +25,8 @@ class LiquidCustomProgressIndicator extends ProgressIndicator {
this.center,
required this.direction,
required this.shapePath,
this.waveCount = 1,
this.amplitude = 2,
}) : super(
key: key,
value: value,
Expand Down Expand Up @@ -62,6 +70,8 @@ class _LiquidCustomProgressIndicatorState
value: widget.value,
color: widget._getValueColor(context),
direction: widget.direction,
waveCount: widget.waveCount,
amplitude: widget.amplitude,
),
),
if (widget.center != null) Center(child: widget.center),
Expand Down
10 changes: 10 additions & 0 deletions lib/src/liquid_linear_progress_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ class LiquidLinearProgressIndicator extends ProgressIndicator {
///The direction the liquid travels.
final Axis direction;

///The number of waves that will be shown in one time frame
final double waveCount;

///The amplitude of the waves
final double amplitude;

LiquidLinearProgressIndicator({
Key? key,
double value = 0.5,
Expand All @@ -27,6 +33,8 @@ class LiquidLinearProgressIndicator extends ProgressIndicator {
this.borderRadius,
this.center,
this.direction = Axis.horizontal,
this.waveCount = 1,
this.amplitude = 2,
}) : super(
key: key,
value: value,
Expand Down Expand Up @@ -73,6 +81,8 @@ class _LiquidLinearProgressIndicatorState
value: widget.value,
color: widget._getValueColor(context),
direction: widget.direction,
waveCount: widget.waveCount,
amplitude: widget.amplitude,
),
if (widget.center != null) Center(child: widget.center),
],
Expand Down
43 changes: 34 additions & 9 deletions lib/src/wave.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ class Wave extends StatefulWidget {
final double? value;
final Color color;
final Axis direction;
final double waveCount;
final double amplitude;

const Wave({
Key? key,
required this.value,
required this.color,
required this.direction,
required this.waveCount,
required this.amplitude,
}) : super(key: key);

@override
Expand Down Expand Up @@ -50,10 +54,11 @@ class _WaveState extends State<Wave> with SingleTickerProviderStateMixin {
color: widget.color,
),
clipper: _WaveClipper(
animationValue: _animationController.value,
value: widget.value,
direction: widget.direction,
),
animationValue: _animationController.value,
value: widget.value,
direction: widget.direction,
waveCount: widget.waveCount,
amplitude: widget.amplitude),
),
);
}
Expand All @@ -63,11 +68,15 @@ class _WaveClipper extends CustomClipper<Path> {
final double animationValue;
final double? value;
final Axis direction;
final double waveCount;
final double amplitude;

_WaveClipper({
required this.animationValue,
required this.value,
required this.direction,
required this.waveCount,
required this.amplitude,
});

@override
Expand All @@ -81,11 +90,27 @@ class _WaveClipper extends CustomClipper<Path> {
return path;
}

Path path = Path()
..addPolygon(_generateVerticalWavePath(size), false)
..lineTo(size.width, size.height)
..lineTo(0.0, size.height)
..close();
double p = value ?? 50 / 100.0;
double n = waveCount;
double amp = amplitude;
double baseHeight = (1 - p) * size.height;

Path path = Path();
path.moveTo(0.0, baseHeight);
for (double i = 0.0; i < size.width; i++) {
path.lineTo(
i,
baseHeight +
math.sin((i / size.width * 2 * math.pi * n) +
(animationValue * 2 * math.pi) +
math.pi * 1) *
amp);
}

path.lineTo(size.width, size.height);
path.lineTo(0.0, size.height);
path.close();

return path;
}

Expand Down