didvan-app/lib/views/widgets/didvan/time_sky_animation.dart

96 lines
3.6 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'dart:math';
import 'package:flutter/material.dart';
class TimeSkyAnimation extends StatelessWidget {
final int hour; // ساعت بین ۰ تا ۲۳
const TimeSkyAnimation({Key? key, required this.hour}) : super(key: key);
bool get _isDay => hour >= 6 && hour < 18; // فرض می‌کنیم روز بین ۶ صبح تا ۶ عصر است
double _getYofMoon(double x) {
// فرمول حرکت قوسی شکل
double r = 12;
double a = -12;
return sqrt(max(0, r * r - (x + a) * (x + a)));
}
@override
Widget build(BuildContext context) {
// نرمال‌سازی ساعت برای حرکت نرم‌تر در انیمیشن (۰ تا ۲۴)
final double hValue = hour.toDouble();
return Container(
height: 120, // ارتفاع کانتینر آسمان
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(24), // گردی گوشه‌ها مشابه دیزاین دیدوان
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, 4),
)
],
),
clipBehavior: Clip.antiAlias,
child: Stack(
children: [
// پس‌زمینه گرادیانت متحرک آسمان
AnimatedPositioned(
duration: const Duration(milliseconds: 500),
top: hValue * -84, // حرکت عمودی گرادیانت بر اساس ساعت
left: hValue * -84, // حرکت افقی گرادیانت
child: Container(
width: 2400, // عرض زیاد برای حرکت روان گرادیانت
height: 2400,
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Color(0xff0d0221), // نیمه شب (تاریک‌ترین)
Color(0xff292929), // بامداد
Color(0xffFAD7A3), // طلوع
Color(0xff2ED4F9), // ظهر (روشن‌ترین)
Color(0xff2ED4F9), // بعد از ظهر
Color(0xffFAD7A3), // غروب
Color(0xff292929), // اوایل شب
Color(0xff0d0221), // نیمه شب
],
),
),
),
),
// خورشید یا ماه
AnimatedPositioned(
duration: const Duration(milliseconds: 500),
bottom: _getYofMoon(hValue > 12 ? hValue - 12 : hValue) * 4,
left: (hValue + 1) * 12, // حرکت افقی
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 500),
switchInCurve: Curves.easeInOut,
switchOutCurve: Curves.easeInOut,
transitionBuilder: (Widget child, Animation<double> animation) {
return FadeTransition(opacity: animation, child: ScaleTransition(scale: animation, child: child));
},
child: _isDay
? Image.asset(
'lib/assets/images/sky/sun.png',
key: const ValueKey(1),
width: 80,
height: 80,
)
: Image.asset(
'lib/assets/images/sky/Moon.png',
key: const ValueKey(2),
width: 80,
height: 80,
),
),
),
],
),
);
}
}