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

Adds handlerRadius as parameter #21

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
1 change: 1 addition & 0 deletions example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
10 changes: 10 additions & 0 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=C:\flutter"
export "FLUTTER_APPLICATION_PATH=E:\workspace\flutter_ws\flutter-circular-slider\example"
export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build\ios"
export "FLUTTER_FRAMEWORK_DIR=C:\flutter\bin\cache\artifacts\engine\ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
71 changes: 38 additions & 33 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,38 +85,40 @@ class _SleepPageState extends State<SleepPage> {
'How long did you stay in bed?',
style: TextStyle(color: Colors.white),
),
// SingleCircularSlider(
// 288,
// endTime,
// height: 220.0,
// width: 220.0,
// primarySectors: 6,
// secondarySectors: 24,
// baseColor: Color.fromRGBO(255, 255, 255, 0.1),
// selectionColor: baseColor,
// handlerColor: Colors.white,
// handlerOutterRadius: 12.0,
// onSelectionChange: _updateLabels,
// showRoundedCapInSelection: true,
// showHandlerOutter: false,
// child: Padding(
// padding: const EdgeInsets.all(42.0),
// child: Column(
// mainAxisAlignment: MainAxisAlignment.center,
// children: [
// SizedBox(height: 20),
// Text('${_formatIntervalTime(inBedTime, outBedTime)}',
// style: TextStyle(fontSize: 24.0, color: Colors.white)),
// Text('${_formatDays(days)}',
// style: TextStyle(
// fontSize: 16.0,
// color: Colors.white,
// fontStyle: FontStyle.italic)),
// ],
// )),
// shouldCountLaps: true,
// ),
DoubleCircularSlider(
SingleCircularSlider(
288,
endTime,
height: 220.0,
width: 220.0,
primarySectors: 6,
secondarySectors: 24,
baseColor: Color.fromRGBO(255, 255, 255, 0.1),
selectionColor: Color.fromRGBO(255, 255, 255, 0.1),//baseColor,
handlerColor: Colors.white,
handlerRadius: 16,
handlerOutterRadius: 24.0,
onSelectionChange: _updateLabels,
showRoundedCapInSelection: true,
showHandlerOutter: false,
child: Padding(
padding: const EdgeInsets.all(42.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(height: 20),
Text('${_formatIntervalTime(inBedTime, outBedTime)}',
style: TextStyle(fontSize: 24.0, color: Colors.white)),
Text('${_formatDays(days)}',
style: TextStyle(
fontSize: 16.0,
color: Colors.white,
fontStyle: FontStyle.italic)),
],
)),
shouldCountLaps: true,
),

