From 6021d7df0b5f8287522b447f7a87bcb124a9a600 Mon Sep 17 00:00:00 2001 From: Sahil Sharma Date: Thu, 2 Mar 2023 12:03:07 +0530 Subject: [PATCH] rulerStyle class corrected --- lib/linear_gauge/linear_gauge.dart | 145 ++++++++++++++++-- .../styles/linear_gauge_ruler_style.dart | 134 ++-------------- test/gauges_test.dart | 20 +-- 3 files changed, 156 insertions(+), 143 deletions(-) diff --git a/lib/linear_gauge/linear_gauge.dart b/lib/linear_gauge/linear_gauge.dart index 898ea85a..10cbcdf6 100644 --- a/lib/linear_gauge/linear_gauge.dart +++ b/lib/linear_gauge/linear_gauge.dart @@ -25,6 +25,14 @@ class LinearGauge extends LeafRenderObjectWidget { this.start = 0, this.end = 100, this.steps = 0, + this.value = 0, + this.gaugeOrientation = GaugeOrientation.horizontal, + this.showLinearGaugeContainer = true, + this.linearGaugeBoxDecoration = const LinearGaugeBoxDecoration(), + this.labelTopMargin = 0.0, + this.indicator = const LinearGaugeIndicator( + shape: PointerShape.circle, + ), this.rulers = const RulerStyle(), this.rangeLinearGauge, }) : super(key: key); @@ -61,11 +69,117 @@ class LinearGauge extends LeafRenderObjectWidget { /// final double? steps; + /// + /// + /// `linearGaugeBoxDecoration` sets the styles of Container using [LinearGaugeBoxDecoration] decoration properties + /// + /// + /// Example + /// + /// ```dart + /// const LinearGauge( + /// linearGaugeBoxDecoration: LinearGaugeBoxDecoration( + /// color: Colors.green, + /// height: 30.0, + /// ), + /// ), + /// ``` + /// + final double? value; + + /// + /// `gaugeOrientation` sets the [LinearGauge] orientation to horizontal or vertical + /// + /// default is to `GaugeOrientation.horizontal` + /// + /// ```dart + /// const LinearGauge( + /// gaugeOrientation : GaugeOrientation.horizontal + /// ), + /// ``` + /// + final GaugeOrientation? gaugeOrientation; + + /// + /// `showLinearGaugeContainer` controls the [LinearGauge] Container render + /// + /// Below example renders the [LinearGauge] Container + /// + /// ```dart + /// const LinearGauge( + /// showLinearGaugeContainer : true + /// ), + /// ``` + /// + /// Below example will not render the [LinearGauge] Container + /// + /// ```dart + /// const LinearGauge( + /// showLinearGaugeContainer : false + /// ), + /// ``` + /// + final bool? showLinearGaugeContainer; + + /// + /// + /// `linearGaugeBoxDecoration` sets the styles of Container using [LinearGaugeBoxDecoration] decoration properties + /// + /// + /// Example + /// + /// ```dart + /// const LinearGauge( + /// linearGaugeBoxDecoration: LinearGaugeBoxDecoration( + /// color: Colors.green, + /// height: 30.0, + /// ), + /// ), + /// ``` + /// + final LinearGaugeBoxDecoration? linearGaugeBoxDecoration; + + /// + /// `Warning`:`deprecated` + /// + /// use `labelOffset` property in `labelStyle` to set gap b/w label & primary ruler + /// + /// `labelTopMargin` sets the margin from the top of the label + /// + /// default is to `labelTopMargin =`0.0` + /// + /// Example + /// + /// ```dart + /// child: const LinearGauge( + /// labelTopMargin: 5.0, + /// ), + /// ``` + /// + + final double? labelTopMargin; + /// /// `rulerStyle` sets the styles of label using [RulerStyle] properties /// final RulerStyle? rulers; + /// + /// `indicator` sets the styles of indicator using [LinearGaugeIndicator] properties + /// + /// Example + /// ```dart + /// const LinearGauge( + /// indicator: LinearGaugeIndicator( + /// color: Colors.green, + /// width: 10.0, + /// shape: LinearGaugeIndicatorShape.circle, + /// height: 10.0, + /// ), + /// ``` + /// + final LinearGaugeIndicator? indicator; + /// /// final List? rangeLinearGauge; @@ -75,29 +189,28 @@ class LinearGauge extends LeafRenderObjectWidget { start: start!, end: end!, steps: steps!, - showLinearGaugeContainer: rulers!.showLinearGaugeContainer!, - gaugeOrientation: rulers!.gaugeOrientation!, + showLinearGaugeContainer: showLinearGaugeContainer!, + gaugeOrientation: gaugeOrientation!, primaryRulersWidth: rulers!.primaryRulersWidth!, primaryRulersHeight: rulers!.primaryRulersHeight!, secondaryRulersHeight: rulers!.secondaryRulersHeight!, secondaryRulersWidth: rulers!.secondaryRulersWidth!, - labelTopMargin: rulers!.labelTopMargin!, + labelTopMargin: labelTopMargin!, primaryRulerColor: rulers!.primaryRulerColor!, secondaryRulerColor: rulers!.secondaryRulerColor!, - linearGaugeBoxDecoration: rulers!.linearGaugeBoxDecoration!, + linearGaugeBoxDecoration: linearGaugeBoxDecoration!, secondaryRulerPerInterval: rulers!.secondaryRulerPerInterval!, - linearGaugeContainerBgColor: - rulers!.linearGaugeBoxDecoration!.backgroundColor, + linearGaugeContainerBgColor: linearGaugeBoxDecoration!.backgroundColor, linearGaugeContainerValueColor: - rulers!.linearGaugeBoxDecoration!.linearGaugeValueColor!, + linearGaugeBoxDecoration!.linearGaugeValueColor!, textStyle: rulers!.textStyle!, showLabel: rulers!.showLabel!, rulerPosition: rulers!.rulerPosition!, labelOffset: rulers!.labelOffset!, showSecondaryRulers: rulers!.showSecondaryRulers, showPrimaryRulers: rulers!.showPrimaryRulers, - indicator: rulers!.indicator!, - value: rulers!.value!, + indicator: indicator!, + value: value!, rangeLinearGauge: rangeLinearGauge!, ); } @@ -107,30 +220,30 @@ class LinearGauge extends LeafRenderObjectWidget { BuildContext context, RenderLinearGauge renderObject) { renderObject ..setEnd = end! - ..setGaugeOrientation = rulers!.gaugeOrientation! - ..setLabelTopMargin = rulers!.labelTopMargin! + ..setGaugeOrientation = gaugeOrientation! + ..setLabelTopMargin = labelTopMargin! ..setPrimaryRulerColor = rulers!.primaryRulerColor! ..setPrimaryRulersHeight = rulers!.primaryRulersHeight! ..setPrimaryRulersWidth = rulers!.primaryRulersWidth! ..setSecondaryRulerColor = rulers!.secondaryRulerColor! ..setSecondaryRulersHeight = rulers!.secondaryRulersHeight! ..setSecondaryRulersWidth = rulers!.secondaryRulersWidth! - ..setShowLinearGaugeContainer = rulers!.showLinearGaugeContainer! + ..setShowLinearGaugeContainer = showLinearGaugeContainer! ..setStart = start! ..setSteps = steps! ..setTextStyle = rulers!.textStyle! ..setSecondaryRulerPerInterval = rulers!.secondaryRulerPerInterval! ..setLinearGaugeContainerBgColor = - rulers!.linearGaugeBoxDecoration!.backgroundColor + linearGaugeBoxDecoration!.backgroundColor ..setLinearGaugeContainerValueColor = - rulers!.linearGaugeBoxDecoration!.linearGaugeValueColor! + linearGaugeBoxDecoration!.linearGaugeValueColor! ..setShowLabel = rulers!.showLabel! ..setRulerPosition = rulers!.rulerPosition! ..setLabelOffset = rulers!.labelOffset! ..setShowSecondaryRulers = rulers!.showSecondaryRulers ..setShowPrimaryRulers = rulers!.showPrimaryRulers - ..setValue = rulers!.value! - ..setLinearGaugeIndicator = rulers!.indicator + ..setValue = value! + ..setLinearGaugeIndicator = indicator ..setRangeLinearGauge = rangeLinearGauge; } } diff --git a/lib/linear_gauge/styles/linear_gauge_ruler_style.dart b/lib/linear_gauge/styles/linear_gauge_ruler_style.dart index d25344f0..953e334a 100644 --- a/lib/linear_gauge/styles/linear_gauge_ruler_style.dart +++ b/lib/linear_gauge/styles/linear_gauge_ruler_style.dart @@ -4,22 +4,14 @@ import 'package:geekyants_flutter_gauges/gauges.dart'; class RulerStyle { const RulerStyle({ this.primaryRulerColor = Colors.black54, - this.showLinearGaugeContainer = true, - this.gaugeOrientation = GaugeOrientation.horizontal, this.primaryRulersWidth = 1.0, this.primaryRulersHeight = 15.0, this.secondaryRulersHeight = 1.0, this.secondaryRulersWidth = 1.0, - this.labelTopMargin = 0.0, this.secondaryRulerColor = Colors.grey, this.secondaryRulerPerInterval = 1.0, - this.linearGaugeBoxDecoration = const LinearGaugeBoxDecoration(), - this.value = 0, this.showSecondaryRulers = true, this.showPrimaryRulers = true, - this.indicator = const LinearGaugeIndicator( - shape: PointerShape.circle, - ), this.textStyle = const TextStyle( fontSize: 12.0, color: Color.fromARGB(255, 86, 86, 86), @@ -41,46 +33,14 @@ class RulerStyle { /// /// ```dart /// child: const LinearGauge( + /// rulers : RulerStyle( /// primaryRulerColor: Colors.green, + /// ) /// ), /// ``` /// final Color? primaryRulerColor; - /// - /// `showLinearGaugeContainer` controls the [LinearGauge] Container render - /// - /// Below example renders the [LinearGauge] Container - /// - /// ```dart - /// const LinearGauge( - /// showLinearGaugeContainer : true - /// ), - /// ``` - /// - /// Below example will not render the [LinearGauge] Container - /// - /// ```dart - /// const LinearGauge( - /// showLinearGaugeContainer : false - /// ), - /// ``` - /// - final bool? showLinearGaugeContainer; - - /// - /// `gaugeOrientation` sets the [LinearGauge] orientation to horizontal or vertical - /// - /// default is to `GaugeOrientation.horizontal` - /// - /// ```dart - /// const LinearGauge( - /// gaugeOrientation : GaugeOrientation.horizontal - /// ), - /// ``` - /// - final GaugeOrientation? gaugeOrientation; - /// /// /// `primaryRulersWidth` set the width of the Rulers which are attached to the labels @@ -91,7 +51,9 @@ class RulerStyle { /// /// ```dart /// child: const LinearGauge( + /// rulers : RulerStyle( /// primaryRulersWidth: 2, + /// ) /// ), /// ``` final double? primaryRulersWidth; @@ -106,7 +68,9 @@ class RulerStyle { /// /// ```dart /// child: const LinearGauge( + /// rulers : RulerStyle( /// primaryRulersHeight: 20, + /// ) /// ), /// ``` /// @@ -122,7 +86,9 @@ class RulerStyle { /// /// ```dart /// child: const LinearGauge( + /// rulers : RulerStyle( /// secondaryRulersHeight: 20, + /// ) /// ), /// ``` /// @@ -138,32 +104,14 @@ class RulerStyle { /// /// ```dart /// child: const LinearGauge( + /// rulers : RulerStyle( /// primaryRulersHeight: 20, + /// ) /// ), /// ``` /// final double? secondaryRulersWidth; - /// - /// `Warning`:`deprecated` - /// - /// use `labelOffset` property in `labelStyle` to set gap b/w label & primary ruler - /// - /// `labelTopMargin` sets the margin from the top of the label - /// - /// default is to `labelTopMargin =`0.0` - /// - /// Example - /// - /// ```dart - /// child: const LinearGauge( - /// labelTopMargin: 5.0, - /// ), - /// ``` - /// - - final double? labelTopMargin; - /// /// /// `secondaryRulerColor` sets the color of the ruler which are in the between of ruler attached to labels @@ -174,7 +122,9 @@ class RulerStyle { /// /// ```dart /// child: const LinearGauge( + /// rulers : RulerStyle( /// secondaryRulerColor: Colors.green, + /// ) /// ), /// ``` /// @@ -190,48 +140,14 @@ class RulerStyle { /// /// ```dart /// child: const LinearGauge( + /// rulers : RulerStyle( /// secondaryRulerPerInterval:1, + /// ) /// ), /// ``` /// final double? secondaryRulerPerInterval; - /// - /// - /// `linearGaugeBoxDecoration` sets the styles of Container using [LinearGaugeBoxDecoration] decoration properties - /// - /// - /// Example - /// - /// ```dart - /// const LinearGauge( - /// linearGaugeBoxDecoration: LinearGaugeBoxDecoration( - /// color: Colors.green, - /// height: 30.0, - /// ), - /// ), - /// ``` - /// - final LinearGaugeBoxDecoration? linearGaugeBoxDecoration; - - /// - /// - /// `linearGaugeBoxDecoration` sets the styles of Container using [LinearGaugeBoxDecoration] decoration properties - /// - /// - /// Example - /// - /// ```dart - /// const LinearGauge( - /// linearGaugeBoxDecoration: LinearGaugeBoxDecoration( - /// color: Colors.green, - /// height: 30.0, - /// ), - /// ), - /// ``` - /// - final double? value; - /// /// /// `showSecondaryRules` sets the visibility of the secondary rulers. @@ -242,22 +158,6 @@ class RulerStyle { /// `showSecondaryRules` sets the visibility of the primary rulers. final bool showPrimaryRulers; - /// - /// `indicator` sets the styles of indicator using [LinearGaugeIndicator] properties - /// - /// Example - /// ```dart - /// const LinearGauge( - /// indicator: LinearGaugeIndicator( - /// color: Colors.green, - /// width: 10.0, - /// shape: LinearGaugeIndicatorShape.circle, - /// height: 10.0, - /// ), - /// ``` - /// - final LinearGaugeIndicator? indicator; - /// /// `textStyle` sets the ruler text style of [LinearGauge] /// @@ -275,7 +175,7 @@ class RulerStyle { /// /// ```dart /// child: const LinearGauge( - /// labelStyle: RulerStyle( + /// rulers: RulerStyle( /// textStyle: TextStyle(color: Colors.red, fontSize: 16.0), /// ) /// ), @@ -298,7 +198,7 @@ class RulerStyle { /// /// ```dart /// child: const LinearGauge( - /// labelStyle : RulerStyle( + /// rulers : RulerStyle( /// rulerPosition: RulerPosition.bottom, /// ), /// ``` @@ -315,7 +215,7 @@ class RulerStyle { /// /// ```dart /// child: const LinearGauge( - /// labelStyle : RulerStyle( + /// rulers : RulerStyle( /// labelOffset: 10.0, /// ), /// ``` diff --git a/test/gauges_test.dart b/test/gauges_test.dart index 1440d4df..9a596b27 100644 --- a/test/gauges_test.dart +++ b/test/gauges_test.dart @@ -9,19 +9,19 @@ void main() { start: 0, end: 1000, steps: 0, + value: 0, + showLinearGaugeContainer: true, + gaugeOrientation: GaugeOrientation.horizontal, + labelTopMargin: 0.0, + linearGaugeBoxDecoration: LinearGaugeBoxDecoration(), rulers: RulerStyle( primaryRulerColor: Colors.black54, - showLinearGaugeContainer: true, - gaugeOrientation: GaugeOrientation.horizontal, primaryRulersWidth: 1.0, primaryRulersHeight: 15.0, secondaryRulersHeight: 1.0, secondaryRulersWidth: 1.0, - labelTopMargin: 0.0, secondaryRulerColor: Colors.grey, secondaryRulerPerInterval: 1.0, - linearGaugeBoxDecoration: LinearGaugeBoxDecoration(), - value: 0, textStyle: TextStyle( fontSize: 12.0, color: Color.fromARGB(255, 86, 86, 86), @@ -42,10 +42,10 @@ void main() { ); expect(linearGauge.start, 0.0); expect(linearGauge.end, 1000.0); - expect(linearGauge.rulers!.value, 0); + expect(linearGauge.value, 0); expect(linearGauge.steps, 0); - expect(linearGauge.rulers!.showLinearGaugeContainer, true); - expect(linearGauge.rulers!.gaugeOrientation, GaugeOrientation.horizontal); + expect(linearGauge.showLinearGaugeContainer, true); + expect(linearGauge.gaugeOrientation, GaugeOrientation.horizontal); expect(linearGauge.rulers!.textStyle, textStyle); expect(linearGauge.rulers!.primaryRulersWidth, 1.0); expect(linearGauge.rulers!.primaryRulersHeight, 15.0); @@ -53,8 +53,8 @@ void main() { expect(linearGauge.rulers!.primaryRulerColor, Colors.black54); expect(linearGauge.rulers!.secondaryRulersHeight, 1); expect(linearGauge.rulers!.secondaryRulersWidth, 1); - expect(linearGauge.rulers!.labelTopMargin, 0.0); - expect(linearGauge.rulers!.linearGaugeBoxDecoration, + expect(linearGauge.labelTopMargin, 0.0); + expect(linearGauge.linearGaugeBoxDecoration, const LinearGaugeBoxDecoration()); expect(linearGauge.rulers!.secondaryRulerPerInterval, 1.0); expect(linearGauge.rulers!.rulerPosition!, RulerPosition.bottom);