Skip to content

Commit 103ac4d

Browse files
authoredMay 6, 2024··
Merge pull request #260 from GeekyAnts/development
Development
2 parents 12e13e4 + afbed78 commit 103ac4d

File tree

20 files changed

+225
-69
lines changed

20 files changed

+225
-69
lines changed
 

‎CHANGELOG.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1+
## 1.0.4
2+
3+
**Features**
4+
5+
- Add Custom Track Labels to Radial Gauge
6+
7+
**Fixes**
8+
9+
- Fixed needle-gap issue in Radial Gauge
10+
111
## 1.0.3
212

313
**Fixes**
414

515
- Fixed Drawing of `Pointer` over `valueBar`
616

7-
817
## 1.0.2
918

1019
**Features**

‎README.md

+38-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ This will add a line like this to your package's pubspec.yaml (and run an implic
6464

6565
```dart
6666
dependencies:
67-
geekyants_flutter_gauges: 1.0.1
67+
geekyants_flutter_gauges: 1.0.4
6868
```
6969

7070
## Usage
@@ -77,6 +77,8 @@ import 'package:geekyants_flutter_gauges/geekyants_flutter_gauges.dart';
7777

7878
Use it as below
7979

80+
# Linear Gauge usage
81+
8082
```dart
8183
class _MyGaugeExampleState extends State<MyGaugeExample> {
8284
@override
@@ -94,6 +96,31 @@ class _MyGaugeExampleState extends State<MyGaugeExample> {
9496
}
9597
```
9698

99+
# Radial Gauge usage
100+
101+
```dart
102+
class _MyGaugeExampleState extends State<MyGaugeExample> {
103+
@override
104+
Widget build(BuildContext context) {
105+
return Scaffold(
106+
body: Center(
107+
child: RadialGauge(
108+
track: RadialTrack(
109+
start: 0,
110+
end: 100,
111+
),
112+
needlePointer: [
113+
NeedlePointer(
114+
value: 30,
115+
),
116+
],
117+
),
118+
)
119+
);
120+
}
121+
}
122+
```
123+
97124
## Linear Gauge
98125

