57 lines
1.5 KiB
Dart
57 lines
1.5 KiB
Dart
// lib/presentation/widgets/onboarding_indicator_painter.dart
|
|
import 'dart:math';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:proxibuy/core/config/app_colors.dart';
|
|
|
|
|
|
class OnboardingIndicatorPainter extends CustomPainter {
|
|
final int pageCount;
|
|
final int currentPage;
|
|
final Color activeColor;
|
|
final Color inactiveColor;
|
|
final double strokeWidth;
|
|
|
|
OnboardingIndicatorPainter({
|
|
required this.pageCount,
|
|
required this.currentPage,
|
|
this.activeColor = AppColors.primary,
|
|
this.inactiveColor = AppColors.unselected,
|
|
this.strokeWidth = 6.0,
|
|
});
|
|
|
|
@override
|
|
void paint(Canvas canvas, Size size) {
|
|
final center = Offset(size.width / 2, size.height / 2);
|
|
final radius = min(size.width, size.height) / 2;
|
|
|
|
const double gapInDegrees = 30.0;
|
|
const double gapInRadians = gapInDegrees * (pi / 180);
|
|
|
|
const double arcAngle = (pi / 2) - gapInRadians;
|
|
|
|
final startAngles = [-pi / 2, 0.0, pi / 2, pi];
|
|
|
|
for (int i = 0; i < pageCount; i++) {
|
|
final paint = Paint()
|
|
..color = (i == currentPage) ? activeColor : inactiveColor
|
|
..style = PaintingStyle.stroke
|
|
..strokeWidth = strokeWidth
|
|
..strokeCap = StrokeCap.round;
|
|
|
|
final correctedStartAngle = startAngles[i] + (gapInRadians / 2);
|
|
|
|
canvas.drawArc(
|
|
Rect.fromCircle(center: center, radius: radius),
|
|
correctedStartAngle,
|
|
arcAngle,
|
|
false,
|
|
paint,
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
bool shouldRepaint(covariant CustomPainter oldDelegate) {
|
|
return true;
|
|
}
|
|
} |