class WaitingClock extends StatefulWidget {
final Color outerRingColor;
final Color innerRingColor;
final Color handColor;
final bool smoothAnimation;
final double size;
final double strokeWidth;
const WaitingClock({
Key? key,
this.outerRingColor = const Color(0xFF8E44AD), // Пурпурный цвет как на изображении
this.innerRingColor = Colors.white,
this.handColor = const Color(0xFFF1C40F), // Желтый цвет как на изображении
this.smoothAnimation = true, // По умолчанию плавная анимация
this.size = 100.0,
this.strokeWidth = 10.0,
}) : super(key: key);
@override
State createState() => _WaitingClockState();
}
class _WaitingClockState extends State with SingleTickerProviderStateMixin {
late AnimationController _controller;
class ClockPainter extends CustomPainter {
final double progress;
final Color outerRingColor;
final Color innerRingColor;
final Color handColor;
final double strokeWidth;
how to add shadow to clock hand to make more 3d look
Assistant
Below is a quick, lightweight trick that already looks surprisingly “3-D”:
Draw a blurred, slightly thicker line a few pixels below the real hand (this is the shadow).
Draw the real hand on top.
Because Canvas.drawLine() is fast, you don’t need an expensive shader or a complex Path—just one extra Paint with a blur (MaskFilter) and a small offset.
dart
// at the top of ClockPainter
import 'dart:ui' as ui; // for convertRadiusToSigma helper
// …
@override
void paint(Canvas canvas, Size size) {
final center = Offset(size.width / 2, size.height / 2);
final radius = min(size.width, size.height) / 2;
// …(outer ring, background, minute marks)…
// 1️⃣ ───── CALCULATE END POINT OF THE HAND ──────────
final handAngle = 2 * pi * progress - pi / 2;
final handStart = center;
final handEnd = Offset(
center.dx + (radius - strokeWidth * 4.5) * cos(handAngle),
center.dy + (radius - strokeWidth * 4.5) * sin(handAngle),
);
// 2️⃣ ───── SHADOW PAINT ────────────────────────────
final shadowPaint = Paint()
..color = Colors.black.withOpacity(0.35) // a soft dark tint
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round
..strokeWidth = strokeWidth / 4 + 2 // slightly thicker than the real hand
..maskFilter = ui.MaskFilter.blur( // gaussian blur
BlurStyle.normal,
_sigma(4), // 4 px blur radius
);
// Offset the line 2 px down & right so it’s visible
const shadowOffset = Offset(2, 2);
canvas.drawLine(
handStart + shadowOffset,
handEnd + shadowOffset,
shadowPaint,
);
// 3️⃣ ───── REAL HAND ───────────────────────────────
final handPaint = Paint()
..color = handColor
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round
..strokeWidth = strokeWidth / 4;
canvas.drawLine(handStart, handEnd, handPaint);
}
// Helper that Flutter itself uses internally.
double _sigma(double radius) => radius * 0.57735 + 0.5;
What the parameters do
• shadowOffset – distance you want the shadow to “drop”.
• strokeWidth / 4 + 2 – makes the shadow slightly wider than the actual hand so it peeks out on the sides.
• _sigma(4) – converts a 4-pixel blur radius to the sigma value the engine expects.
Feel free to tweak the blur radius, opacity, or offset for a bolder or softer effect. 🎨