Skip to content

add feature that makes it possible to set touch on track to false #68

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

Open
wants to merge 1 commit 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
3 changes: 3 additions & 0 deletions example/lib/ui/example_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class ExampleViewModel {
final double min;
final double max;
final double value;
final bool touchOnTrack;
final InnerWidget? innerWidget;

ExampleViewModel(
Expand All @@ -15,6 +16,7 @@ class ExampleViewModel {
this.min = 0,
this.max = 100,
this.value = 50,
this.touchOnTrack = true,
this.innerWidget});
}

Expand Down Expand Up @@ -44,6 +46,7 @@ class ExamplePage extends StatelessWidget {
appearance: viewModel.appearance,
min: viewModel.min,
max: viewModel.max,
touchOnTrack: viewModel.touchOnTrack,
initialValue: viewModel.value,
)),
),
Expand Down
11 changes: 7 additions & 4 deletions example/lib/ui/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'package:flutter/material.dart';
import 'clock_page.dart';
import 'random_value_page.dart';
import 'package:example/utils.dart';
import 'dart:math' as math;

import 'package:example/utils.dart';
import 'package:flutter/material.dart';
import 'package:sleek_circular_slider/sleek_circular_slider.dart';

import 'clock_page.dart';
import 'example_page.dart';
import 'random_value_page.dart';

/// Example 01
final CircularSliderAppearance appearance01 = CircularSliderAppearance();
Expand All @@ -13,6 +15,7 @@ final viewModel01 = ExampleViewModel(
min: 0,
max: 100,
value: 60,
touchOnTrack:false,
pageColors: [Colors.white, HexColor('#E1C3FF')]);
final example01 = ExamplePage(
viewModel: viewModel01,
Expand Down
25 changes: 21 additions & 4 deletions lib/src/circular_slider.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
library circular_slider;

import 'package:flutter/material.dart';
import 'package:flutter/gestures.dart';
import 'dart:math' as math;

import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:sleek_circular_slider/src/slider_animations.dart';
import 'utils.dart';

import 'appearance.dart';
import 'slider_label.dart';
import 'dart:math' as math;
import 'utils.dart';

part 'curve_painter.dart';
part 'custom_gesture_recognizer.dart';

typedef void OnChange(double value);
typedef Widget InnerWidget(double percentage);


class SleekCircularSlider extends StatefulWidget {
final double initialValue;
final double min;
final double max;
final bool touchOnTrack;
final CircularSliderAppearance appearance;
final OnChange? onChange;
final OnChange? onChangeStart;
Expand All @@ -35,6 +39,7 @@ class SleekCircularSlider extends StatefulWidget {
this.initialValue = 50,
this.min = 0,
this.max = 100,
this.touchOnTrack = true,
this.appearance = defaultAppearance,
this.onChange,
this.onChangeStart,
Expand Down Expand Up @@ -297,6 +302,18 @@ class _SleekCircularSliderState extends State<SleekCircularSlider>
? widget.appearance.progressBarWidth
: 25.0;

if(!widget.touchOnTrack) {
Offset handlerOffset = degreesToCoordinates(
_painter!.center!, -math.pi / 2 + _startAngle + _currentAngle! + 1.5,
_painter!.radius);
if (!Rect.fromCenter(
center: position, width: touchWidth, height: touchWidth).contains(
handlerOffset)) {
return false;
}
}


if (isPointAlongCircle(
position, _painter!.center!, _painter!.radius, touchWidth)) {
_isHandlerSelected = true;
Expand Down