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

Added Wavy circle clipper #27

Merged
merged 2 commits into from
Dec 18, 2022
Merged
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
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ To use this plugin, add `flutter_custom_clippers` as a [dependency in your pubsp
<img src="https://github.com/lohanidamodar/flutter_custom_clippers/raw/master/screenshots/screenshot4.png" height="480px">
<img src="https://github.com/lohanidamodar/flutter_custom_clippers/raw/master/screenshots/screenshot5.png" height="480px">
<img src="screenshots/side.png" height="480px">

<img src="https://github.com/shwetavish/flutter_custom_clippers/blob/wavy_circle_clipper/screenshots/screenshot10.png" height="480px">



Expand Down Expand Up @@ -224,6 +224,16 @@ class HomeScreen extends StatelessWidget {
child: Center(child: Text("MessageClipper()")),
),
),
SizedBox(height: 20),
ClipPath(
clipper: WavyCircleClipper(32),
child: Container(
width: 400,
height: 400,
color: Colors.purple,
child: const Center(child: Text("WavyCircleClipper()")),
),
),
],
),
);
Expand Down
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28
compileSdkVersion flutter.compileSdkVersion

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand Down
2 changes: 1 addition & 1 deletion example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:name="${applicationName}"
android:label="example"
android:icon="@mipmap/ic_launcher">
<activity
Expand Down
4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.6.10'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
20 changes: 16 additions & 4 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ class HomeScreen extends StatelessWidget {
padding: EdgeInsets.all(20.0),
children: <Widget>[
ClipPath(
clipper: WaveClipperOne(flip: true,reverse: true),
clipper: WaveClipperOne(flip: true, reverse: true),
child: Container(
height: 120,
color: Colors.orange,
child: Center(child: Text("WaveClipperTwo(flip: true,reverse: true)")),
child: Center(
child: Text("WaveClipperTwo(flip: true,reverse: true)")),
),
),
SizedBox(height: 10.0),
Expand All @@ -41,11 +42,12 @@ class HomeScreen extends StatelessWidget {
),
SizedBox(height: 10.0),
ClipPath(
clipper: WaveClipperTwo(flip: true,reverse: true),
clipper: WaveClipperTwo(flip: true, reverse: true),
child: Container(
height: 120,
color: Colors.orange,
child: Center(child: Text("WaveClipperTwo(flip: true,reverse:true)")),
child: Center(
child: Text("WaveClipperTwo(flip: true,reverse:true)")),
),
),
SizedBox(height: 10.0),
Expand Down Expand Up @@ -323,6 +325,16 @@ class HomeScreen extends StatelessWidget {
child: Center(child: Text("MessageClipper()")),
),
),
SizedBox(height: 20),
ClipPath(
clipper: WavyCircleClipper(32),
child: Container(
width: 400,
height: 400,
color: Colors.purple,
child: const Center(child: Text("WavyCircleClipper()")),
),
),
],
),
);
Expand Down
29 changes: 15 additions & 14 deletions lib/flutter_custom_clippers.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
export 'src/arc_clipper.dart';
export 'src/arrow_clipper.dart';
export 'src/diagonal_path_clipper_1.dart';
export 'src/diagonal_path_clipper_2.dart';
export 'src/hexagonal_clipper.dart';
export 'src/message_clipper.dart';
export 'src/movie_ticket_both_side_clipper.dart';
export 'src/movie_ticket_clipper.dart';
export 'src/multiple_pointed_edge.dart';
export 'src/multiple_rounded_curve.dart';
export 'src/octagonal_clipper.dart';
export 'src/oval_bottom_clipper.dart';
export 'src/oval_left_clipper.dart';
export 'src/oval_right_clipper.dart';
export 'src/oval_top_border_clipper.dart';
export 'src/parallelogram_clipper.dart';
export 'src/points_clipper.dart';
export 'src/rounded_diagonal_path_clipper.dart';
export 'src/side_cut_clipper.dart';
export 'src/star_clipper.dart';
export 'src/triangle_clipper.dart';
export 'src/wave_clipper_1.dart';
export 'src/wave_clipper_2.dart';
export 'src/multiple_pointed_edge.dart';
export 'src/multiple_rounded_curve.dart';
export 'src/arc_clipper.dart';
export 'src/movie_ticket_both_side_clipper.dart';
export 'src/movie_ticket_clipper.dart';
export 'src/points_clipper.dart';
export 'src/triangle_clipper.dart';
export 'src/arrow_clipper.dart';
export 'src/star_clipper.dart';
export 'src/message_clipper.dart';
export 'src/oval_left_clipper.dart';
export 'src/oval_right_clipper.dart';
export 'src/oval_bottom_clipper.dart';
export 'src/side_cut_clipper.dart';
export 'src/wavy_circle_clipper.dart';
71 changes: 71 additions & 0 deletions lib/src/wavy_circle_clipper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import 'dart:math' as math;

import 'package:flutter/widgets.dart';

/// Clip widget in star shape
class WavyCircleClipper extends CustomClipper<Path> {
WavyCircleClipper(this.numberOfPoints);

/// The number of points of the star
final int numberOfPoints;

late int counter = 0;

@override
Path getClip(Size size) {
double width = size.width;

double halfWidth = width / 2;

double radius = halfWidth / 1.11;

double outerCurveRadius = width / 2.08;

double innerCurveRadius = width / 2.42;

double degreesPerStep = _degToRad(360 / numberOfPoints) as double;

double halfDegreesPerStep = degreesPerStep / 2;

var path = Path();

double max = 2 * math.pi;

path.moveTo(width, halfWidth);

path.moveTo(
halfWidth + radius * math.cos(0 + halfDegreesPerStep),
halfWidth + radius * math.sin(0 + halfDegreesPerStep),
);

for (double step = 0; step < max + 1; step += degreesPerStep) {
if (counter % 2 == 0) {
path.quadraticBezierTo(
halfWidth + outerCurveRadius * math.cos(step),
halfWidth + outerCurveRadius * math.sin(step),
halfWidth + radius * math.cos(step + halfDegreesPerStep),
halfWidth + radius * math.sin(step + halfDegreesPerStep),
);
} else {
path.quadraticBezierTo(
halfWidth + innerCurveRadius * math.cos(step),
halfWidth + innerCurveRadius * math.sin(step),
halfWidth + radius * math.cos(step + halfDegreesPerStep),
halfWidth + radius * math.sin(step + halfDegreesPerStep),
);
}

counter++;
}
path.close();
return path;
}

num _degToRad(num deg) => deg * (math.pi / 180.0);

@override
bool shouldReclip(CustomClipper<Path> oldClipper) {
WavyCircleClipper oldie = oldClipper as WavyCircleClipper;
return numberOfPoints != oldie.numberOfPoints;
}
}
Binary file added screenshots/screenshot10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.