Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Afroz-Shaikh committed May 14, 2024
1 parent 2c65b39 commit 4c5ac76
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 52 deletions.
57 changes: 31 additions & 26 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class _LinearGaugeExampleState extends State<LinearGaugeExample> {
child: Column(
children: [
LinearGauge(
numberFormat:
NumberFormat.currency(decimalDigits: 1, symbol: 'F'),
// numberFormat:
// NumberFormat.currency(decimalDigits: 1, symbol: 'F'),
start: -70.33,
end: 62.4444,
gaugeOrientation: GaugeOrientation.horizontal,
Expand Down Expand Up @@ -70,29 +70,34 @@ class _LinearGaugeExampleState extends State<LinearGaugeExample> {
/// You can customize the [RadialGauge] Widget as per your need.
///
// class RadialGaugeExample extends StatefulWidget {
// const RadialGaugeExample({super.key});
class RadialGaugeExample extends StatefulWidget {
const RadialGaugeExample({super.key});

// @override
// State<RadialGaugeExample> createState() => _RadialGaugeExampleState();
// }
@override
State<RadialGaugeExample> createState() => _RadialGaugeExampleState();
}

// class _RadialGaugeExampleState extends State<RadialGaugeExample> {
// @override
// Widget build(BuildContext context) {
// return Scaffold(
// backgroundColor: Colors.white,
// body: RadialGauge(
// track: RadialTrack(
// start: 0,
// end: 100,
// ),
// needlePointer: [
// NeedlePointer(
// value: 30,
// ),
// ],
// ),
// );
// }
// }
class _RadialGaugeExampleState extends State<RadialGaugeExample> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: RadialGauge(
track: RadialTrack(
// trackLabelFormater: (value) {
// return NumberFormat.currency(
// locale: 'en_US', name: 'R', decimalDigits: 3)
// .format(value);
// },
start: -70.33,
end: 62.4444,
),
needlePointer: [
NeedlePointer(
value: 30,
),
],
),
);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:geekyants_flutter_gauges/geekyants_flutter_gauges.dart';
import 'package:intl/intl.dart';
import 'package:intl/intl.dart' show NumberFormat;
import 'dart:math' as math;
import '../linear_gauge_label.dart';

Expand All @@ -20,7 +20,7 @@ class LinearGaugeContainer extends LeafRenderObjectWidget {
return RenderLinearGaugeContainer(
start: linearGauge.start!,
end: linearGauge.end!,
numberFormat: linearGauge.numberFormat ?? NumberFormat('#.##'),
numberFormat: linearGauge.labelFormat ?? NumberFormat('#.##'),
value: linearGauge.value!,
steps: linearGauge.steps!,
gaugeOrientation: linearGauge.gaugeOrientation!,
Expand Down Expand Up @@ -61,7 +61,7 @@ class LinearGaugeContainer extends LeafRenderObjectWidget {
renderObject
..setStart = linearGauge.start!
..setEnd = linearGauge.end!
..setNumberFormat = linearGauge.numberFormat ?? NumberFormat('#.##')
..setNumberFormat = linearGauge.labelFormat ?? NumberFormat('#.##')
..setValue = linearGauge.value!
..setSteps = linearGauge.steps!
..setGaugeOrientation = linearGauge.gaugeOrientation!
Expand Down Expand Up @@ -714,7 +714,7 @@ class RenderLinearGaugeContainer extends RenderBox {
}

_linearGaugeLabel.addLabels(
numberFormat: getNumberFormat,
labelFormat: getNumberFormat,
distanceValueInRangeOfHundred: getSteps == 0.0 ? interval : getSteps,
start: getStart,
end: getEnd,
Expand Down
20 changes: 15 additions & 5 deletions lib/src/linear_gauge/linear_gauge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class LinearGauge extends StatefulWidget {
Key? key,
this.start = 0,
this.end = 100,
this.numberFormat,
this.labelFormat,
this.steps = 0,
@Deprecated('Use ValueBar instead') this.value = 0,
this.gaugeOrientation = GaugeOrientation.horizontal,
Expand Down Expand Up @@ -157,8 +157,18 @@ class LinearGauge extends StatefulWidget {
///
final double? steps;

//!
final NumberFormat? numberFormat;
///
/// `labelFormat` Sets the format of the label of the [LinearGauge] using [NumberFormat]
///
/// default is to `NumberFormat('#.##')`
///
/// ```dart
/// const LinearGauge(
/// labelFormat : NumberFormat.currency(locale: "en_US", symbol: "\$"),
/// ),
/// ```
///
final NumberFormat? labelFormat;

///
/// `extendLinearGauge` Sets the rulers & labels away from the ending points of [LinearGauge] Container
Expand Down Expand Up @@ -717,7 +727,7 @@ class _RLinearGauge extends MultiChildRenderObjectWidget {
return RenderLinearGauge(
start: lGauge.start!,
end: lGauge.end!,
numberFormat: lGauge.numberFormat ?? NumberFormat('#.##'),
labelFormat: lGauge.labelFormat ?? NumberFormat('#.##'),
steps: lGauge.steps!,
gaugeOrientation: lGauge.gaugeOrientation!,
primaryRulersWidth: lGauge.rulers!.primaryRulersWidth!,
Expand Down Expand Up @@ -747,7 +757,7 @@ class _RLinearGauge extends MultiChildRenderObjectWidget {
BuildContext context, RenderLinearGauge renderObject) {
renderObject
..setCustomLabels = lGauge.customLabels!
..setNumberFormat = lGauge.numberFormat!
..setNumberFormat = lGauge.labelFormat ?? NumberFormat('#.##')
..setGaugeOrientation = lGauge.gaugeOrientation!
..setPrimaryRulersHeight = lGauge.rulers!.primaryRulersHeight!
..setPrimaryRulersWidth = lGauge.rulers!.primaryRulersWidth!
Expand Down
22 changes: 13 additions & 9 deletions lib/src/linear_gauge/linear_gauge_label.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,33 @@ class LinearGaugeLabel {
TextPainter(textDirection: TextDirection.ltr);

void addLabels({
NumberFormat? numberFormat,
NumberFormat? labelFormat,
required double distanceValueInRangeOfHundred,
required double start,
required double end,
}) {
_linearGaugeLabel.clear();

for (double i = start; i <= end; i += distanceValueInRangeOfHundred) {
String temp;
if (numberFormat != null) {
temp = numberFormat.format(i);
String stringValue;
if (labelFormat != null) {
stringValue = labelFormat.format(i);
} else {
temp = i.toString();
stringValue = i.toString();
}
_linearGaugeLabel.add(LinearGaugeLabel(text: temp, value: i));
// _linearGaugeLabel
// .add(LinearGaugeLabel(text: i.toStringAsFixed(2), value: i));
_linearGaugeLabel.add(LinearGaugeLabel(text: stringValue, value: i));
}

final LinearGaugeLabel localLabel =
_linearGaugeLabel[_linearGaugeLabel.length - 1];
if (localLabel.value != end && localLabel.value! < end) {
_linearGaugeLabel.add(LinearGaugeLabel(text: end.toString(), value: end));
String stringValue;
if (labelFormat != null) {
stringValue = labelFormat.format(end);
} else {
stringValue = end.toString();
}
_linearGaugeLabel.add(LinearGaugeLabel(text: stringValue, value: end));
}
}

Expand Down
14 changes: 6 additions & 8 deletions lib/src/linear_gauge/linear_gauge_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RenderLinearGauge extends RenderBox
RenderLinearGauge({
required double start,
required double end,
required NumberFormat numberFormat,
required NumberFormat labelFormat,
required double steps,
required GaugeOrientation gaugeOrientation,
required TextStyle textStyle,
Expand Down Expand Up @@ -147,8 +147,6 @@ class RenderLinearGauge extends RenderBox
double get getStart => _start;
double _start;
set setStart(double start) {
log('Setting start as $start');

if (_start == start) return;
_start = start;
markNeedsPaint();
Expand All @@ -165,11 +163,11 @@ class RenderLinearGauge extends RenderBox
markNeedsPaint();
}

get getNumberFormat => _numberFormat;
NumberFormat? _numberFormat;
set setNumberFormat(NumberFormat? numberFormat) {
if (_numberFormat == numberFormat) return;
_numberFormat = numberFormat;
get getLabelFormat => _labelFormat;
NumberFormat? _labelFormat;
set setNumberFormat(NumberFormat? labelFormat) {
if (_labelFormat == labelFormat) return;
_labelFormat = labelFormat;
markNeedsPaint();
}

Expand Down

0 comments on commit 4c5ac76

Please sign in to comment.