Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/radial shape pointers #272

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 36 additions & 12 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ void main() {
runApp(
const MaterialApp(
debugShowCheckedModeBanner: false,
home: MyVerticalGauge(),
home: RadialGaugeExample(),
),
);
}
Expand All @@ -23,6 +23,7 @@ class LinearGaugeExample extends StatefulWidget {
}

class _LinearGaugeExampleState extends State<LinearGaugeExample> {
double value = 20;
@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -33,12 +34,17 @@ class _LinearGaugeExampleState extends State<LinearGaugeExample> {
rulers: RulerStyle(
rulerPosition: RulerPosition.bottom,
),
pointers: const [
Pointer(
value: 50,
shape: PointerShape.circle,
),
valueBar: [
ValueBar(
value: 20,
offset: 300,
)
],
customLabels: [
CustomRulerLabel(text: "Hello One", value: value),
CustomRulerLabel(text: "Hello Two", value: 60),
],
pointers: [],
),
),
);
Expand All @@ -58,19 +64,37 @@ class RadialGaugeExample extends StatefulWidget {
}

class _RadialGaugeExampleState extends State<RadialGaugeExample> {
double value = 20;
@override
Widget build(BuildContext context) {
return const Scaffold(
backgroundColor: Colors.white,
return Scaffold(
backgroundColor: Colors.black,
body: RadialGauge(
track: RadialTrack(
trackStyle: TrackStyle(
labelStyle: TextStyle(color: Colors.white),
primaryRulerColor: Colors.blueAccent,
secondaryRulerColor: Colors.blueGrey),
color: Colors.white,
start: 0,
end: 100,
// startAngle: 0,
// endAngle: 360,
),
needlePointer: [
NeedlePointer(
value: 30,
),
shapePointer: [
RadialShapePointer(
color: Colors.red,
width: 40,
height: 40,
isInteractive: true,
onChanged: (v) {
setState(() {
value = v;
});
},
value: value,
shape: PointerShape.triangle,
)
],
),
);
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.3"
version: "1.0.4"
leak_tracker:
dependency: transitive
description:
Expand Down
6 changes: 6 additions & 0 deletions lib/src/linear_gauge/linear_gauge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ class LinearGauge extends StatefulWidget {
this.curves = const [],
}) : assert(() {
if (customLabels!.isNotEmpty) {
if (valueBar != []) {
assert(
valueBar!.every(
(element) => element.value >= customLabels.first.value!),
"Valuebar value should be greater than or equal to customLabels start value");
}
assert(customLabels.length >= 2,
"At least two CustomRulerLabel should be added");

Expand Down
8 changes: 8 additions & 0 deletions lib/src/radial_gauge/pointer/radial_shape_pointer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class RadialShapePointer extends LeafRenderObjectWidget {
const RadialShapePointer({
super.key,
required this.value,
this.offset = 0,
this.color = Colors.red,
this.height = 10,
this.width = 10,
Expand All @@ -44,6 +45,11 @@ class RadialShapePointer extends LeafRenderObjectWidget {
///
final double value;

///
/// `offset` sets the offset of the [RadialShapePointer] on the [RadialGauge]
///
final double offset;

///
/// `color` sets the color of the [RadialShapePointer] on the [RadialGauge]
///
Expand Down Expand Up @@ -90,6 +96,7 @@ class RadialShapePointer extends LeafRenderObjectWidget {
return RenderRadialShapePointer(
value: value,
color: color,
offset: offset,
height: height,
width: width,
isInteractive: isInteractive,
Expand All @@ -107,6 +114,7 @@ class RadialShapePointer extends LeafRenderObjectWidget {
..setValue = value
..setRadialGauge = scope.rGauge
..setColor = color
..setOffset = offset
..setHeight = height
..setWidth = width
..onChanged = onChanged
Expand Down
Loading
Loading