/* DoubleCircularSlider(
288,
initTime,
endTime,
Expand Down Expand Up @@ -147,7 +149,10 @@ class _SleepPageState extends State<SleepPage> {
],
)),
shouldCountLaps: true,
),
), */



Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
_formatBedTime('IN THE', inBedTime),
_formatBedTime('OUT OF', outBedTime),
Expand Down
71 changes: 60 additions & 11 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
# Generated by pub
# See https://www.dartlang.org/tools/pub/glossary#lockfile
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.11"
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.2"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.4.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
version: "1.0.5"
charcode:
dependency: transitive
description:
Expand All @@ -29,6 +43,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.11"
convert:
dependency: transitive
description:
name: convert
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -46,41 +74,55 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
image:
dependency: transitive
description:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.4"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.5"
version: "0.12.6"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
version: "1.1.8"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.2"
version: "1.6.4"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.0"
version: "1.8.0+1"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
version: "2.0.5"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -113,7 +155,7 @@ packages:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
version: "1.0.5"
term_glyph:
dependency: transitive
description:
Expand All @@ -127,7 +169,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.4"
version: "0.2.11"
typed_data:
dependency: transitive
description:
Expand All @@ -142,5 +184,12 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.5.0"
sdks:
dart: ">=2.2.0 <3.0.0"
dart: ">=2.4.0 <3.0.0"
5 changes: 4 additions & 1 deletion lib/src/circular_slider_paint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CircularSliderPaint extends StatefulWidget {
final Color baseColor;
final Color selectionColor;
final Color handlerColor;
final double handlerRadius;
final double handlerOutterRadius;
final Widget child;
final bool showRoundedCapInSelection;
Expand All @@ -43,6 +44,7 @@ class CircularSliderPaint extends StatefulWidget {
@required this.baseColor,
@required this.selectionColor,
@required this.handlerColor,
@required this.handlerRadius,
@required this.handlerOutterRadius,
@required this.showRoundedCapInSelection,
@required this.showHandlerOutter,
Expand Down Expand Up @@ -181,6 +183,7 @@ class _CircularSliderState extends State<CircularSliderPaint> {
sweepAngle: _sweepAngle,
selectionColor: widget.selectionColor,
handlerColor: widget.handlerColor,
handlerRadius: widget.handlerRadius,
handlerOutterRadius: widget.handlerOutterRadius,
showRoundedCapInSelection: widget.showRoundedCapInSelection,
showHandlerOutter: widget.showHandlerOutter,
Expand Down Expand Up @@ -291,7 +294,7 @@ class _CircularSliderState extends State<CircularSliderPaint> {
}

if (isSingleHandler) {
if (isPointAlongCircle(position, _painter.center, _painter.radius)) {
if (isPointAlongCircle(position, _painter.center, _painter.radius,padding: widget.handlerOutterRadius)) {
_isEndHandlerSelected = true;
_onPanUpdate(details);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/src/single_circular_slider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class SingleCircularSlider extends StatefulWidget {
/// (int init, int end) => void
final SelectionChanged<int> onSelectionEnd;

/// radius for the handlers
final double handlerRadius;

/// outter radius for the handlers
final double handlerOutterRadius;

Expand Down Expand Up @@ -80,6 +83,7 @@ class SingleCircularSlider extends StatefulWidget {
this.handlerColor,
this.onSelectionChange,
this.onSelectionEnd,
this.handlerRadius,
this.handlerOutterRadius,
this.showRoundedCapInSelection,
this.showHandlerOutter,
Expand Down Expand Up @@ -134,6 +138,7 @@ class _SingleCircularSliderState extends State<SingleCircularSlider> {
selectionColor:
widget.selectionColor ?? Color.fromRGBO(255, 255, 255, 0.3),
handlerColor: widget.handlerColor ?? Colors.white,
handlerRadius: widget.handlerRadius ?? 8.0,
handlerOutterRadius: widget.handlerOutterRadius ?? 12.0,
showRoundedCapInSelection: widget.showRoundedCapInSelection ?? false,
showHandlerOutter: widget.showHandlerOutter ?? true,
Expand Down
7 changes: 5 additions & 2 deletions lib/src/slider_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SliderPainter extends CustomPainter {
double sweepAngle;
Color selectionColor;
Color handlerColor;
double handlerRadius;
double handlerOutterRadius;
bool showRoundedCapInSelection;
bool showHandlerOutter;
Expand All @@ -29,6 +30,7 @@ class SliderPainter extends CustomPainter {
@required this.sweepAngle,
@required this.selectionColor,
@required this.handlerColor,
@required this.handlerRadius,
@required this.handlerOutterRadius,
@required this.showRoundedCapInSelection,
@required this.showHandlerOutter,
Expand All @@ -51,15 +53,16 @@ class SliderPainter extends CustomPainter {
// draw handlers
if (mode == CircularSliderMode.doubleHandler) {
initHandler = radiansToCoordinates(center, -pi / 2 + startAngle, radius);
canvas.drawCircle(initHandler, 8.0, handler);
canvas.drawCircle(initHandler, handlerRadius, handler);
canvas.drawCircle(initHandler, handlerOutterRadius, handlerOutter);
}

endHandler = radiansToCoordinates(center, -pi / 2 + endAngle, radius);
canvas.drawCircle(endHandler, 8.0, handler);
canvas.drawCircle(endHandler, handlerRadius, handler);
if (showHandlerOutter) {
canvas.drawCircle(endHandler, handlerOutterRadius, handlerOutter);
}

}

Paint _getPaint({@required Color color, double width, PaintingStyle style}) =>
Expand Down
18 changes: 13 additions & 5 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:math';
import 'dart:ui';

import 'package:flutter/cupertino.dart';

double percentageToRadians(double percentage) => ((2 * pi * percentage) / 100);

double radiansToPercentage(double radians) {
Expand Down Expand Up @@ -30,18 +32,24 @@ int percentageToValue(double percentage, int intervals) =>
bool isPointInsideCircle(Offset point, Offset center, double rradius) {
var radius = rradius * 1.2;
return point.dx < (center.dx + radius) &&
point.dx > (center.dx - radius) &&
point.dy < (center.dy + radius) &&
point.dy > (center.dy - radius);
point.dx > (center.dx - radius) &&
point.dy < (center.dy + radius) &&
point.dy > (center.dy - radius);
}

bool isPointAlongCircle(Offset point, Offset center, double radius) {
bool isPointAlongCircle(Offset point, Offset center, double radius,{double padding=15}) {
// distance is root(sqr(x2 - x1) + sqr(y2 - y1))
// i.e., (7,8) and (3,2) -> 7.21

double padOffSet = padding*2;

radius = radius + padding;

var d1 = pow(point.dx - center.dx, 2);
var d2 = pow(point.dy - center.dy, 2);
var distance = sqrt(d1 + d2);
return (distance - radius).abs() < 10;

return (distance - radius).abs() < padOffSet;
}

double getSweepAngle(double init, double end) {
Expand Down
Loading