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

Fix issue hard coded values in radial widget painter #247

Closed
wants to merge 1 commit into from
Closed
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
40 changes: 40 additions & 0 deletions example/lib/radial_gauge_custom_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:flutter/material.dart';
import 'package:geekyants_flutter_gauges/geekyants_flutter_gauges.dart';

///
/// The following code is a Simple Example of [RadialGauge] Widget with custom widgets.
///
class RadialGaugeCustomWidget extends StatefulWidget {
const RadialGaugeCustomWidget({super.key});

@override
State<RadialGaugeCustomWidget> createState() =>
_RadialGaugeCustomWidgetState();
}

class _RadialGaugeCustomWidgetState extends State<RadialGaugeCustomWidget> {
@override
Widget build(BuildContext context) {
return const Scaffold(
backgroundColor: Colors.white,
body: RadialGauge(
track: RadialTrack(
color: Colors.grey,
start: 0,
end: 100,
thickness: 40,
),
widgetPointer: [
RadialWidgetPointer(
value: 35.5,
child: Text("35.5"),
),
RadialWidgetPointer(
value: 78.2,
child: Text("78.2"),
),
],
),
);
}
}
26 changes: 17 additions & 9 deletions lib/src/radial_gauge/pointer/radial_widget_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,32 @@ class RenderRadialWidgetPointer extends RenderProxyBox {
double gaugeStart = _radialGauge.track.start;
double gaugeEnd = _radialGauge.track.end;

// final center = Offset(offset.dx, offset.dy);
double containerWidth = constraints.maxWidth;
double containerHeight = constraints.maxHeight;
double containerShortestSide = min(containerWidth, containerHeight);
final childSize = child?.computeDryLayout(constraints);
final childOffsetX = (childSize?.width ?? 0.0) / 2;
final childOffsetY = (childSize?.height ?? 0.0) / 2;

final center = Offset(
1440 * _radialGauge.xCenterCoordinate -
2 * _radialGauge.track.thickness,
900 * _radialGauge.yCenterCoordinate - _radialGauge.track.thickness);
containerWidth * _radialGauge.xCenterCoordinate + offset.dx,
containerHeight * _radialGauge.yCenterCoordinate + offset.dy);

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 circlePointerOffset =
(900 / 2 - _radialGauge.track.thickness) * _radialGauge.radiusFactor;
(containerShortestSide / 2 - _radialGauge.track.thickness) *
_radialGauge.radiusFactor;

double circlePointerEndX =
center.dx + circlePointerOffset * cos(angle) - childOffsetX;
double circlePointerEndY =
center.dy + circlePointerOffset * sin(angle) - childOffsetY;

double circlePointerEndX = center.dx + circlePointerOffset * cos(angle);
double circlePointerEndY = center.dy + circlePointerOffset * sin(angle);
// canvas.drawCircle(Offset(circlePointerEndX, circlePointerEndY), 30,
// Paint()..color = Colors.red);
super.paint(context, Offset(circlePointerEndX, circlePointerEndY));
}

Expand Down