99126
### **Gauge Orientation**:
@@ -167,6 +194,12 @@ Default **`endAngle`**`: 210°
167194

168195
<p align='center'><img src="https://raw.githubusercontent.com/GeekyAnts/GaugesFlutter/main/example/screens/radial-angles.png" alt="radial-angels" height=440></p>
169196

197+
#### Custom Track Labels
198+
199+
The labels displayed on the RadialGauge track can easily be formated to your need.
200+
201+
<p align='center'><img src="example/screens/radial-custom-track-label.png" alt="radial-gauge-custom-track-label" height=440></p>
202+
170203
#### **Radii Customization**
171204

172205
`radiusFactor` can be used to size the adjust the scaling factor of the radius and change the radius of the gauge accordingly.
@@ -224,3 +257,7 @@ In the Radial Gauge, the `NeedlePointer` and `RadialShapePointer` can be set to
224257
## Credits
225258

226259
Made with ❤️ by <a href="https://geekyants.com/" ><img src="https://s3.ap-southeast-1.amazonaws.com/cdn.elitmus.com/sy0zfezmfdovlb4vaz6siv1l7g30" height="17"/></a>
260+
261+
```
262+
263+
```

‎example/lib/main.dart

+3-11
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,12 @@ class _RadialGaugeExampleState extends State<RadialGaugeExample> {
6464
backgroundColor: Colors.white,
6565
body: RadialGauge(
6666
track: RadialTrack(
67-
color: Colors.grey,
68-
start: 0,
69-
end: 100,
70-
trackStyle: TrackStyle(
71-
showLastLabel: false,
72-
secondaryRulerColor: Colors.grey,
73-
secondaryRulerPerInterval: 3)),
67+
start: 0,
68+
end: 100,
69+
),
7470
needlePointer: [
7571
NeedlePointer(
7672
value: 30,
77-
color: Colors.red,
78-
tailColor: Colors.black,
79-
tailRadius: 0,
80-
needleStyle: NeedleStyle.flatNeedle,
8173
),
8274
],
8375
),
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:geekyants_flutter_gauges/geekyants_flutter_gauges.dart';
3+
4+
///
5+
/// The following code is a Simple Example of [RadialGauge] Widget with custom track labels.
6+
///
7+
class RadialGaugeCustomLabel extends StatefulWidget {
8+
const RadialGaugeCustomLabel({super.key});
9+
10+
@override
11+
State<RadialGaugeCustomLabel> createState() => _RadialGaugeCustomLabelState();
12+
}
13+
14+
class _RadialGaugeCustomLabelState extends State<RadialGaugeCustomLabel> {
15+
@override
16+
Widget build(BuildContext context) {
17+
return Scaffold(
18+
backgroundColor: Colors.white,
19+
body: RadialGauge(
20+
track: RadialTrack(
21+
color: Colors.grey,
22+
start: 0,
23+
end: 100,
24+
trackLabelFormater: (double value) => "${value.round()}€",
25+
trackStyle: const TrackStyle(
26+
showFirstLabel: false,
27+
showLastLabel: false,
28+
)),
29+
),
30+
);
31+
}
32+
}

‎example/macos/Runner.xcodeproj/project.pbxproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
isa = PBXProject;
183183
attributes = {
184184
LastSwiftUpdateCheck = 0920;
185-
LastUpgradeCheck = 1430;
185+
LastUpgradeCheck = 1510;
186186
ORGANIZATIONNAME = "";
187187
TargetAttributes = {
188188
33CC10EC2044A3C60003C045 = {

‎example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1430"
3+
LastUpgradeVersion = "1510"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

‎example/pubspec.lock

+52-28
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,18 @@ packages:
3737
dependency: transitive
3838
description:
3939
name: collection
40-
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
40+
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
4141
url: "https://pub.dev"
4242
source: hosted
43-
version: "1.17.2"
43+
version: "1.18.0"
4444
cupertino_icons:
4545
dependency: "direct main"
4646
description:
4747
name: cupertino_icons
48-
sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be
48+
sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6
4949
url: "https://pub.dev"
5050
source: hosted
51-
version: "1.0.5"
51+
version: "1.0.8"
5252
fake_async:
5353
dependency: transitive
5454
description:
@@ -66,10 +66,10 @@ packages:
6666
dependency: "direct dev"
6767
description:
6868
name: flutter_lints
69-
sha256: aeb0b80a8b3709709c9cc496cdc027c5b3216796bc0af0ce1007eaf24464fd4c
69+
sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04
7070
url: "https://pub.dev"
7171
source: hosted
72-
version: "2.0.1"
72+
version: "2.0.3"
7373
flutter_test:
7474
dependency: "direct dev"
7575
description: flutter
@@ -81,47 +81,71 @@ packages:
8181
path: ".."
8282
relative: true
8383
source: path
84-
version: "1.0.2"
84+
version: "1.0.3"
85+
leak_tracker:
86+
dependency: transitive
87+
description:
88+
name: leak_tracker
89+
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
90+
url: "https://pub.dev"
91+
source: hosted
92+
version: "10.0.0"
93+
leak_tracker_flutter_testing:
94+
dependency: transitive
95+
description:
96+
name: leak_tracker_flutter_testing
97+
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
98+
url: "https://pub.dev"
99+
source: hosted
100+
version: "2.0.1"
101+
leak_tracker_testing:
102+
dependency: transitive
103+
description:
104+
name: leak_tracker_testing
105+
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
106+
url: "https://pub.dev"
107+
source: hosted
108+
version: "2.0.1"
85109
lints:
86110
dependency: transitive
87111
description:
88112
name: lints
89-
sha256: "5e4a9cd06d447758280a8ac2405101e0e2094d2a1dbdd3756aec3fe7775ba593"
113+
sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452"
90114
url: "https://pub.dev"
91115
source: hosted
92-
version: "2.0.1"
116+
version: "2.1.1"
93117
matcher:
94118
dependency: transitive
95119
description:
96120
name: matcher
97-
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
121+
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
98122
url: "https://pub.dev"
99123
source: hosted
100-
version: "0.12.16"
124+
version: "0.12.16+1"
101125
material_color_utilities:
102126
dependency: transitive
103127
description:
104128
name: material_color_utilities
105-
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
129+
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
106130
url: "https://pub.dev"
107131
source: hosted
108-
version: "0.5.0"
132+
version: "0.8.0"
109133
meta:
110134
dependency: transitive
111135
description:
112136
name: meta
113-
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
137+
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
114138
url: "https://pub.dev"
115139
source: hosted
116-
version: "1.9.1"
140+
version: "1.11.0"
117141
path:
118142
dependency: transitive
119143
description:
120144
name: path
121-
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
145+
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
122146
url: "https://pub.dev"
123147
source: hosted
124-
version: "1.8.3"
148+
version: "1.9.0"
125149
sky_engine:
126150
dependency: transitive
127151
description: flutter
@@ -139,18 +163,18 @@ packages:
139163
dependency: transitive
140164
description:
141165
name: stack_trace
142-
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
166+
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
143167
url: "https://pub.dev"
144168
source: hosted
145-
version: "1.11.0"
169+
version: "1.11.1"
146170
stream_channel:
147171
dependency: transitive
148172
description:
149173
name: stream_channel
150-
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
174+
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
151175
url: "https://pub.dev"
152176
source: hosted
153-
version: "2.1.1"
177+
version: "2.1.2"
154178
string_scanner:
155179
dependency: transitive
156180
description:
@@ -171,10 +195,10 @@ packages:
171195
dependency: transitive
172196
description:
173197
name: test_api
174-
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
198+
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
175199
url: "https://pub.dev"
176200
source: hosted
177-
version: "0.6.0"
201+
version: "0.6.1"
178202
vector_math:
179203
dependency: transitive
180204
description:
@@ -183,14 +207,14 @@ packages:
183207
url: "https://pub.dev"
184208
source: hosted
185209
version: "2.1.4"
186-
web:
210+
vm_service:
187211
dependency: transitive
188212
description:
189-
name: web
190-
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
213+
name: vm_service
214+
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
191215
url: "https://pub.dev"
192216
source: hosted
193-
version: "0.1.4-beta"
217+
version: "13.0.0"
194218
sdks:
195-
dart: ">=3.1.0-185.0.dev <4.0.0"
219+
dart: ">=3.2.0-0 <4.0.0"
196220
flutter: ">=1.17.0"
26.1 KB
Loading

‎lib/src/radial_gauge/pointer/needle_pointer_painter.dart

+1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ class RenderNeedlePointer extends RenderBox {
200200

201201
final needlePaint = Paint()
202202
..color = _color
203+
..style = PaintingStyle.fill
203204
..strokeWidth = strokeWidth
204205
..shader = gradient.createShader(
205206
Rect.fromPoints(

‎lib/src/radial_gauge/radial_gauge_container_painter.dart

+6-7
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ class RenderRadialGaugeContainer extends RenderBox {
5454
..strokeWidth = getRadialGauge.track.trackStyle.secondaryRulersWidth!
5555
..style = PaintingStyle.stroke;
5656

57+
final trackLabelFormater = getRadialGauge.track.trackLabelFormater ??
58+
(double value) => ((value * 10).round() / 10).toString();
59+
5760
// Loop to draw the Rulers and Labels
5861
for (int i = 0; i <= numParts; i++) {
5962
double rulerOffset = getRadialGauge.track.trackStyle.rulersOffset ?? 0;
@@ -111,13 +114,10 @@ class RenderRadialGaugeContainer extends RenderBox {
111114
final TextPainter textPainter =
112115
TextPainter(textDirection: TextDirection.ltr);
113116

114-
const String labelFormat = '%d';
115117
final double langle =
116118
startAngle + i * partAngle; // the angle of the current ruler
117119
// the y coordinate of the label
118-
final String label = labelFormat.replaceAll(
119-
'%d', ((langle - startAngle) * 180 / pi).round().toString());
120-
double l = double.parse(label);
120+
double l = (langle - startAngle) * 180 / pi;
121121
double sAngle = _radialGauge.track.startAngle;
122122
double eAngle = _radialGauge.track.endAngle;
123123

@@ -126,11 +126,10 @@ class RenderRadialGaugeContainer extends RenderBox {
126126
double end = _radialGauge.track.end;
127127
double valueRange = (end - start);
128128

129-
double exactValue =
130-
start + double.parse(((l / range) * valueRange).toStringAsFixed(2));
129+
double exactValue = start + ((l / range) * valueRange);
131130
Color textColor = Colors.black;
132131
textPainter.text = TextSpan(
133-
text: exactValue.toString(),
132+
text: trackLabelFormater(exactValue),
134133
style: getRadialGauge.track.trackStyle.labelStyle ??
135134
TextStyle(color: textColor, fontWeight: FontWeight.bold));
136135
textPainter.layout();

‎lib/src/radial_gauge/radial_track.dart

+16
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class RadialTrack {
6363
secondaryRulerPerInterval: 4.0,
6464
),
6565
this.gradient,
66+
this.trackLabelFormater,
6667
});
6768

6869
///
@@ -121,6 +122,21 @@ class RadialTrack {
121122
/// The [trackStyle] property is used to customize the track of the Radial Gauge.
122123
///
123124
final TrackStyle trackStyle;
125+
126+
///
127+
/// The [trackLabelFormater] property is used to customize the track labels of the Radial Gauge.
128+
///
129+
/// ``` dart
130+
/// RadialGauge(
131+
/// track: RadialTrack(
132+
/// start: 0,
133+
/// end: 100,
134+
/// trackLabelFormater: (double value) => "${value.round()}€",
135+
/// ),
136+
/// ),
137+
/// ```
138+
///
139+
final String Function(double)? trackLabelFormater;
124140
}
125141

