Skip to content

Commit

Permalink
feat: Arc component supports: displayOnly, SingleSelector, DoubleSele…
Browse files Browse the repository at this point in the history
…ctor modes

Support for Arc component to display:
* displayOnly: No thumb selector is shown
* SingleSelector: One thumb selector is shown
* DoubleSelector: (WIP) Two selectors will be shown
  • Loading branch information
ses110 committed May 21, 2021
1 parent f46cd1a commit fd1a722
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
61 changes: 37 additions & 24 deletions lib/components/arc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'dart:math';

import 'package:flutter/material.dart';

enum ArcMode { displayOnly, singleSelection, doubleSelection }

class Arc extends StatefulWidget {
final Widget centerWidget;
final Color color;
Expand All @@ -10,14 +12,17 @@ class Arc extends StatefulWidget {

final double initialValue;

Arc(
{Key key,
@required this.centerWidget,
this.color,
@required this.initialValue,
@required this.onFinalSetPoint,
@required this.maxValue})
: super(key: key);
final ArcMode arcMode;

Arc({
Key key,
this.arcMode = ArcMode.singleSelection,
@required this.centerWidget,
@required this.initialValue,
@required this.maxValue,
@required this.onFinalSetPoint,
this.color,
}) : super(key: key);

@override
_ArcState createState() => _ArcState();
Expand Down Expand Up @@ -95,28 +100,36 @@ class _ArcState extends State<Arc> {
height: height,
child: GestureDetector(
onTapDown: (TapDownDetails details) {
final x = details.localPosition.dx;
final y = details.localPosition.dy;
updateXYAndSetValue(x, y, width);
if (widget.arcMode != ArcMode.displayOnly) {
final x = details.localPosition.dx;
final y = details.localPosition.dy;
updateXYAndSetValue(x, y, width);
}
},
onPanEnd: (DragEndDetails details) {
final _value = calculateMagnitude();
setState(() {
value = _value;
});
widget.onFinalSetPoint(value);
if (widget.arcMode != ArcMode.displayOnly) {
final _value = calculateMagnitude();
setState(() {
value = _value;
});
widget.onFinalSetPoint(value);
}
},
onPanUpdate: (DragUpdateDetails details) {
final x = details.localPosition.dx;
final y = details.localPosition.dy;
updateXYAndSetValue(x, y, width);
if (widget.arcMode != ArcMode.displayOnly) {
final x = details.localPosition.dx;
final y = details.localPosition.dy;
updateXYAndSetValue(x, y, width);
}
},
onTapUp: (TapUpDetails details) {
final _value = calculateMagnitude();
setState(() {
value = _value;
});
widget.onFinalSetPoint(value);
if (widget.arcMode != ArcMode.displayOnly) {
final _value = calculateMagnitude();
setState(() {
value = _value;
});
widget.onFinalSetPoint(value);
}
},
child: CustomPaint(
painter:
Expand Down
1 change: 1 addition & 0 deletions lib/components/lock_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class LockWidget extends StatelessWidget {
),
Center(
child: Arc(
arcMode: ArcMode.displayOnly,
centerWidget: SizedBox(
width: 175,
height: 175,
Expand Down

0 comments on commit fd1a722

Please sign in to comment.