From 33a2dde7d5249c84b3a65aee6e12028789109511 Mon Sep 17 00:00:00 2001 From: Afroz-Shaikh Date: Mon, 29 May 2023 12:16:10 +0530 Subject: [PATCH] WIP- needle Pointer --- example/lib/gauge_vertical.dart | 2 +- example/lib/main.dart | 31 +- example/lib/multiple_pointer_example.dart | 2 +- example/lib/pointer_alignment_example.dart | 2 +- example/lib/shaders.dart | 2 +- example/lib/tickness_extend_example.dart | 2 +- example/lib/valuebar_position.dart | 2 +- lib/geekyants_flutter_gauges.dart | 2 + .../linear_gauge/linear_gauge_painter.dart | 8 +- .../pointers/linear_gauge_pointer.dart | 2 +- .../pointers/linear_gauge_shape_pointer.dart | 8 +- .../linear_gauge_shape_pointer_painter.dart | 2 +- .../pointers/linear_gauge_widget_pointer.dart | 5 - .../linear_gauge_widget_pointer_painter.dart | 1 - .../linear_gauge/rulers/label_painter.dart | 8 +- .../radial_gauge/pointer/needle_pointer.dart | 2 +- .../pointer/needle_pointer_painter.dart | 60 +++- lib/src/radial_gauge/radial_gauge.dart | 248 +++++++++++--- .../radial_gauge/radial_gauge_container.dart | 170 +++++---- lib/src/radial_gauge/radial_track.dart | 33 +- .../shape_pointer/radial_shape_pointer.dart | 187 ++++++++++ .../valuebar/radial_value_bar.dart | 82 ++++- .../valuebar/radial_value_bar_painter.dart | 33 +- test/gauges_test.dart | 2 +- test/pointers_test/pointer_test_cases.dart | 324 +++++++++--------- 25 files changed, 837 insertions(+), 383 deletions(-) create mode 100644 lib/src/radial_gauge/shape_pointer/radial_shape_pointer.dart diff --git a/example/lib/gauge_vertical.dart b/example/lib/gauge_vertical.dart index 899b1ed7..7e601de9 100644 --- a/example/lib/gauge_vertical.dart +++ b/example/lib/gauge_vertical.dart @@ -25,7 +25,7 @@ class _MyVerticalGaugeState extends State { rulers: RulerStyle( primaryRulersWidth: 10, primaryRulersHeight: 30, - primaryRulerColor: Color(0xff310072), + primaryRulerColor: const Color(0xff310072), inverseRulers: false, showLabel: false, showSecondaryRulers: false, diff --git a/example/lib/main.dart b/example/lib/main.dart index 2f229725..d0cfc732 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -6,40 +6,11 @@ void main() { runApp( const MaterialApp( debugShowCheckedModeBanner: false, - home: MyValueBarPosition(), + home: MyGaugeExample(), ), ); } -class MyValueBarPosition extends StatefulWidget { - const MyValueBarPosition({super.key}); - - @override - State createState() => _MyValueBarPositionState(); -} - -class _MyValueBarPositionState extends State { - double value = 50; - @override - Widget build(BuildContext context) { - return const Scaffold( - body: Center( - child: RadialGauge( - needlePointer: NeedlePointer(value: 5), - track: RadialTrack( - steps: 1, - startAngle: 0, - endAngle: 360, - hideTrack: true, - start: 0, - end: 12, - ), - ), - ), - ); - } -} - class MyGaugeExample extends StatefulWidget { const MyGaugeExample({Key? key}) : super(key: key); diff --git a/example/lib/multiple_pointer_example.dart b/example/lib/multiple_pointer_example.dart index a5d32224..2aa7221a 100644 --- a/example/lib/multiple_pointer_example.dart +++ b/example/lib/multiple_pointer_example.dart @@ -19,7 +19,7 @@ class _MultiplePointerExampleState extends State { valueBar: const [ ValueBar(value: 23, color: Colors.red), ], - pointers: [ + pointers: const [ Pointer( value: 28, width: 20, diff --git a/example/lib/pointer_alignment_example.dart b/example/lib/pointer_alignment_example.dart index cbff9ab1..4c7d2eef 100644 --- a/example/lib/pointer_alignment_example.dart +++ b/example/lib/pointer_alignment_example.dart @@ -15,7 +15,7 @@ class _PointerAlignmentExampleState extends State { return Center( child: LinearGauge( gaugeOrientation: GaugeOrientation.vertical, - pointers: [ + pointers: const [ Pointer( color: Colors.red, value: 30, diff --git a/example/lib/shaders.dart b/example/lib/shaders.dart index f2656e72..de85e9b6 100644 --- a/example/lib/shaders.dart +++ b/example/lib/shaders.dart @@ -64,7 +64,7 @@ class _MyShadersState extends State { rulerPosition: RulerPosition.center, inverseRulers: true, // secondaryRulersHeight: 300, - textStyle: TextStyle( + textStyle: const TextStyle( fontSize: 12, ), // rulersOffset: 20, diff --git a/example/lib/tickness_extend_example.dart b/example/lib/tickness_extend_example.dart index 4f28e9d0..7142d44a 100644 --- a/example/lib/tickness_extend_example.dart +++ b/example/lib/tickness_extend_example.dart @@ -26,7 +26,7 @@ class _ThicknessExtendExampleState extends State { enableGaugeAnimation: true, linearGaugeBoxDecoration: const LinearGaugeBoxDecoration(thickness: 20), - pointers: [ + pointers: const [ Pointer( shape: PointerShape.triangle, pointerPosition: PointerPosition.left, diff --git a/example/lib/valuebar_position.dart b/example/lib/valuebar_position.dart index 0273b8fd..0d23ab57 100644 --- a/example/lib/valuebar_position.dart +++ b/example/lib/valuebar_position.dart @@ -35,7 +35,7 @@ class _MyValueBarPositionState extends State { height: 100, width: 100, color: Colors.black.withOpacity(0.3), - labelStyle: TextStyle(color: Colors.black), + labelStyle: const TextStyle(color: Colors.black), pointerPosition: PointerPosition.top, ), // ShapePointer( diff --git a/lib/geekyants_flutter_gauges.dart b/lib/geekyants_flutter_gauges.dart index 03c05185..5c8dffc5 100644 --- a/lib/geekyants_flutter_gauges.dart +++ b/lib/geekyants_flutter_gauges.dart @@ -29,7 +29,9 @@ export './src/linear_gauge/custom_label/custom_ruler_label.dart'; export './src/linear_gauge/value_bar/value_bar.dart'; export './src/linear_gauge/utils/enums.dart'; export './src/linear_gauge/curve/custom_curve.dart'; + export './src/radial_gauge/radial_gauge.dart'; export './src/radial_gauge/radial_track.dart'; export 'src/radial_gauge/pointer/needle_pointer.dart'; export 'src/radial_gauge/valuebar/radial_value_bar.dart'; +export 'src/radial_gauge/shape_pointer/radial_shape_pointer.dart'; diff --git a/lib/src/linear_gauge/linear_gauge_painter.dart b/lib/src/linear_gauge/linear_gauge_painter.dart index 95de779c..170689f2 100644 --- a/lib/src/linear_gauge/linear_gauge_painter.dart +++ b/lib/src/linear_gauge/linear_gauge_painter.dart @@ -1627,7 +1627,7 @@ class RenderLinearGauge extends RenderBox yAxisForGaugeContainer = spacingForGauge; if (topCurveMaxHeight! <= pointerMaxOfTopAndCenter!) { - valueBarMaxOfTopAndCenter = 0; + topCurveMaxHeight = 0; } else { pointerMaxOfTopAndCenter = topCurveMaxHeight!; valueBarMaxOfTopAndCenter = 0; @@ -1641,7 +1641,7 @@ class RenderLinearGauge extends RenderBox } if (bottomCurveMaxHeight! <= pointerMaxOfBottomAndCenter!) { - valueBarMaxOfBottomAndCenter = 0; + bottomCurveMaxHeight = 0; } else { pointerMaxOfBottomAndCenter = bottomCurveMaxHeight!; valueBarMaxOfBottomAndCenter = 0; @@ -1665,7 +1665,7 @@ class RenderLinearGauge extends RenderBox yAxisForGaugeContainer = pointerMaxOfTopAndCenter!; if (topCurveMaxHeight! <= pointerMaxOfTopAndCenter!) { - valueBarMaxOfTopAndCenter = 0; + topCurveMaxHeight = 0; } else { yAxisForGaugeContainer = topCurveMaxHeight!; pointerMaxOfTopAndCenter = yAxisForGaugeContainer; @@ -1687,7 +1687,7 @@ class RenderLinearGauge extends RenderBox } if (bottomCurveMaxHeight! <= pointerMaxOfBottomAndCenter! + spacingForGauge) { - // valueBarMaxOfBottomAndCenter = 0; + bottomCurveMaxHeight = 0; } else { valueBarMaxOfBottomAndCenter = bottomCurveMaxHeight! - spacingForGauge; pointerMaxOfBottomAndCenter = 0; diff --git a/lib/src/linear_gauge/pointers/linear_gauge_pointer.dart b/lib/src/linear_gauge/pointers/linear_gauge_pointer.dart index 9a622a0b..8cad9dde 100644 --- a/lib/src/linear_gauge/pointers/linear_gauge_pointer.dart +++ b/lib/src/linear_gauge/pointers/linear_gauge_pointer.dart @@ -49,7 +49,7 @@ abstract class BasePointer { /// ), /// ), /// ``` - double value; + final double value; /// /// Pointer Position on the [LinearGauge] sets the position of `pointer` on the [LinearGauge] diff --git a/lib/src/linear_gauge/pointers/linear_gauge_shape_pointer.dart b/lib/src/linear_gauge/pointers/linear_gauge_shape_pointer.dart index 740ae525..bca7cddf 100644 --- a/lib/src/linear_gauge/pointers/linear_gauge_shape_pointer.dart +++ b/lib/src/linear_gauge/pointers/linear_gauge_shape_pointer.dart @@ -20,8 +20,10 @@ import 'package:geekyants_flutter_gauges/geekyants_flutter_gauges.dart'; /// ``` /// /// +/// + class Pointer extends LeafRenderObjectWidget implements BasePointer { - Pointer({ + const Pointer({ Key? key, required this.value, this.height = 10.0, @@ -51,7 +53,7 @@ class Pointer extends LeafRenderObjectWidget implements BasePointer { /// ), /// ``` @override - double value; + final double value; /// /// `height` Sets the height of the pointer on the [LinearGauge] @@ -91,7 +93,7 @@ class Pointer extends LeafRenderObjectWidget implements BasePointer { /// ), /// ``` - bool isInteractive; + final bool isInteractive; /// /// `color` Sets the color of the pointer on the [LinearGauge] diff --git a/lib/src/linear_gauge/pointers/linear_gauge_shape_pointer_painter.dart b/lib/src/linear_gauge/pointers/linear_gauge_shape_pointer_painter.dart index 3bda4a02..c7e23886 100644 --- a/lib/src/linear_gauge/pointers/linear_gauge_shape_pointer_painter.dart +++ b/lib/src/linear_gauge/pointers/linear_gauge_shape_pointer_painter.dart @@ -473,7 +473,7 @@ class RenderLinearGaugeShapePointer extends RenderOpacity { offset.dy + height + yAxisTurn); break; case PointerPosition.center: - var yAxisTurn; + var yAxisTurn = 0.0; if (gaugeOrientation == GaugeOrientation.horizontal) { yAxisTurn = (quarterTurns == QuarterTurns.zero || quarterTurns == QuarterTurns.two) diff --git a/lib/src/linear_gauge/pointers/linear_gauge_widget_pointer.dart b/lib/src/linear_gauge/pointers/linear_gauge_widget_pointer.dart index 2b7574eb..9a2d73ca 100644 --- a/lib/src/linear_gauge/pointers/linear_gauge_widget_pointer.dart +++ b/lib/src/linear_gauge/pointers/linear_gauge_widget_pointer.dart @@ -170,9 +170,4 @@ class WidgetPointer extends SingleChildRenderObjectWidget super.updateRenderObject(context, renderObject); } - - @override - set value(double _value) { - value = _value; - } } diff --git a/lib/src/linear_gauge/pointers/linear_gauge_widget_pointer_painter.dart b/lib/src/linear_gauge/pointers/linear_gauge_widget_pointer_painter.dart index c739ab32..4b12e88e 100644 --- a/lib/src/linear_gauge/pointers/linear_gauge_widget_pointer_painter.dart +++ b/lib/src/linear_gauge/pointers/linear_gauge_widget_pointer_painter.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; - import '../../../geekyants_flutter_gauges.dart'; import '../linear_gauge_label.dart'; import '../linear_gauge_painter.dart'; diff --git a/lib/src/linear_gauge/rulers/label_painter.dart b/lib/src/linear_gauge/rulers/label_painter.dart index 492ec9b1..932b13b7 100644 --- a/lib/src/linear_gauge/rulers/label_painter.dart +++ b/lib/src/linear_gauge/rulers/label_painter.dart @@ -244,7 +244,7 @@ class RenderRulerLabel extends RenderBox { _endLabelSize = parentDataRef.linearGaugeLabel.endLabelSize; gaugeStart = parentDataRef.gaugeStart; gaugeEnd = parentDataRef.gaugeEnd; - Size _axisActualSize; + Size axisActualSize; setCustomLabelStartEnd(); double actualParentWidth; @@ -275,12 +275,12 @@ class RenderRulerLabel extends RenderBox { } if (_isHorizontalOrientation) { - _axisActualSize = Size(actualParentWidth, effectiveLabelHeight); + axisActualSize = Size(actualParentWidth, effectiveLabelHeight); } else { - _axisActualSize = Size(effectiveLabelHeight, actualParentWidth); + axisActualSize = Size(effectiveLabelHeight, actualParentWidth); } - size = _axisActualSize; + size = axisActualSize; } void _drawLabels( diff --git a/lib/src/radial_gauge/pointer/needle_pointer.dart b/lib/src/radial_gauge/pointer/needle_pointer.dart index 6265267b..1cf975dc 100644 --- a/lib/src/radial_gauge/pointer/needle_pointer.dart +++ b/lib/src/radial_gauge/pointer/needle_pointer.dart @@ -10,7 +10,7 @@ class NeedlePointer extends LeafRenderObjectWidget { this.color = Colors.red, this.tailColor = Colors.red, this.needleWidth = 10, - this.needleHeight = 350, + this.needleHeight = 150, this.tailRadius = 20}) : super(key: key); diff --git a/lib/src/radial_gauge/pointer/needle_pointer_painter.dart b/lib/src/radial_gauge/pointer/needle_pointer_painter.dart index 1910b540..dfbb8b64 100644 --- a/lib/src/radial_gauge/pointer/needle_pointer_painter.dart +++ b/lib/src/radial_gauge/pointer/needle_pointer_painter.dart @@ -1,8 +1,5 @@ import 'dart:math'; - -import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; - import '../../../geekyants_flutter_gauges.dart'; class RenderNeedlePointer extends RenderBox { @@ -112,7 +109,8 @@ class RenderNeedlePointer extends RenderBox { final canvas = context.canvas; final center = offset; - Rect circle = Rect.fromLTWH(offset.dx, offset.dy, size.width, _tailRadius); + Rect circle = Rect.fromLTWH(offset.dx - getTailRadius / 2, + offset.dy - getTailRadius / 2, _tailRadius, _tailRadius); Path circlePath = Path()..addOval(circle); double strokeWidth = _needleWidth; @@ -123,30 +121,54 @@ class RenderNeedlePointer extends RenderBox { double gaugeEnd = _radialGauge!.track.end; double value = calculateValueAngle(_value, gaugeStart, gaugeEnd); - double startAngle = _radialGauge!.track.startAngle * (pi / 180); - double endAngle = _radialGauge!.track.endAngle * (pi / 180); + double startAngle = (_radialGauge!.track.startAngle - 180) * (pi / 180); + double endAngle = (_radialGauge!.track.endAngle - 180) * (pi / 180); - final double needleMultiplier = _needleHeight; + final maxH = size.shortestSide / 2 * getRadialGauge.radiusFactor; + + final double needleMultiplier = _needleHeight.clamp(0, maxH - 40); final double angle = startAngle + (value / 100) * (endAngle - startAngle); - final double needleEndX = - center.dx + getTailRadius / 2 + needleMultiplier * cos(angle); - final double needleEndY = - center.dy + getTailRadius / 2 + needleMultiplier * sin(angle); + double needleEndX = center.dx + needleMultiplier * cos(angle); + double needleEndY = center.dy + needleMultiplier * sin(angle); + double needleStartX = center.dx; + double needleStartY = center.dy; final needlePaint = Paint() ..color = _color ..strokeWidth = strokeWidth - ..shader = gradient.createShader(Rect.fromPoints( - Offset(center.dx + getTailRadius / 2, center.dy + getTailRadius / 2), - Offset(needleEndX, needleEndY), - )) + ..shader = gradient.createShader( + Rect.fromPoints( + Offset(needleStartX, needleStartY), + Offset(needleEndX, needleEndY), + ), + ) ..strokeCap = StrokeCap.round; - canvas.drawLine( - Offset(center.dx + getTailRadius / 2, center.dy + getTailRadius / 2), - Offset(needleEndX, needleEndY), - needlePaint); + + // Simple Needle + // canvas.drawLine(Offset(needleStartX, needleStartY), + // Offset(needleEndX, needleEndY), needlePaint); + + // Needle Path + Path needlePath = Path(); + needlePath.moveTo(offset.dx + getTailRadius / 2 * cos(angle + pi / 2), + offset.dy - getTailRadius / 2 * sin(angle - pi / 2)); + needlePath.lineTo(needleStartX + getTailRadius / 2 * cos(angle - pi / 2), + needleStartY - (getTailRadius / 2) * sin(angle + pi / 2)); + + double temp1 = 30; + needlePath.moveTo(offset.dx + temp1 * cos(angle + pi / 2), + offset.dy - temp1 * sin(angle - pi / 2)); + needlePath.lineTo(needleStartX + temp1 * cos(angle - pi / 2), + needleStartY - (temp1) * sin(angle + pi / 2)); + + needlePath.lineTo(needleEndX, needleEndY); + // Offset c = Offset(offset.dx, offset.dy - getTailRadius); + // canvas.drawCircle(c, 100, Paint()..color = Colors.black); + needlePath.close(); + //* Needle Pointer paint + canvas.drawPath(needlePath, needlePaint); canvas.drawPath(circlePath, Paint()..color = _tailColor); } diff --git a/lib/src/radial_gauge/radial_gauge.dart b/lib/src/radial_gauge/radial_gauge.dart index 050c477d..c45480ec 100644 --- a/lib/src/radial_gauge/radial_gauge.dart +++ b/lib/src/radial_gauge/radial_gauge.dart @@ -1,11 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; -import 'package:geekyants_flutter_gauges/src/radial_gauge/pointer/needle_pointer.dart'; +import 'package:geekyants_flutter_gauges/geekyants_flutter_gauges.dart'; import 'package:geekyants_flutter_gauges/src/radial_gauge/pointer/needle_pointer_painter.dart'; import 'package:geekyants_flutter_gauges/src/radial_gauge/radial_gauge_container.dart'; import 'package:geekyants_flutter_gauges/src/radial_gauge/radial_gauge_state.dart'; -import 'package:geekyants_flutter_gauges/src/radial_gauge/radial_track.dart'; -import 'package:geekyants_flutter_gauges/src/radial_gauge/valuebar/radial_value_bar.dart'; import 'package:geekyants_flutter_gauges/src/radial_gauge/valuebar/radial_value_bar_painter.dart'; /// Creates a Radial Gauge Widget to display the values in a Radial Scale. @@ -27,12 +25,79 @@ class RadialGauge extends StatefulWidget { Key? key, required this.track, this.valueBar, - this.needlePointer = const NeedlePointer( - value: 0, - ), + this.xCenterCoordinate = 0.5, + this.yCenterCoordinate = 0.5, + this.radiusFactor = 1, + this.shapePointer = const [], + this.needlePointer = const [], // List? track, }) : super(key: key); + /// + /// The x-coordinate of the center of the Radial Gauge. + /// + /// Defaults to 0.5. + /// ```dart + /// RadialGauge( + /// xCenterCoordinate: 0.5, + /// track: RadialTrack( + /// start: 0, + /// end: 100, + /// ), + /// ), + /// ``` + /// + final double xCenterCoordinate; + + /// + /// The y-coordinate of the center of the Radial Gauge. + /// + /// Defaults to 0.5. + /// ```dart + /// RadialGauge( + /// yCenterCoordinate: 0.5, + /// track: RadialTrack( + /// start: 0, + /// end: 100, + /// ), + /// ), + /// ``` + final double yCenterCoordinate; + + /// + /// The radius factor of the Radial Gauge. + /// The value ranges from 0 to 1. + /// + /// Defaults to 1. + /// ```dart + /// RadialGauge( + /// radiusFactor: 0.8, + /// track: RadialTrack( + /// start: 0, + /// end: 100, + /// ), + /// ), + /// ``` + /// + final double radiusFactor; + + /// + /// The list of [ShapePointers] to be displayed in the Radial Gauge. + /// + /// ```dart + /// RadialGauge( + /// track: RadialTrack( + /// start: 0, + /// end: 100, + /// ), + /// shapePointer: [ + /// RadialShapePointer(value: 10), + /// ], + /// ), + /// ``` + /// + final List? shapePointer; + /// /// The list of [RadialTrack] to be displayed in the Radial Gauge. /// @@ -64,7 +129,7 @@ class RadialGauge extends StatefulWidget { /// ), /// ``` /// - final NeedlePointer? needlePointer; + final List? needlePointer; /// /// The [RadialValueBar] is used to display the value in the Radial Gauge. @@ -78,7 +143,7 @@ class RadialGauge extends StatefulWidget { /// ), /// ``` /// - final RadialValueBar? valueBar; + final List? valueBar; @override State createState() => _RadialGaugeState(); @@ -109,18 +174,31 @@ class _RadialGaugeState extends State { )); if (widget.needlePointer != null) { - _addChild(widget.needlePointer!, null, null); + for (int i = 0; i < widget.needlePointer!.length; i++) { + _addChild(widget.needlePointer![i], null, null); + } } if (widget.valueBar != null) { - _addChild(widget.valueBar!, null, null); + for (int i = 0; i < widget.valueBar!.length; i++) { + _addChild(widget.valueBar![i], null, null); + } + } + + if (widget.shapePointer != null) { + for (int i = 0; i < widget.shapePointer!.length; i++) { + _addChild(widget.shapePointer![i], null, null); + } } return _radialGaugeWidgets; } void _addChild(Widget child, Animation? animation, AnimationController? controller) { - _radialGaugeWidgets.add( - RadialGaugeState(rGauge: widget, track: widget.track, child: child)); + _radialGaugeWidgets.add(RadialGaugeState( + rGauge: widget, + track: widget.track, + child: child, + )); } @override @@ -144,7 +222,11 @@ class RRadialGauge extends MultiChildRenderObjectWidget { RenderObject createRenderObject(BuildContext context) { return RenderRadialGauge( needlePointer: rGauge.needlePointer, + xCenterCoordinate: rGauge.xCenterCoordinate, + yCenterCoordinate: rGauge.yCenterCoordinate, valueBar: rGauge.valueBar, + shapePointer: rGauge.shapePointer, + radiusFactor: rGauge.radiusFactor, track: rGauge.track, ); } @@ -154,6 +236,10 @@ class RRadialGauge extends MultiChildRenderObjectWidget { BuildContext context, covariant RenderRadialGauge renderObject) { renderObject ..setTrack = rGauge.track + ..setValueBar = rGauge.valueBar + ..setShapePointer = rGauge.shapePointer + ..setXCenterCoordinate = rGauge.xCenterCoordinate + ..setYCenterCoordinate = rGauge.yCenterCoordinate ..setNeedlePointer = rGauge.needlePointer!; } } @@ -166,12 +252,59 @@ class RenderRadialGauge extends RenderBox RenderRadialGauge({ Key? key, required RadialTrack track, - required NeedlePointer? needlePointer, - required RadialValueBar? valueBar, + required double radiusFactor, + required double xCenterCoordinate, + required double yCenterCoordinate, + required List? needlePointer, + required List? shapePointer, + required List? valueBar, }) : _track = track, _needlePointer = needlePointer, + _valueBar = valueBar, + _xCenterCoordinate = xCenterCoordinate, + _radiusFactor = radiusFactor, + _shapePointer = shapePointer, + _yCenterCoordinate = yCenterCoordinate, super(); + double gaugeHeight = 0; + double gaugeWidth = 0; + double valueBarTopHeight = 0, valueBarWidth = 0; + + List? get getShapePointer => _shapePointer; + List? _shapePointer; + + set setShapePointer(List? shapePointer) { + if (_shapePointer == shapePointer) return; + _shapePointer = shapePointer; + + markNeedsPaint(); + } + + double get getRadiusFactor => _radiusFactor; + double _radiusFactor; + set setRadiusFactor(double radiusFactor) { + if (_radiusFactor == radiusFactor) return; + _radiusFactor = radiusFactor; + markNeedsPaint(); + } + + double get xCenterCoordinate => _xCenterCoordinate; + double _xCenterCoordinate; + set setXCenterCoordinate(double xCenterCoordinate) { + if (_xCenterCoordinate == xCenterCoordinate) return; + _xCenterCoordinate = xCenterCoordinate; + markNeedsPaint(); + } + + double get yCenterCoordinate => _yCenterCoordinate; + double _yCenterCoordinate; + set setYCenterCoordinate(double yCenterCoordinate) { + if (_yCenterCoordinate == yCenterCoordinate) return; + _yCenterCoordinate = yCenterCoordinate; + markNeedsPaint(); + } + RadialTrack get getTrack => _track; RadialTrack _track; set setTrack(RadialTrack track) { @@ -180,74 +313,102 @@ class RenderRadialGauge extends RenderBox markNeedsPaint(); } - RadialValueBar get getValueBar => _valueBar!; - RadialValueBar? _valueBar; - set setValueBar(RadialValueBar valueBar) { + List get getValueBar => _valueBar!; + List? _valueBar; + set setValueBar(List? valueBar) { if (_valueBar == valueBar) return; _valueBar = valueBar; markNeedsPaint(); } - NeedlePointer get getNeedlePointer => _needlePointer!; - NeedlePointer? _needlePointer; - set setNeedlePointer(NeedlePointer needlePointer) { + List get getNeedlePointer => _needlePointer!; + List? _needlePointer; + set setNeedlePointer(List? needlePointer) { if (_needlePointer == needlePointer) return; _needlePointer = needlePointer; markNeedsPaint(); } + late double? extraH; @override void performLayout() { size = computeDryLayout(constraints); + RenderBox? child = firstChild; + while (child != null) { final MultiChildLayoutParentData childParentData = child.parentData as MultiChildLayoutParentData; - if (child is RenderRadialGaugeContainer) { - childParentData.offset = Offset(size.width, size.height); + if (child is RenderRadialValueBar) { + childParentData.offset = Offset( + size.width * xCenterCoordinate, size.height * yCenterCoordinate); + extraH = (child.getRadialOffset); final childConstraints = BoxConstraints( maxWidth: size.width, maxHeight: size.height, ); child.layout(childConstraints, parentUsesSize: true); - } + } else if (child is RenderRadialGaugeContainer) { + childParentData.offset = Offset((size.width * xCenterCoordinate), + (size.height * yCenterCoordinate)); - if (child is RenderNeedlePointer) { - childParentData.offset = Offset( - size.width / 2 - (child.getTailRadius / 2), - (size.height / 2) - (child.getTailRadius / 2)); final childConstraints = BoxConstraints( - maxWidth: child.getTailRadius, - maxHeight: child.getTailRadius, + maxWidth: size.width, + maxHeight: size.height, ); + child.layout(childConstraints, parentUsesSize: true); - } else if (child is RenderRadialValueBar) { - childParentData.offset = Offset(size.width / 2, size.height / 2); + } else if (child is RenderNeedlePointer) { + childParentData.offset = Offset( + size.width * xCenterCoordinate, size.height * yCenterCoordinate); final childConstraints = BoxConstraints( - maxWidth: size.width, - maxHeight: size.height, + maxWidth: size.shortestSide - getTrack.thickness, + maxHeight: size.shortestSide - getTrack.thickness, ); child.layout(childConstraints, parentUsesSize: true); + } else if (child is RenderRadialShapePointer) { + childParentData.offset = Offset( + size.width * xCenterCoordinate, size.height * yCenterCoordinate); + child.layout(constraints, parentUsesSize: true); } else { - childParentData.offset = Offset.zero; + childParentData.offset = + Offset(((size.width) / 2), ((size.height) / 2)); } child = childParentData.nextSibling; } - - // if (children.contains(RenderNeedlePointer)) { - // print("NeedlePointer"); - // } } + late double kheight; + late double kwidth; + double kDefaultRadialGaugeSize = 350.0; + @override Size computeDryLayout(BoxConstraints constraints) { - final double actualWidth = constraints.maxWidth; - final double actualHeight = constraints.maxHeight; + final double actualHeight = constraints.hasBoundedHeight + ? constraints.maxHeight + : kDefaultRadialGaugeSize; + final double actualWidth = constraints.hasBoundedWidth + ? constraints.maxWidth + : kDefaultRadialGaugeSize; + + kheight = actualHeight; + kwidth = actualWidth; + + Size s = Size(actualWidth, actualHeight); + + return constraints.constrain(s); + } + + getRadialGaugeContainerSize() { + Offset c = Offset(kheight / 2, kwidth / 2); + + final Rect rect = + Rect.fromCenter(center: c, width: kwidth, height: kheight); - return constraints.constrain(Size(actualWidth, actualHeight)); + return rect.size; } @override @@ -258,8 +419,9 @@ class RenderRadialGauge extends RenderBox } @override - bool hitTest(BoxHitTestResult result, {required Offset position}) { - return false; + bool hitTestChildren(BoxHitTestResult result, {required Offset position}) { + final bool isHit = super.defaultHitTestChildren(result, position: position); + return isHit; } @override diff --git a/lib/src/radial_gauge/radial_gauge_container.dart b/lib/src/radial_gauge/radial_gauge_container.dart index e2968645..c876ebcc 100644 --- a/lib/src/radial_gauge/radial_gauge_container.dart +++ b/lib/src/radial_gauge/radial_gauge_container.dart @@ -56,64 +56,29 @@ class RenderRadialGaugeContainer extends RenderBox { size = Size(constraints.maxWidth, constraints.maxHeight); } - @override - void paint(PaintingContext context, Offset offset) { - final canvas = context.canvas; - + void paintRulersAndLabels( + Canvas canvas, + double numParts, + double startAngle, + double partAngle, + double radius, + double thickness, + double rulerLength, + Offset center, + ) { + // Primary Ruler Paint final Paint primaryRulerPaint = Paint() ..color = getRadialGauge.track.trackStyle.primaryRulerColor! ..strokeWidth = getRadialGauge.track.trackStyle.primaryRulersWidth! ..style = PaintingStyle.stroke; - double startAngle = getRadialGauge.track.startAngle * (pi / 180); - double endAngle = getRadialGauge.track.endAngle * (pi / 180); - if (startAngle > endAngle) { - double temp = startAngle; - startAngle = endAngle; - endAngle = temp; - } - int calculateNumOfDivisions(int steps, double start, double end) { - double range = end - start.toDouble(); - int numOfDivisions = range ~/ steps; - - return numOfDivisions; - } - - var thickness = getRadialGauge.track.thickness; - double shortestSide = size.shortestSide; - - double rulerLength = - getRadialGauge.track.trackStyle.primaryRulersHeight ?? 10; - double arcLength = endAngle - startAngle; // length of the arc in radians - double numParts = calculateNumOfDivisions(getRadialGauge.track.steps, - getRadialGauge.track.start, getRadialGauge.track.end) - .toDouble(); - // .toDouble(); // number of parts to divide the arc into - double partAngle = arcLength / numParts; // angle of each part in radians - double radius = shortestSide / 2 - thickness; // radius of the arc - final center = offset + size.center(Offset.zero); - - // Rect for Arc - Rect c = Rect.fromCircle(center: center, radius: radius); - final Paint containerPaint = Paint() - ..color = getRadialGauge.track.color - ..strokeCap = StrokeCap.round - ..strokeWidth = thickness + // Secondary Ruler Paint + final Paint secondaryRulerPaint = Paint() + ..color = getRadialGauge.track.trackStyle.secondaryRulerColor! + ..strokeWidth = getRadialGauge.track.trackStyle.secondaryRulersWidth! ..style = PaintingStyle.stroke; - // Gradient - if (getRadialGauge.track.gradient != null) { - LinearGradient gradient = getRadialGauge.track.gradient!; - containerPaint.shader = gradient.createShader(c); - } - - // Drawing The Arc - if (!getRadialGauge.track.hideTrack) { - canvas.drawArc(c, startAngle, arcLength, false, containerPaint); - } - - Color textColor = Colors.black; - + // Loop to draw the Rulers and Labels for (int i = 0; i <= numParts; i++) { final double angle = startAngle + i * partAngle; // angle of the current part @@ -127,22 +92,21 @@ class RenderRadialGaugeContainer extends RenderBox { (radius - rulerLength - 20 - thickness) * cos(angle), (radius - rulerLength - 20 - thickness) * sin(angle)); - var numSecondaryRulers = + var secondaryRulerInterval = getRadialGauge.track.trackStyle.secondaryRulerPerInterval ?? 1; var secondaryRulerLength = getRadialGauge.track.trackStyle.secondaryRulersHeight ?? 5; - var secondaryRulerWidth = - getRadialGauge.track.trackStyle.secondaryRulersWidth ?? 1; - Color secondaryRulerColor = - getRadialGauge.track.trackStyle.secondaryRulerColor ?? Colors.grey; - final double secondaryRulerAngle = partAngle / (numSecondaryRulers + 1); + final double secondaryRulerAngle = + partAngle / (secondaryRulerInterval + 1); // Draw the primary Ruler - canvas.drawLine( - center + startPoint, center + endPoint, primaryRulerPaint); + if (getRadialGauge.track.trackStyle.showPrimaryRulers) { + canvas.drawLine( + center + startPoint, center + endPoint, primaryRulerPaint); + } if (i != numParts) { - for (int j = 1; j <= numSecondaryRulers; j++) { + for (int j = 1; j <= secondaryRulerInterval; j++) { final double secondaryAngle = angle + (j * secondaryRulerAngle); final Offset secondaryStartPoint = Offset( (radius - thickness) * cos(secondaryAngle), @@ -154,16 +118,18 @@ class RenderRadialGaugeContainer extends RenderBox { ((radius - thickness) - secondaryRulerLength) * sin(secondaryAngle)); - canvas.drawLine( + // Draw the secondary Ruler + if (getRadialGauge.track.trackStyle.showSecondaryRulers) { + canvas.drawLine( center + secondaryStartPoint, center + secondaryEndPoint, - Paint() - ..color = secondaryRulerColor - ..strokeWidth = secondaryRulerWidth); + secondaryRulerPaint, + ); + } } } - //! DRAW Primary LABEL + //* DRAW LABELS final TextPainter textPainter = TextPainter(textDirection: TextDirection.ltr); const String labelFormat = '%d'; @@ -184,7 +150,7 @@ class RenderRadialGaugeContainer extends RenderBox { double exactValue = start + double.parse(((l / range) * valueRange).toStringAsFixed(2)); - + Color textColor = Colors.black; textPainter.text = TextSpan( text: exactValue.toString(), style: TextStyle(color: textColor, fontWeight: FontWeight.bold)); @@ -193,9 +159,75 @@ class RenderRadialGaugeContainer extends RenderBox { final Offset labelOffset = Offset( (labelEndPoint.dx + center.dx) - textPainter.width / 2, (labelEndPoint.dy + center.dy) - textPainter.height / 2); - // if (getRadialGauge.track.hideStartLabel && i == 0) { - textPainter.paint(canvas, labelOffset); - // } + if (getRadialGauge.track.trackStyle.showLabel!) { + textPainter.paint(canvas, labelOffset); + } + } + } + + int calculateNumOfDivisions(int steps, double start, double end) { + double range = end - start.toDouble(); + int numOfDivisions = range ~/ steps; + + return numOfDivisions; + } + + @override + void paint(PaintingContext context, Offset offset) { + final canvas = context.canvas; + + // Angles in radians + double startAngle = (getRadialGauge.track.startAngle - 180) * (pi / 180); + double endAngle = (getRadialGauge.track.endAngle - 180) * (pi / 180); + if (startAngle > endAngle) { + double temp = startAngle; + startAngle = endAngle; + endAngle = temp; } + + var thickness = getRadialGauge.track.thickness; + double shortestSide = size.shortestSide; + + double rulerLength = + getRadialGauge.track.trackStyle.primaryRulersHeight ?? 10; + double arcLength = endAngle - startAngle; // length of the arc in radians + + double numParts = calculateNumOfDivisions( + getRadialGauge.track.steps, + getRadialGauge.track.start, + getRadialGauge.track.end, + ).toDouble(); + + // double radialOffset = getRadialGauge.valueBar!.first.radialOffset; + + double partAngle = arcLength / numParts; // angle of each part in radians + double radius = (shortestSide / 2 - thickness) * + getRadialGauge.radiusFactor; // radius of the arc + + final center = offset; + + final Paint containerPaint = Paint() + ..color = getRadialGauge.track.color + ..strokeCap = StrokeCap.round + ..strokeWidth = thickness + ..style = PaintingStyle.stroke; + + // Rect for Arc + Rect rectForArc = Rect.fromCircle(center: center, radius: radius); + + // Gradient + if (getRadialGauge.track.gradient != null) { + LinearGradient gradient = getRadialGauge.track.gradient!; + containerPaint.shader = gradient.createShader(rectForArc); + } + + // Drawing The Arc + if (!getRadialGauge.track.hideTrack) { + canvas.drawArc(rectForArc, startAngle, arcLength, false, containerPaint); + } + + // Drawing the Rulers and Labels + paintRulersAndLabels(canvas, numParts, startAngle, partAngle, radius, + thickness, rulerLength, center); } } diff --git a/lib/src/radial_gauge/radial_track.dart b/lib/src/radial_gauge/radial_track.dart index 913abb7a..f3795807 100644 --- a/lib/src/radial_gauge/radial_track.dart +++ b/lib/src/radial_gauge/radial_track.dart @@ -1,24 +1,42 @@ import 'package:flutter/material.dart'; import 'package:geekyants_flutter_gauges/src/base/base_ruler_style.dart'; +/// The [RadialTrack] is used to set the track of the Radial Gauge. +/// +/// The [start] property is used to set the start value of the Radial Gauge. +/// The [end] property is used to set the end value of the Radial Gauge. +/// The [startAngle] property is used to set the start angle of the Radial Gauge. +/// The [endAngle] property is used to set the end angle of the Radial Gauge. +/// +/// ``` dart +/// RadialGauge( +/// track: RadialTrack( +/// start: 0, +/// end: 100, +/// startAngle: 0, +/// endAngle: 360, +/// ), +/// ), +/// ``` +/// class RadialTrack { const RadialTrack({ Key? key, required this.start, required this.end, - this.startAngle = 140, + this.startAngle = -30, this.steps = 10, - this.endAngle = 400, + this.endAngle = 210, this.color = Colors.grey, - this.hideStartLabel = false, + this.hideLabels = false, this.hideTrack = false, this.thickness = 10, this.trackStyle = const TrackStyle( - primaryRulersHeight: 20, + primaryRulersHeight: 10, primaryRulerColor: Colors.black54, secondaryRulerColor: Colors.grey, inverseRulers: false, - secondaryRulersHeight: 10, + secondaryRulersHeight: 5, primaryRulersWidth: 1.0, secondaryRulerPerInterval: 1.0, ), @@ -64,9 +82,9 @@ class RadialTrack { final Color color; /// - /// The [hideStartLabel] property is used to hide the start label of the Radial Gauge. + /// The [hideLabels] property is used to hide the start label of the Radial Gauge. /// - final bool hideStartLabel; + final bool hideLabels; /// /// The [thickness] property is used to set the thickness of the Radial Gauge. @@ -79,6 +97,7 @@ class RadialTrack { final bool hideTrack; /// + /// The [trackStyle] property is used to customize the track of the Radial Gauge. /// final TrackStyle trackStyle; } diff --git a/lib/src/radial_gauge/shape_pointer/radial_shape_pointer.dart b/lib/src/radial_gauge/shape_pointer/radial_shape_pointer.dart new file mode 100644 index 00000000..fbc39a0b --- /dev/null +++ b/lib/src/radial_gauge/shape_pointer/radial_shape_pointer.dart @@ -0,0 +1,187 @@ +import 'dart:math'; + +import 'package:flutter/material.dart'; +import 'package:geekyants_flutter_gauges/geekyants_flutter_gauges.dart'; +import 'package:geekyants_flutter_gauges/src/radial_gauge/radial_gauge_state.dart'; + +class RadialShapePointer extends LeafRenderObjectWidget { + const RadialShapePointer({ + super.key, + required this.value, + this.color = Colors.red, + this.height = 10, + this.width = 10, + this.shape = PointerShape.triangle, + }); + + final double value; + final Color color; + final double height; + final double width; + final PointerShape shape; + + @override + RenderObject createRenderObject(BuildContext context) { + final RadialGaugeState scope = RadialGaugeState.of(context); + + return RenderRadialShapePointer( + value: value, + color: color, + height: height, + width: width, + shape: shape, + radialGauge: scope.rGauge, + ); + } + + @override + void updateRenderObject( + BuildContext context, RenderRadialShapePointer renderObject) { + final RadialGaugeState scope = RadialGaugeState.of(context); + renderObject + ..setValue = value + ..setRadialGauge = scope.rGauge + ..setColor = color + ..setHeight = height + ..setWidth = width + ..setShape = shape; + } +} + +class RenderRadialShapePointer extends RenderBox { + RenderRadialShapePointer({ + required double value, + required Color color, + required double height, + required double width, + required PointerShape shape, + required RadialGauge radialGauge, + }) : _value = value, + _color = color, + _height = height, + _width = width, + _shape = shape, + _radialGauge = radialGauge; + + double _value; + Color _color; + double _height; + double _width; + PointerShape _shape; + RadialGauge _radialGauge; + + @override + Size computeDryLayout(BoxConstraints constraints) { + return constraints.constrain(constraints.biggest); + } + + @override + bool hitTestSelf(Offset position) { + return true; + } + + @override + void performLayout() { + size = Size(constraints.maxWidth, constraints.maxHeight); + } + + set setValue(double value) { + if (_value == value) { + return; + } + _value = value; + markNeedsPaint(); + } + + set setColor(Color color) { + if (_color == color) { + return; + } + _color = color; + markNeedsPaint(); + } + + set setHeight(double height) { + if (_height == height) { + return; + } + _height = height; + markNeedsPaint(); + } + + set setWidth(double width) { + if (_width == width) { + return; + } + _width = width; + markNeedsPaint(); + } + + set setShape(PointerShape shape) { + if (_shape == shape) { + return; + } + _shape = shape; + markNeedsPaint(); + } + + set setRadialGauge(RadialGauge radialGauge) { + if (_radialGauge == radialGauge) { + return; + } + _radialGauge = radialGauge; + markNeedsPaint(); + } + + @override + void paint(PaintingContext context, Offset offset) { + final canvas = context.canvas; + + double gaugeStart = _radialGauge.track.start; + double gaugeEnd = _radialGauge.track.end; + + final center = offset; + double value = calculateValueAngle(_value, gaugeStart, gaugeEnd); + double startAngle = (_radialGauge.track.startAngle - 180) * (pi / 180); + double endAngle = (_radialGauge.track.endAngle - 180) * (pi / 180); + + final double angle = startAngle + (value / 100) * (endAngle - startAngle); + + double needleLength = 30; + double needleWidth = 10; + final pointerPath = Path(); + // double pointerOffset = 430 + 0; + double pointerOffset = + (size.shortestSide / 2 - _radialGauge.track.thickness) * + _radialGauge.radiusFactor; + // needleEndY = center.dy + 250 * sin(angle); + double pointerEndX = center.dx + pointerOffset * cos(angle); + double pointerEndY = center.dy + pointerOffset * sin(angle); + // needleEndX = center.dx + 250 * cos(angle); + // // needleEndX = center.dx + getTailRadius / 2 + needleMultiplier * cos(angle); + pointerPath.moveTo(pointerEndX, pointerEndY); + pointerPath.lineTo( + pointerEndX - needleWidth * cos(angle + pi / 2), + pointerEndY - needleWidth * sin(angle + pi / 2), + ); + pointerPath.lineTo( + pointerEndX - (needleLength - needleWidth) * cos(angle), + pointerEndY - (needleLength - needleWidth) * sin(angle), + ); + pointerPath.lineTo( + pointerEndX + needleWidth * cos(angle + pi / 2), + pointerEndY + needleWidth * sin(angle + pi / 2), + ); + pointerPath.close(); + + canvas.drawCircle( + Offset(pointerEndX, pointerEndY), _width, Paint()..color = _color); + // canvas.drawPath(pointerPath, Paint()..color = Colors.red); + } + + double calculateValueAngle(double value, double gaugeStart, double gaugeEnd) { + double newValue = (value - gaugeStart) / (gaugeEnd - gaugeStart) * 100; + + return newValue; + } +} diff --git a/lib/src/radial_gauge/valuebar/radial_value_bar.dart b/lib/src/radial_gauge/valuebar/radial_value_bar.dart index 318dcfa5..4198c806 100644 --- a/lib/src/radial_gauge/valuebar/radial_value_bar.dart +++ b/lib/src/radial_gauge/valuebar/radial_value_bar.dart @@ -22,17 +22,93 @@ class RadialValueBar extends LeafRenderObjectWidget { required this.value, this.color = Colors.blue, this.valueBarThickness = 10, - this.borderRadius = 0, this.gradient, this.radialOffset = 0, }) : super(key: key); + /// [value] denotes the value of the value bar. + /// + ///```dart + /// RadialGauge( + /// valueBar: [ + /// RadialValueBar( + /// value: 50, + /// ), + /// ], + /// track: RadialTrack( + /// start: 0, + /// end: 100, + /// ), + /// ), + /// ``` + /// + final double value; + /// [color] denotes the color of the value bar. + /// + ///```dart + /// RadialGauge( + /// valueBar: [ + /// RadialValueBar( + /// value: 50, + /// color: Colors.blue + /// ), + /// ], + /// track: RadialTrack( + /// start: 0, + /// end: 100, + /// ), + /// ), + /// ``` + /// final Color color; + + /// [radialOffset] denotes the offset of the value bar. + /// The value bar will be rendered at the given offset. + /// + /// ```dart + /// RadialGauge( + /// valueBar: [ + /// RadialValueBar( + /// value: 50, + /// color: Colors.blue + /// radialOffset: 10, + /// ), + /// ], + /// track: RadialTrack( + /// start: 0, + /// end: 100, + /// + /// ), + /// ), + /// ``` + /// final double radialOffset; + + /// [valueBarThickness] denotes the thickness of the value bar. + /// The value bar will be rendered at the given thickness. + /// + /// ```dart + /// RadialGauge( + /// valueBar: [ + /// RadialValueBar( + /// value: 50, + /// color: Colors.blue + /// valueBarThickness: 20, + /// ), + /// ], + /// track: RadialTrack( + /// start: 0, + /// end: 100, + /// + /// ), + /// ), + /// ``` final double valueBarThickness; - final double borderRadius; + + /// [gradient] denotes the gradient of the value bar. + /// final LinearGradient? gradient; @override @@ -45,7 +121,6 @@ class RadialValueBar extends LeafRenderObjectWidget { gradient: gradient ?? LinearGradient(colors: [color, color]), radialOffset: radialOffset, valueBarThickness: valueBarThickness, - borderRadius: borderRadius, radialGauge: scope.rGauge, ); } @@ -60,7 +135,6 @@ class RadialValueBar extends LeafRenderObjectWidget { ..setRadialOffset = radialOffset ..setLinearGradient = gradient ?? LinearGradient(colors: [color, color]) ..setValueBarThickness = valueBarThickness - ..setBorderRadius = borderRadius ..setRadialGauge = scope.rGauge; } } diff --git a/lib/src/radial_gauge/valuebar/radial_value_bar_painter.dart b/lib/src/radial_gauge/valuebar/radial_value_bar_painter.dart index 616d88d2..3b5dbc48 100644 --- a/lib/src/radial_gauge/valuebar/radial_value_bar_painter.dart +++ b/lib/src/radial_gauge/valuebar/radial_value_bar_painter.dart @@ -1,8 +1,5 @@ import 'dart:math'; - -import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; - import '../../../geekyants_flutter_gauges.dart'; class RenderRadialValueBar extends RenderBox { @@ -12,7 +9,6 @@ class RenderRadialValueBar extends RenderBox { required Color color, required LinearGradient? gradient, required double valueBarThickness, - required double borderRadius, required RadialGauge radialGauge, required double radialOffset, }) : _value = value, @@ -21,7 +17,6 @@ class RenderRadialValueBar extends RenderBox { _radialOffset = radialOffset, _radialGauge = radialGauge, _valueBarThickness = valueBarThickness, - _borderRadius = borderRadius, super(); RadialGauge get getRadialGauge => _radialGauge!; @@ -64,14 +59,6 @@ class RenderRadialValueBar extends RenderBox { markNeedsPaint(); } - double get getBorderRadius => _borderRadius; - double _borderRadius; - set setBorderRadius(double borderRadius) { - if (_borderRadius == borderRadius) return; - _borderRadius = borderRadius; - markNeedsPaint(); - } - LinearGradient get getLinearGradient => _gradient; LinearGradient _gradient; set setLinearGradient(LinearGradient linearGradient) { @@ -98,9 +85,12 @@ class RenderRadialValueBar extends RenderBox { @override void paint(PaintingContext context, Offset offset) { final Canvas canvas = context.canvas; + final center = offset; + final LinearGradient gradient = getLinearGradient; - double startAngle = getRadialGauge.track.startAngle * (pi / 180); - double endAngle = getRadialGauge.track.endAngle * (pi / 180); + // Angles in radians + double startAngle = (getRadialGauge.track.startAngle - 180) * (pi / 180); + double endAngle = (getRadialGauge.track.endAngle - 180) * (pi / 180); double value = (_value - getRadialGauge.track.start) / (getRadialGauge.track.end - getRadialGauge.track.start) * @@ -108,16 +98,13 @@ class RenderRadialValueBar extends RenderBox { final double angle = startAngle + (value / 100) * (endAngle - startAngle); endAngle = angle; + if (startAngle > endAngle) { final double temp = startAngle; startAngle = endAngle; endAngle = temp; } - final center = offset; - - final LinearGradient gradient = getLinearGradient; - final Paint containerPaint = Paint() ..color = _color ..strokeCap = StrokeCap.round @@ -128,9 +115,11 @@ class RenderRadialValueBar extends RenderBox { double arcLength = endAngle - startAngle; double shortestSide = size.shortestSide; - double radius = shortestSide / 2.0 - - getRadialGauge.track.thickness + - getRadialOffset; // + double radius = + shortestSide / 2.0 - getRadialGauge.track.thickness - getRadialOffset; + // getRadialGauge.track.thickness - + // getRadialOffset - + // getValueBarThickness; // Rect c = Rect.fromCircle(center: center, radius: radius); canvas.drawArc(c, startAngle, arcLength, false, containerPaint); diff --git a/test/gauges_test.dart b/test/gauges_test.dart index 3782d8e0..d6b319cd 100644 --- a/test/gauges_test.dart +++ b/test/gauges_test.dart @@ -14,7 +14,7 @@ void main() { showLinearGaugeContainer: true, gaugeOrientation: GaugeOrientation.horizontal, labelTopMargin: 0.0, - pointers: [ + pointers: const [ Pointer( value: 0, shape: PointerShape.triangle, diff --git a/test/pointers_test/pointer_test_cases.dart b/test/pointers_test/pointer_test_cases.dart index 06ea251e..81c63e1c 100644 --- a/test/pointers_test/pointer_test_cases.dart +++ b/test/pointers_test/pointer_test_cases.dart @@ -4,7 +4,7 @@ import 'package:geekyants_flutter_gauges/geekyants_flutter_gauges.dart'; List valueTests = [ // Circle TestCases { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, value: 0, pointerPosition: PointerPosition.top, @@ -13,7 +13,7 @@ List valueTests = [ 'Do': 'Pointer should be drawn at 0 value with with circle shape', }, { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, value: 50, pointerPosition: PointerPosition.top, @@ -22,7 +22,7 @@ List valueTests = [ 'Do': 'Pointer should be drawn at 0 value with with circle shape', }, { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, value: 100, pointerPosition: PointerPosition.top, @@ -33,7 +33,7 @@ List valueTests = [ // Rectangle TestCases { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, value: 0, pointerPosition: PointerPosition.top, @@ -42,7 +42,7 @@ List valueTests = [ 'Do': 'Pointer should be drawn at 0 value with with rectangle shape', }, { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, value: 50, pointerPosition: PointerPosition.top, @@ -51,7 +51,7 @@ List valueTests = [ 'Do': 'Pointer should be drawn at 0 value with with rectangle shape', }, { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, value: 100, pointerPosition: PointerPosition.top, @@ -62,7 +62,7 @@ List valueTests = [ //Triangle TestCases { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, value: 0, pointerPosition: PointerPosition.top, @@ -71,7 +71,7 @@ List valueTests = [ 'Do': 'Pointer should be drawn at 0 value with with triangle shape', }, { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, value: 50, pointerPosition: PointerPosition.top, @@ -80,7 +80,7 @@ List valueTests = [ 'Do': 'Pointer should be drawn at 0 value with with triangle shape', }, { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, value: 100, pointerPosition: PointerPosition.top, @@ -91,7 +91,7 @@ List valueTests = [ //Diamond TestCases { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, value: 0, pointerPosition: PointerPosition.top, @@ -100,7 +100,7 @@ List valueTests = [ 'Do': 'Pointer should be drawn at 0 value with with diamond shape', }, { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, value: 50, pointerPosition: PointerPosition.top, @@ -109,7 +109,7 @@ List valueTests = [ 'Do': 'Pointer should be drawn at 0 value with with diamond shape', }, { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, value: 100, pointerPosition: PointerPosition.top, @@ -122,7 +122,7 @@ List valueTests = [ List positionTestCases = [ { // Circle TestCases with PointerPosition - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, value: 50, pointerPosition: PointerPosition.top, @@ -132,7 +132,7 @@ List positionTestCases = [ 'Pointer should be drawn at 50 value with with Circle shape and pointerPosition.top', }, { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, value: 50, pointerPosition: PointerPosition.center, @@ -142,7 +142,7 @@ List positionTestCases = [ 'Pointer should be drawn at 50 value with with Circle shape and pointerPosition.center', }, { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, value: 50, pointerPosition: PointerPosition.bottom, @@ -154,7 +154,7 @@ List positionTestCases = [ // Rectangle TestCases with PointerPosition { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, value: 50, pointerPosition: PointerPosition.top, @@ -164,7 +164,7 @@ List positionTestCases = [ 'Pointer should be drawn at 50 value with with Rectangle shape and pointerPosition.top', }, { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, value: 50, pointerPosition: PointerPosition.center, @@ -174,7 +174,7 @@ List positionTestCases = [ 'Pointer should be drawn at 50 value with with Rectangle shape and pointerPosition.center', }, { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, value: 50, pointerPosition: PointerPosition.bottom, @@ -186,7 +186,7 @@ List positionTestCases = [ // Triangle TestCases with PointerPosition { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, value: 50, pointerPosition: PointerPosition.top, @@ -196,7 +196,7 @@ List positionTestCases = [ 'Pointer should be drawn at 50 value with with Triangle shape and pointerPosition.top', }, { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, value: 50, pointerPosition: PointerPosition.center, @@ -206,7 +206,7 @@ List positionTestCases = [ 'Pointer should be drawn at 50 value with with Triangle shape and pointerPosition.center', }, { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, value: 50, pointerPosition: PointerPosition.bottom, @@ -218,7 +218,7 @@ List positionTestCases = [ // Diamond TestCases with PointerPosition { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, value: 50, pointerPosition: PointerPosition.top, @@ -228,7 +228,7 @@ List positionTestCases = [ 'Pointer should be drawn at 50 value with with Diamond shape and pointerPosition.top', }, { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, value: 50, pointerPosition: PointerPosition.center, @@ -238,7 +238,7 @@ List positionTestCases = [ 'Pointer should be drawn at 50 value with with Diamond shape and pointerPosition.center', }, { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, value: 50, pointerPosition: PointerPosition.bottom, @@ -253,7 +253,7 @@ List valueTestCasesVertical = [ // Circle TestCases { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, value: 0, pointerPosition: PointerPosition.left, @@ -263,7 +263,7 @@ List valueTestCasesVertical = [ }, { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, value: 50, pointerPosition: PointerPosition.left, @@ -273,7 +273,7 @@ List valueTestCasesVertical = [ }, { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, value: 100, pointerPosition: PointerPosition.left, @@ -285,7 +285,7 @@ List valueTestCasesVertical = [ // Rectangle TestCases { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, value: 0, pointerPosition: PointerPosition.left, @@ -295,7 +295,7 @@ List valueTestCasesVertical = [ }, { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, value: 50, pointerPosition: PointerPosition.left, @@ -305,7 +305,7 @@ List valueTestCasesVertical = [ }, { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, value: 100, pointerPosition: PointerPosition.left, @@ -317,7 +317,7 @@ List valueTestCasesVertical = [ //Triangle TestCases { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, value: 0, pointerPosition: PointerPosition.left, @@ -327,7 +327,7 @@ List valueTestCasesVertical = [ }, { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, value: 50, pointerPosition: PointerPosition.left, @@ -337,7 +337,7 @@ List valueTestCasesVertical = [ }, { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, value: 100, pointerPosition: PointerPosition.left, @@ -349,7 +349,7 @@ List valueTestCasesVertical = [ //Diamond TestCases { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, value: 0, pointerPosition: PointerPosition.left, @@ -359,7 +359,7 @@ List valueTestCasesVertical = [ }, { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, value: 50, pointerPosition: PointerPosition.left, @@ -369,7 +369,7 @@ List valueTestCasesVertical = [ }, { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, value: 100, pointerPosition: PointerPosition.left, @@ -383,7 +383,7 @@ List edgeCases = [ //Cirlce TestCases { 'gaugeOrientation': GaugeOrientation.horizontal, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, width: 150, value: 0, @@ -394,7 +394,7 @@ List edgeCases = [ }, { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, width: 150, value: 100, @@ -406,7 +406,7 @@ List edgeCases = [ //Rectangle TestCases { 'gaugeOrientation': GaugeOrientation.horizontal, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, width: 150, height: 10, @@ -418,7 +418,7 @@ List edgeCases = [ }, { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, width: 150, height: 10, @@ -431,7 +431,7 @@ List edgeCases = [ }, { 'gaugeOrientation': GaugeOrientation.horizontal, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, width: 10, height: 150, @@ -443,7 +443,7 @@ List edgeCases = [ }, { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, width: 10, height: 150, @@ -458,7 +458,7 @@ List edgeCases = [ // Triangle TestCases { 'gaugeOrientation': GaugeOrientation.horizontal, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, width: 150, height: 20, @@ -471,7 +471,7 @@ List edgeCases = [ }, { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, width: 150, height: 20, @@ -484,7 +484,7 @@ List edgeCases = [ }, { 'gaugeOrientation': GaugeOrientation.horizontal, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, width: 20, height: 150, @@ -497,7 +497,7 @@ List edgeCases = [ }, { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, width: 20, height: 150, @@ -512,7 +512,7 @@ List edgeCases = [ //Diamond TestCases { 'gaugeOrientation': GaugeOrientation.horizontal, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, width: 150, height: 20, @@ -525,7 +525,7 @@ List edgeCases = [ }, { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, width: 150, height: 20, @@ -538,7 +538,7 @@ List edgeCases = [ }, { 'gaugeOrientation': GaugeOrientation.horizontal, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, width: 20, height: 150, @@ -551,7 +551,7 @@ List edgeCases = [ }, { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, width: 20, height: 150, @@ -566,7 +566,7 @@ List edgeCases = [ // Edge Cases Circle { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, width: 20, value: 100, @@ -578,7 +578,7 @@ List edgeCases = [ }, { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, width: 20, value: 100, @@ -592,7 +592,7 @@ List edgeCases = [ // Edge Cases Rectangle { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, width: 20, value: 100, @@ -604,7 +604,7 @@ List edgeCases = [ }, { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, width: 20, value: 100, @@ -618,7 +618,7 @@ List edgeCases = [ // Edge Cases Triangle { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, width: 20, value: 100, @@ -630,7 +630,7 @@ List edgeCases = [ }, { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, width: 20, value: 100, @@ -644,7 +644,7 @@ List edgeCases = [ // Edge Cases Diamond { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, width: 20, value: 100, @@ -656,7 +656,7 @@ List edgeCases = [ }, { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, width: 20, value: 100, @@ -672,7 +672,7 @@ List showLabelTests = [ { 'gaugeOrientation': GaugeOrientation.horizontal, 'showLabel': false, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, color: Colors.blue, value: 0, @@ -686,7 +686,7 @@ List showLabelTests = [ { 'gaugeOrientation': GaugeOrientation.horizontal, 'showLabel': false, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, color: Colors.blue, value: 100, @@ -700,7 +700,7 @@ List showLabelTests = [ { 'showLabel': false, 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( height: 50, width: 50, shape: PointerShape.triangle, @@ -714,7 +714,7 @@ List showLabelTests = [ { 'showLabel': false, 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( height: 50, width: 50, shape: PointerShape.triangle, @@ -731,7 +731,7 @@ List showLabelTests = [ { 'showLabel': false, 'gaugeOrientation': GaugeOrientation.horizontal, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, color: Colors.blue, value: 0, @@ -745,7 +745,7 @@ List showLabelTests = [ { 'showLabel': false, 'gaugeOrientation': GaugeOrientation.horizontal, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, color: Colors.blue, value: 100, @@ -759,7 +759,7 @@ List showLabelTests = [ { 'showLabel': false, 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( height: 30, width: 30, shape: PointerShape.circle, @@ -773,7 +773,7 @@ List showLabelTests = [ { 'showLabel': false, 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( height: 30, width: 30, shape: PointerShape.circle, @@ -789,7 +789,7 @@ List showLabelTests = [ { 'showLabel': false, 'gaugeOrientation': GaugeOrientation.horizontal, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, color: Colors.blue, value: 0, @@ -803,7 +803,7 @@ List showLabelTests = [ { 'showLabel': false, 'gaugeOrientation': GaugeOrientation.horizontal, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, color: Colors.blue, value: 100, @@ -817,7 +817,7 @@ List showLabelTests = [ { 'showLabel': false, 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( height: 30, width: 30, shape: PointerShape.rectangle, @@ -831,7 +831,7 @@ List showLabelTests = [ { 'showLabel': false, 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( height: 30, width: 30, shape: PointerShape.rectangle, @@ -847,7 +847,7 @@ List showLabelTests = [ { 'showLabel': false, 'gaugeOrientation': GaugeOrientation.horizontal, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, color: Colors.blue, value: 0, @@ -861,7 +861,7 @@ List showLabelTests = [ { 'showLabel': false, 'gaugeOrientation': GaugeOrientation.horizontal, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, color: Colors.blue, value: 100, @@ -875,7 +875,7 @@ List showLabelTests = [ { 'showLabel': false, 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( height: 30, width: 30, shape: PointerShape.diamond, @@ -889,7 +889,7 @@ List showLabelTests = [ { 'showLabel': false, 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( height: 30, width: 30, shape: PointerShape.diamond, @@ -906,7 +906,7 @@ List showLabelTests = [ 'showLabel': false, 'inverse': true, 'gaugeOrientation': GaugeOrientation.horizontal, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, color: Colors.blue, value: 0, @@ -921,7 +921,7 @@ List showLabelTests = [ 'inverse': true, 'showLabel': false, 'gaugeOrientation': GaugeOrientation.horizontal, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, color: Colors.blue, value: 100, @@ -936,7 +936,7 @@ List showLabelTests = [ 'inverse': true, 'showLabel': false, 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( height: 30, width: 30, shape: PointerShape.triangle, @@ -952,7 +952,7 @@ List showLabelTests = [ 'inverse': true, 'showLabel': false, 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( height: 30, width: 30, shape: PointerShape.triangle, @@ -969,7 +969,7 @@ List showLabelTests = [ List colorTests = [ //Circle { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, color: Colors.blue, value: 50, @@ -980,7 +980,7 @@ List colorTests = [ }, // Rectangle { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, color: Colors.blue, value: 50, @@ -991,7 +991,7 @@ List colorTests = [ }, // Triangle { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, color: Colors.blue, value: 50, @@ -1002,7 +1002,7 @@ List colorTests = [ }, // Diamond { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, color: Colors.blue, value: 50, @@ -1016,7 +1016,7 @@ List colorTests = [ List valueLabelTests = [ // For value 50 { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, color: Colors.blue, value: 50, @@ -1032,7 +1032,7 @@ List valueLabelTests = [ }, // For Value 0 { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, color: Colors.blue, value: 0, @@ -1048,7 +1048,7 @@ List valueLabelTests = [ }, //For value 100 { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, color: Colors.blue, value: 100, @@ -1063,7 +1063,7 @@ List valueLabelTests = [ 'Do': 'Should display value label for pointer', }, { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, color: Colors.blue, value: 100, @@ -1084,7 +1084,7 @@ List extendLinearGaugePointerTestsHorizontal = [ //circle center { 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, color: Colors.blue, value: 50, @@ -1095,7 +1095,7 @@ List extendLinearGaugePointerTestsHorizontal = [ }, { 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, color: Colors.blue, value: 0, @@ -1106,7 +1106,7 @@ List extendLinearGaugePointerTestsHorizontal = [ }, { 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, color: Colors.blue, value: 100, @@ -1120,7 +1120,7 @@ List extendLinearGaugePointerTestsHorizontal = [ { 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, color: Colors.blue, value: 50, @@ -1131,7 +1131,7 @@ List extendLinearGaugePointerTestsHorizontal = [ }, { 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, color: Colors.blue, value: 0, @@ -1142,7 +1142,7 @@ List extendLinearGaugePointerTestsHorizontal = [ }, { 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, color: Colors.blue, value: 100, @@ -1156,7 +1156,7 @@ List extendLinearGaugePointerTestsHorizontal = [ { 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, color: Colors.blue, value: 50, @@ -1167,7 +1167,7 @@ List extendLinearGaugePointerTestsHorizontal = [ }, { 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, color: Colors.blue, value: 0, @@ -1178,7 +1178,7 @@ List extendLinearGaugePointerTestsHorizontal = [ }, { 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, color: Colors.blue, value: 100, @@ -1198,7 +1198,7 @@ List extendLinearGaugePointerTestsHorizontal = [ color: Colors.black, ), ), - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, color: Colors.blue, value: 0, @@ -1214,7 +1214,7 @@ List extendLinearGaugePointerTestsHorizontal = [ //triangle with random values and positions { 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, color: Colors.blue, value: 60, @@ -1225,7 +1225,7 @@ List extendLinearGaugePointerTestsHorizontal = [ }, { 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, color: Colors.blue, value: 0, @@ -1236,7 +1236,7 @@ List extendLinearGaugePointerTestsHorizontal = [ }, { 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, color: Colors.blue, value: 100, @@ -1256,7 +1256,7 @@ List extendLinearGaugePointerTestsHorizontal = [ color: Colors.black, ), ), - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, color: Colors.blue, value: 100, @@ -1270,7 +1270,7 @@ List extendLinearGaugePointerTestsHorizontal = [ //diamond with random values and positions { 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, color: Colors.blue, value: 20, @@ -1281,7 +1281,7 @@ List extendLinearGaugePointerTestsHorizontal = [ }, { 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, color: Colors.blue, value: 80, @@ -1302,7 +1302,7 @@ List extendLinearGaugePointerTestsHorizontal = [ color: Colors.black, ), ), - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, color: Colors.blue, value: 80, @@ -1315,7 +1315,7 @@ List extendLinearGaugePointerTestsHorizontal = [ }, { 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, color: Colors.blue, value: 0, @@ -1329,7 +1329,7 @@ List extendLinearGaugePointerTestsHorizontal = [ }, { 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, color: Colors.blue, value: 100, @@ -1340,7 +1340,7 @@ List extendLinearGaugePointerTestsHorizontal = [ }, { 'extendLinearGauge': 10.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, color: Colors.blue, value: 90, @@ -1355,7 +1355,7 @@ List extendLinearGaugePointerTestsHorizontal = [ //rectangle with random values and positions { 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, color: Colors.blue, value: 30, @@ -1366,7 +1366,7 @@ List extendLinearGaugePointerTestsHorizontal = [ }, { 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, color: Colors.blue, value: 0, @@ -1385,7 +1385,7 @@ List extendLinearGaugePointerTestsHorizontal = [ color: Colors.black, ), ), - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, color: Colors.blue, value: 0, @@ -1397,7 +1397,7 @@ List extendLinearGaugePointerTestsHorizontal = [ }, { 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, color: Colors.blue, value: 0, @@ -1410,7 +1410,7 @@ List extendLinearGaugePointerTestsHorizontal = [ }, { 'extendLinearGauge': 50.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, color: Colors.blue, value: 100, @@ -1426,7 +1426,7 @@ List extendLinearGaugePointerTestsVertical = [ { 'gaugeOrientation': GaugeOrientation.vertical, 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, color: Colors.blue, value: 50, @@ -1439,7 +1439,7 @@ List extendLinearGaugePointerTestsVertical = [ { 'extendLinearGauge': 100.0, 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, color: Colors.blue, value: 0, @@ -1462,7 +1462,7 @@ List extendLinearGaugePointerTestsVertical = [ color: Colors.black, ), ), - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, color: Colors.blue, value: 0, @@ -1478,7 +1478,7 @@ List extendLinearGaugePointerTestsVertical = [ { 'extendLinearGauge': 100.0, 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, color: Colors.blue, value: 90, @@ -1494,7 +1494,7 @@ List extendLinearGaugePointerTestsVertical = [ { 'gaugeOrientation': GaugeOrientation.vertical, 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, color: Colors.blue, value: 50, @@ -1507,7 +1507,7 @@ List extendLinearGaugePointerTestsVertical = [ { 'extendLinearGauge': 100.0, 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, color: Colors.blue, value: 0, @@ -1531,7 +1531,7 @@ List extendLinearGaugePointerTestsVertical = [ ), ), 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, color: Colors.blue, value: 0, @@ -1547,7 +1547,7 @@ List extendLinearGaugePointerTestsVertical = [ { 'extendLinearGauge': 100.0, 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, color: Colors.blue, value: 30, @@ -1565,7 +1565,7 @@ List extendLinearGaugePointerTestsVertical = [ { 'gaugeOrientation': GaugeOrientation.vertical, 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, color: Colors.blue, value: 50, @@ -1586,7 +1586,7 @@ List extendLinearGaugePointerTestsVertical = [ ), ), 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, color: Colors.blue, value: 50, @@ -1599,7 +1599,7 @@ List extendLinearGaugePointerTestsVertical = [ { 'extendLinearGauge': 100.0, 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, color: Colors.blue, value: 0, @@ -1615,7 +1615,7 @@ List extendLinearGaugePointerTestsVertical = [ { 'extendLinearGauge': 100.0, 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, color: Colors.blue, value: 30, @@ -1633,7 +1633,7 @@ List extendLinearGaugePointerTestsVertical = [ { 'gaugeOrientation': GaugeOrientation.vertical, 'extendLinearGauge': 100.0, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, color: Colors.blue, value: 50, @@ -1646,7 +1646,7 @@ List extendLinearGaugePointerTestsVertical = [ { 'extendLinearGauge': 100.0, 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, color: Colors.blue, value: 0, @@ -1662,7 +1662,7 @@ List extendLinearGaugePointerTestsVertical = [ { 'extendLinearGauge': 100.0, 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, color: Colors.blue, value: 30, @@ -1686,7 +1686,7 @@ List extendLinearGaugePointerTestsVertical = [ color: Colors.black, ), ), - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, color: Colors.blue, value: 30, @@ -1712,7 +1712,7 @@ List inverseValueTests = [ // Inverse Circle TestCases with PointerPosition { 'inverse': true, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, value: 30, pointerPosition: PointerPosition.top, @@ -1723,7 +1723,7 @@ List inverseValueTests = [ }, { 'inverse': true, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, value: 30, pointerPosition: PointerPosition.center, @@ -1734,7 +1734,7 @@ List inverseValueTests = [ }, { 'inverse': true, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, value: 30, pointerPosition: PointerPosition.bottom, @@ -1747,7 +1747,7 @@ List inverseValueTests = [ // Inverse Rectangle TestCases with PointerPosition { 'inverse': true, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, value: 30, pointerPosition: PointerPosition.top, @@ -1758,7 +1758,7 @@ List inverseValueTests = [ }, { 'inverse': true, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, value: 30, pointerPosition: PointerPosition.center, @@ -1769,7 +1769,7 @@ List inverseValueTests = [ }, { 'inverse': true, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, value: 30, pointerPosition: PointerPosition.bottom, @@ -1782,7 +1782,7 @@ List inverseValueTests = [ // Inverse Triangle TestCases with PointerPosition { 'inverse': true, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, value: 30, pointerPosition: PointerPosition.top, @@ -1793,7 +1793,7 @@ List inverseValueTests = [ }, { 'inverse': true, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, value: 30, pointerPosition: PointerPosition.center, @@ -1804,7 +1804,7 @@ List inverseValueTests = [ }, { 'inverse': true, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, value: 30, pointerPosition: PointerPosition.bottom, @@ -1817,7 +1817,7 @@ List inverseValueTests = [ // Inverse Diamond TestCases with PointerPosition { 'inverse': true, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, value: 30, pointerPosition: PointerPosition.top, @@ -1828,7 +1828,7 @@ List inverseValueTests = [ }, { 'inverse': true, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, value: 30, pointerPosition: PointerPosition.center, @@ -1839,7 +1839,7 @@ List inverseValueTests = [ }, { 'inverse': true, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, value: 30, pointerPosition: PointerPosition.bottom, @@ -1853,7 +1853,7 @@ List inverseValueTests = [ List pointerAlignmentTestsHorizontal = [ // for circle { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, value: 30, pointerPosition: PointerPosition.bottom, @@ -1864,7 +1864,7 @@ List pointerAlignmentTestsHorizontal = [ 'Pointer should be drawn at 30 value with circle shape and pointerPosition.bottom and start alignment', }, { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, value: 30, pointerPosition: PointerPosition.bottom, @@ -1875,7 +1875,7 @@ List pointerAlignmentTestsHorizontal = [ 'Pointer should be drawn at 30 value with circle shape and pointerPosition.bottom and center alignment', }, { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, value: 30, pointerPosition: PointerPosition.bottom, @@ -1886,7 +1886,7 @@ List pointerAlignmentTestsHorizontal = [ 'Pointer should be drawn at 30 value with circle shape and pointerPosition.bottom and end alignment', }, { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, value: 60, width: 30, @@ -1899,7 +1899,7 @@ List pointerAlignmentTestsHorizontal = [ }, { 'inverse': true, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, value: 60, pointerPosition: PointerPosition.top, @@ -1911,7 +1911,7 @@ List pointerAlignmentTestsHorizontal = [ }, { 'inverse': true, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, value: 60, pointerPosition: PointerPosition.top, @@ -1923,7 +1923,7 @@ List pointerAlignmentTestsHorizontal = [ }, // for rectangle { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, value: 30, pointerPosition: PointerPosition.bottom, @@ -1934,7 +1934,7 @@ List pointerAlignmentTestsHorizontal = [ 'Pointer should be drawn at 30 value with rectangle shape and pointerPosition.bottom and start alignment', }, { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, value: 60, width: 30, @@ -1947,7 +1947,7 @@ List pointerAlignmentTestsHorizontal = [ }, { 'inverse': true, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, value: 60, pointerPosition: PointerPosition.top, @@ -1959,7 +1959,7 @@ List pointerAlignmentTestsHorizontal = [ }, //for triangle { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, value: 30, pointerPosition: PointerPosition.bottom, @@ -1970,7 +1970,7 @@ List pointerAlignmentTestsHorizontal = [ 'Pointer should be drawn at 30 value with triangle shape and pointerPosition.bottom and start alignment', }, { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, value: 60, width: 30, @@ -1983,7 +1983,7 @@ List pointerAlignmentTestsHorizontal = [ }, { 'inverse': true, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, value: 60, pointerPosition: PointerPosition.top, @@ -1995,7 +1995,7 @@ List pointerAlignmentTestsHorizontal = [ }, //for diamond { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, value: 30, pointerPosition: PointerPosition.bottom, @@ -2006,7 +2006,7 @@ List pointerAlignmentTestsHorizontal = [ 'Pointer should be drawn at 30 value with diamond shape and pointerPosition.bottom and start alignment', }, { - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, value: 60, width: 30, @@ -2019,7 +2019,7 @@ List pointerAlignmentTestsHorizontal = [ }, { 'inverse': true, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, value: 60, pointerPosition: PointerPosition.top, @@ -2035,7 +2035,7 @@ List pointerAlignmentTestsVertical = [ //for circles { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, value: 20, pointerPosition: PointerPosition.left, @@ -2047,7 +2047,7 @@ List pointerAlignmentTestsVertical = [ }, { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, value: 20, pointerPosition: PointerPosition.left, @@ -2059,7 +2059,7 @@ List pointerAlignmentTestsVertical = [ }, { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, value: 20, pointerPosition: PointerPosition.left, @@ -2071,7 +2071,7 @@ List pointerAlignmentTestsVertical = [ }, { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, value: 60, width: 30, @@ -2086,7 +2086,7 @@ List pointerAlignmentTestsVertical = [ { 'gaugeOrientation': GaugeOrientation.vertical, 'inverse': true, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.circle, value: 60, pointerPosition: PointerPosition.left, @@ -2099,7 +2099,7 @@ List pointerAlignmentTestsVertical = [ { 'gaugeOrientation': GaugeOrientation.vertical, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.rectangle, value: 60, width: 50, @@ -2115,7 +2115,7 @@ List pointerAlignmentTestsVertical = [ { 'gaugeOrientation': GaugeOrientation.vertical, 'inverse': true, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.diamond, value: 90, width: 30, @@ -2131,7 +2131,7 @@ List pointerAlignmentTestsVertical = [ { 'gaugeOrientation': GaugeOrientation.vertical, 'inverse': true, - 'pointer': Pointer( + 'pointer': const Pointer( shape: PointerShape.triangle, value: 10, width: 50,