126142
class TrackStyle extends BaseRulerStyle {

‎test/custom_curve_test/custom_curve_test.dart

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class MyCustomCurveGauge extends StatelessWidget {
5151
Widget build(BuildContext context) {
5252
return MaterialApp(
5353
theme: ThemeData(
54+
useMaterial3: false,
5455
fontFamily: 'Roboto',
5556
),
5657
home: Scaffold(

‎test/custom_labels_test/custom_labels_test.dart

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class MyPointerTestLinearGauge extends StatelessWidget {
4949
Widget build(BuildContext context) {
5050
return MaterialApp(
5151
theme: ThemeData(
52+
useMaterial3: false,
5253
fontFamily: 'Roboto',
5354
),
5455
home: Scaffold(

‎test/extend_linear_gauge_test/extend_linear_gauge_test.dart

+1-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ class MyExtendLinearGaugeTest extends StatelessWidget {
4343
@override
4444
Widget build(BuildContext context) {
4545
return MaterialApp(
46-
theme: ThemeData(
47-
fontFamily: 'Roboto',
48-
),
46+
theme: ThemeData(fontFamily: 'Roboto', useMaterial3: false),
4947
home: Scaffold(
5048
appBar: AppBar(
5149
title: const Text("Default LinearGauge"),

‎test/flutter_test_config.dart

+57-16
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,63 @@
11
import 'dart:async';
2-
import 'dart:io';
32

4-
import 'package:golden_toolkit/golden_toolkit.dart';
3+
import 'package:flutter/foundation.dart';
4+
import 'package:flutter_test/flutter_test.dart';
55

6-
// All tests in this folder and its subfolders will have the configuration defined here
6+
const _kGoldenTestsThreshold = 10 / 100; // 1% tolerance
77

88
Future<void> testExecutable(FutureOr<void> Function() testMain) async {
9-
return GoldenToolkit.runWithConfiguration(
10-
() async {
11-
await loadAppFonts();
12-
await testMain();
13-
},
14-
config: GoldenToolkitConfiguration(
15-
// Currently, goldens are not generated/validated in CI for this repo. We have settled on the goldens for this package
16-
// being captured/validated by developers running on MacOSX. We may revisit this in the future if there is a reason to invest
17-
// in more sophistication
18-
skipGoldenAssertion: () => !Platform.isMacOS,
19-
enableRealShadows: true,
20-
),
21-
);
9+
if (goldenFileComparator is LocalFileComparator) {
10+
final testUrl = (goldenFileComparator as LocalFileComparator).basedir;
11+
12+
goldenFileComparator = LocalFileComparatorWithThreshold(
13+
Uri.parse('$testUrl/test. dart'),
14+
_kGoldenTestsThreshold,
15+
);
16+
} else {
17+
throw Exception(
18+
'Expected goldenFileComparator to be of type'
19+
'LocalFileComparator'
20+
'but it is of type ${goldenFileComparator.runtimeType}`',
21+
);
22+
}
23+
await testMain();
24+
}
25+
26+
/// Works just like [LocalFileComparator] but includes a [threshold] that, when
27+
/// exceeded, marks the test as a failure.
28+
class LocalFileComparatorWithThreshold extends LocalFileComparator {
29+
/// Threshold above which tests will be marked as failing.
30+
/// Ranges from 0 to 1, both inclusive.
31+
final double threshold;
32+
33+
LocalFileComparatorWithThreshold(Uri testFile, this.threshold)
34+
: assert(threshold >= 0 && threshold <= 1),
35+
super(testFile);
36+
37+
/// Copy of [LocalFileComparator]'s [compare] method, except for the fact that
38+
/// it checks if the [ComparisonResult.diffPercent] is not greater than
39+
/// [threshold] to decide whether this test is successful or a failure.
40+
@override
41+
Future<bool> compare(Uint8List imageBytes, Uri golden) async {
42+
final result = await GoldenFileComparator.compareLists(
43+
imageBytes,
44+
await getGoldenBytes(golden),
45+
);
46+
47+
if (!result.passed && result.diffPercent <= threshold) {
48+
// print(
49+
// 'A difference of ${result.diffPercent * 100}% was found, but it is '
50+
// 'acceptable since it is not greater than the threshold of '
51+
// '${threshold * 100}%',
52+
// );
53+
54+
return true;
55+
}
56+
57+
if (!result.passed) {
58+
final error = await generateFailureOutput(result, golden, basedir);
59+
throw FlutterError(error);
60+
}
61+
return result.passed;
62+
}
2263
}

‎test/linear_gauge_container_test/linear_gauge_container_test.dart

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class MyLinearGaugeContainer extends StatelessWidget {
4545
return MaterialApp(
4646
theme: ThemeData(
4747
fontFamily: 'Roboto',
48+
useMaterial3: false,
4849
),
4950
home: Scaffold(
5051
appBar: AppBar(

‎test/pointers_test/pointers_test.dart

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class MyPointerTestLinearGauge extends StatelessWidget {
7676
return MaterialApp(
7777
theme: ThemeData(
7878
fontFamily: 'Roboto',
79+
useMaterial3: false,
7980
),
8081
home: Scaffold(
8182
appBar: AppBar(

‎test/range_linear_gauge_test/range_linear_test.dart

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class MyRangeLinearGauge extends StatelessWidget {
6565
return MaterialApp(
6666
theme: ThemeData(
6767
fontFamily: 'Roboto',
68+
useMaterial3: false,
6869
),
6970
home: Scaffold(
7071
appBar: AppBar(

‎test/shader_paint_test/shader_paint_test.dart

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class MyValuBarTestLinearGauge extends StatelessWidget {
4848
return MaterialApp(
4949
theme: ThemeData(
5050
fontFamily: 'Roboto',
51+
useMaterial3: false,
5152
),
5253
home: Scaffold(
5354
appBar: AppBar(

‎test/value_bar_test/value_bar_test.dart

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class MyValuBarTestLinearGauge extends StatelessWidget {
5252
return MaterialApp(
5353
theme: ThemeData(
5454
fontFamily: 'Roboto',
55+
useMaterial3: false,
5556
),
5657
home: Scaffold(
5758
appBar: AppBar(

0 commit comments

Comments
 (0)
Please sign in to comment.