Skip to content

Commit

Permalink
feat(custom-gauge): implementation of custom arc gauge
Browse files Browse the repository at this point in the history
  • Loading branch information
Khushboo1702 authored and TusharFA committed May 3, 2024
1 parent 0dbef94 commit 90bd834
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/fa_flutter_ui_kit.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
library fa_flutter_ui_kit;

export 'src/app/index.dart';
export 'src/config/index.dart';
export 'src/constants/index.dart';
export 'src/core/location_info/index.dart';
export 'src/data/index.dart';
export 'src/modules/day_start/index.dart';
export 'src/modules/custom_gauge/index.dart';
export 'src/modules/day_end/index.dart';
export 'src/modules/day_start/index.dart';
export 'src/modules/index.dart';
export 'src/navigator/index.dart';
export 'src/utils/index.dart';
export 'src/widgets/index.dart';
export 'src/app/index.dart';
export 'src/core/location_info/index.dart';
export 'src/widgets/common/multi_select_items/multi_select_flutter.dart';
export 'src/widgets/index.dart';
69 changes: 69 additions & 0 deletions lib/src/modules/custom_gauge/custom_gauge_painter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import 'dart:math';

import 'package:flutter/material.dart';

class CustomGaugePainter extends CustomPainter {
CustomGaugePainter({
required this.currentValue,
required this.targetValue,
required this.gaugeColor,
required this.backgroundColor,
});

final double currentValue;
final double targetValue;
final Color gaugeColor;
final Color backgroundColor;

@override
void paint(Canvas canvas, Size size) {
final paint = Paint()
..style = PaintingStyle.stroke
..strokeWidth = 40;

final center = Offset(size.width / 2, size.height);

paint.color = backgroundColor;
canvas.drawArc(
Rect.fromCircle(center: center, radius: 100),
pi,
pi,
false,
paint,
);

paint.color = gaugeColor;
final sweepAngle = (pi * currentValue) / targetValue;
canvas.drawArc(
Rect.fromCircle(center: center, radius: 100),
pi,
sweepAngle,
false,
paint,
);

final startLabelPainter = TextPainter(
text: TextSpan(
text: '0', style: TextStyle(color: Colors.black, fontSize: 16)),
textDirection: TextDirection.ltr,
);
startLabelPainter
..layout()
..paint(canvas, Offset(center.dx - 110, size.height + 10));

final targetLabelPainter = TextPainter(
text: TextSpan(
text: targetValue.toString(),
style: TextStyle(color: Colors.black, fontSize: 16),
),
textDirection: TextDirection.ltr,
);
targetLabelPainter.layout();
targetLabelPainter.paint(canvas, Offset(center.dx + 80, size.height + 10));
}

@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return true;
}
}
1 change: 1 addition & 0 deletions lib/src/modules/custom_gauge/index.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'custom_gauge_painter.dart';

0 comments on commit 90bd834

Please sign in to comment.