-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(custom-gauge): implementation of custom arc gauge
- Loading branch information
1 parent
0dbef94
commit 90bd834
Showing
3 changed files
with
75 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export 'custom_gauge_painter.dart'; |