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

Dashed line option #17

Open
wants to merge 3 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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ ios/Runner/GeneratedPluginRegistrant.*

example/pubspec.lock
example/.packages
example/ios/Flutter/flutter_export_environment.sh
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ There are two different options:
| showHandlerOutter | true | If true will display an extra ring around the handlers. |
| sliderStrokeWidth | 12.0 | The stroke width for the slider (thickness). |
| shouldCountLaps | false | If true, onSelectionChange will also return the updated number of laps. |
| dashList | null | If specified, will draw the base circle as a dashed line. Is a `List<double>`, specifying the Dash intervals. |

### Use Cases

Expand Down
35 changes: 25 additions & 10 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Generated by pub
# See https://www.dartlang.org/tools/pub/glossary#lockfile
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.3.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 Down Expand Up @@ -59,28 +59,42 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
version: "1.1.7"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.2"
version: "1.6.4"
path_drawing:
dependency: transitive
description:
name: path_drawing
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.1"
path_parsing:
dependency: transitive
description:
name: path_parsing
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.0"
version: "1.8.0+1"
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 +127,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 +141,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.4"
version: "0.2.5"
typed_data:
dependency: transitive
description:
Expand All @@ -143,4 +157,5 @@ packages:
source: hosted
version: "2.0.8"
sdks:
dart: ">=2.2.0 <3.0.0"
dart: ">=2.2.2 <3.0.0"
flutter: ">=0.3.6 <2.0.0"
10 changes: 9 additions & 1 deletion lib/src/base_painter.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:path_drawing/path_drawing.dart';

import 'utils.dart';

Expand All @@ -10,6 +11,7 @@ class BasePainter extends CustomPainter {
int primarySectors;
int secondarySectors;
double sliderStrokeWidth;
List<double> dashList;

Offset center;
double radius;
Expand All @@ -20,6 +22,7 @@ class BasePainter extends CustomPainter {
@required this.primarySectors,
@required this.secondarySectors,
@required this.sliderStrokeWidth,
this.dashList,
});

@override
Expand All @@ -32,7 +35,12 @@ class BasePainter extends CustomPainter {

assert(radius > 0);

canvas.drawCircle(center, radius, base);
Path path = Path();
path.addOval(Rect.fromCircle(center: center, radius: radius));
if (dashList != null) {
path = dashPath(path, dashArray: CircularIntervalList<double>(dashList));
}
canvas.drawPath(path, base);

if (primarySectors > 0) {
_paintSectors(primarySectors, 8.0, selectionColor, canvas);
Expand Down
11 changes: 7 additions & 4 deletions lib/src/circular_slider_paint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CircularSliderPaint extends StatefulWidget {
final bool showHandlerOutter;
final double sliderStrokeWidth;
final bool shouldCountLaps;
final List<double> dashList;

CircularSliderPaint({
@required this.mode,
Expand All @@ -48,6 +49,7 @@ class CircularSliderPaint extends StatefulWidget {
@required this.showHandlerOutter,
@required this.sliderStrokeWidth,
@required this.shouldCountLaps,
this.dashList,
});

@override
Expand Down Expand Up @@ -113,10 +115,10 @@ class _CircularSliderState extends State<CircularSliderPaint> {
CustomPanGestureRecognizer:
GestureRecognizerFactoryWithHandlers<CustomPanGestureRecognizer>(
() => CustomPanGestureRecognizer(
onPanDown: _onPanDown,
onPanUpdate: _onPanUpdate,
onPanEnd: _onPanEnd,
),
onPanDown: _onPanDown,
onPanUpdate: _onPanUpdate,
onPanEnd: _onPanEnd,
),
(CustomPanGestureRecognizer instance) {},
),
},
Expand All @@ -127,6 +129,7 @@ class _CircularSliderState extends State<CircularSliderPaint> {
primarySectors: widget.primarySectors,
secondarySectors: widget.secondarySectors,
sliderStrokeWidth: widget.sliderStrokeWidth,
dashList: widget.dashList,
),
foregroundPainter: _painter,
child: Padding(
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 @@ -67,6 +67,9 @@ class SingleCircularSlider extends StatefulWidget {
/// otherwise, everytime the user completes a full lap, the selection restarts from 0
final bool shouldCountLaps;

/// if specified, use a dashed-line with the given Dash list as the base circle
final List<double> dashList;

SingleCircularSlider(
this.divisions,
this.position, {
Expand All @@ -85,6 +88,7 @@ class SingleCircularSlider extends StatefulWidget {
this.showHandlerOutter,
this.sliderStrokeWidth,
this.shouldCountLaps,
this.dashList,
}) : assert(position >= 0 && position <= divisions,
'init has to be > 0 and < divisions value'),
assert(divisions >= 0 && divisions <= 300,
Expand Down Expand Up @@ -138,6 +142,7 @@ class _SingleCircularSliderState extends State<SingleCircularSlider> {
showRoundedCapInSelection: widget.showRoundedCapInSelection ?? false,
showHandlerOutter: widget.showHandlerOutter ?? true,
shouldCountLaps: widget.shouldCountLaps ?? false,
dashList: widget.dashList,
));
}
}
35 changes: 25 additions & 10 deletions pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Generated by pub
# See https://www.dartlang.org/tools/pub/glossary#lockfile
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.3.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 Down Expand Up @@ -52,28 +52,42 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
version: "1.1.7"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.2"
version: "1.6.4"
path_drawing:
dependency: "direct main"
description:
name: path_drawing
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.1"
path_parsing:
dependency: transitive
description:
name: path_parsing
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.0"
version: "1.8.0+1"
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 @@ -106,7 +120,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 @@ -120,7 +134,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.4"
version: "0.2.5"
typed_data:
dependency: transitive
description:
Expand All @@ -136,4 +150,5 @@ packages:
source: hosted
version: "2.0.8"
sdks:
dart: ">=2.2.0 <3.0.0"
dart: ">=2.2.2 <3.0.0"
flutter: ">=0.3.6 <2.0.0"
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ environment:
dependencies:
flutter:
sdk: flutter
path_drawing: ^0.4.0 # for dashed lines

dev_dependencies:
flutter_test:
Expand Down