231 lines
8.3 KiB
Dart
231 lines
8.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../../../core/theme/app_theme.dart';
|
|
|
|
/// دیالوگِ استریکِ روزانه به سبکِ دولینگو: شعلهی بزرگ + شمارِ روز + نوارِ
|
|
/// پیشرفتِ هفتگی بهسویِ پاداشِ ۵۰۰ سکهای + دکمهی دریافت.
|
|
class StreakDialog extends StatelessWidget {
|
|
final int streak;
|
|
final int best;
|
|
final bool ready;
|
|
final int nextReward;
|
|
final VoidCallback onClaim;
|
|
|
|
const StreakDialog({
|
|
super.key,
|
|
required this.streak,
|
|
required this.best,
|
|
required this.ready,
|
|
required this.nextReward,
|
|
required this.onClaim,
|
|
});
|
|
|
|
static Future<void> show(
|
|
BuildContext context, {
|
|
required int streak,
|
|
required int best,
|
|
required bool ready,
|
|
required int nextReward,
|
|
required VoidCallback onClaim,
|
|
}) {
|
|
return showDialog(
|
|
context: context,
|
|
barrierColor: Colors.black.withValues(alpha: 0.7),
|
|
builder: (_) => StreakDialog(
|
|
streak: streak,
|
|
best: best,
|
|
ready: ready,
|
|
nextReward: nextReward,
|
|
onClaim: onClaim,
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// پیشرفت تا پاداشِ هفتگی (۷تایی). اگر روی مضربِ ۷ باشد، کاملِ ۷.
|
|
int weekProg = streak % 7;
|
|
if (weekProg == 0 && streak > 0) weekProg = 7;
|
|
final toBonus = 7 - weekProg;
|
|
|
|
return Dialog(
|
|
backgroundColor: Colors.transparent,
|
|
insetPadding: const EdgeInsets.symmetric(horizontal: 28, vertical: 40),
|
|
child: Container(
|
|
padding: const EdgeInsets.fromLTRB(20, 24, 20, 20),
|
|
decoration: BoxDecoration(
|
|
gradient: const LinearGradient(
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
colors: [AppColors.lapisMid, AppColors.lapisLo],
|
|
),
|
|
borderRadius: BorderRadius.circular(24),
|
|
border: Border.all(color: AppColors.gold, width: 1.8),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: const Color(0xFFFF7A1A).withValues(alpha: 0.25),
|
|
blurRadius: 26),
|
|
],
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
// شعلهی بزرگ با عددِ استریک.
|
|
SizedBox(
|
|
height: 118,
|
|
child: Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
const Icon(Icons.local_fire_department,
|
|
color: Color(0xFFFF7A1A), size: 118),
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 22),
|
|
child: Text(
|
|
'$streak',
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 44,
|
|
fontWeight: FontWeight.w900,
|
|
shadows: [Shadow(color: Colors.black45, blurRadius: 6)],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
streak > 0 ? '$streak روز پیاپی!' : 'زنجیرهات رو شروع کن',
|
|
style: const TextStyle(
|
|
color: AppColors.gold,
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.bold),
|
|
),
|
|
const SizedBox(height: 2),
|
|
Text('بهترین رکورد: $best روز',
|
|
style: const TextStyle(color: Colors.white54, fontSize: 12)),
|
|
const SizedBox(height: 18),
|
|
|
|
// نوارِ پیشرفتِ هفتگی.
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
|
|
decoration: BoxDecoration(
|
|
color: Colors.black.withValues(alpha: 0.22),
|
|
borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: AppColors.goldFaint),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
for (var i = 0; i < 7; i++) _dayCell(i, weekProg),
|
|
],
|
|
),
|
|
const SizedBox(height: 10),
|
|
Text(
|
|
toBonus == 0
|
|
? '🎉 امروز پاداشِ هفتگی +۵۰۰ سکه!'
|
|
: '$toBonus روز تا پاداشِ هفتگی (+۵۰۰ سکه)',
|
|
style: const TextStyle(color: Colors.white70, fontSize: 12),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 18),
|
|
|
|
// دکمهی دریافت / وضعیتِ دریافتشده.
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor:
|
|
ready ? AppColors.success : AppColors.lapisHi,
|
|
padding: const EdgeInsets.symmetric(vertical: 13),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(14),
|
|
side: const BorderSide(color: AppColors.gold, width: 1.3),
|
|
),
|
|
),
|
|
onPressed: ready
|
|
? () {
|
|
Navigator.pop(context);
|
|
onClaim();
|
|
}
|
|
: null,
|
|
child: ready
|
|
? Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
const Text('دریافت هدیه',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 15,
|
|
fontWeight: FontWeight.bold)),
|
|
const SizedBox(width: 8),
|
|
const Icon(Icons.monetization_on,
|
|
color: AppColors.gold, size: 20),
|
|
const SizedBox(width: 3),
|
|
Text('+$nextReward',
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 15,
|
|
fontWeight: FontWeight.bold)),
|
|
],
|
|
)
|
|
: const Text('فردا دوباره سر بزن ✓',
|
|
style: TextStyle(
|
|
color: Colors.white70,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.bold)),
|
|
),
|
|
),
|
|
const SizedBox(height: 6),
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('بستن',
|
|
style: TextStyle(color: Colors.white38, fontSize: 13)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
// یک خانهی روز در نوارِ هفتگی. خانههای پرشده تا weekProg شعله دارند؛ خانهی
|
|
// پایانی (روزِ هفتم) پاداشِ سکهای است.
|
|
Widget _dayCell(int i, int weekProg) {
|
|
final done = i < weekProg;
|
|
final isBonus = i == 6;
|
|
final Color bg = done
|
|
? (isBonus ? AppColors.gold : const Color(0xFFFF7A1A))
|
|
: AppColors.lapisHi;
|
|
return Column(
|
|
children: [
|
|
Container(
|
|
width: 32,
|
|
height: 32,
|
|
decoration: BoxDecoration(
|
|
color: bg.withValues(alpha: done ? 1 : 0.35),
|
|
shape: BoxShape.circle,
|
|
border: Border.all(
|
|
color: done ? AppColors.gold : Colors.white24,
|
|
width: done ? 1.4 : 1,
|
|
),
|
|
),
|
|
child: Icon(
|
|
isBonus
|
|
? Icons.monetization_on
|
|
: (done ? Icons.local_fire_department : Icons.circle_outlined),
|
|
color: done ? Colors.white : Colors.white38,
|
|
size: isBonus ? 18 : 16,
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text('${i + 1}',
|
|
style: const TextStyle(color: Colors.white38, fontSize: 10)),
|
|
],
|
|
);
|
|
}
|
|
}
|