215 lines
6.2 KiB
Dart
215 lines
6.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class OpenCelenganModal {
|
|
/// Entry point utama — cek target dulu, lalu arahkan ke flow yang sesuai
|
|
static void show(
|
|
BuildContext context, {
|
|
required bool targetTercapai,
|
|
required VoidCallback onKonfirmasiBuka,
|
|
}) {
|
|
if (targetTercapai) {
|
|
_showTargetTercapai(context, onKonfirmasiBuka: onKonfirmasiBuka);
|
|
} else {
|
|
_showBelumTercapaiStep1(context, onKonfirmasiBuka: onKonfirmasiBuka);
|
|
}
|
|
}
|
|
|
|
// ─── Flow 1: Target sudah tercapai ───────────────────────────────────────
|
|
|
|
static void _showTargetTercapai(
|
|
BuildContext context, {
|
|
required VoidCallback onKonfirmasiBuka,
|
|
}) {
|
|
showDialog(
|
|
context: context,
|
|
barrierDismissible: false,
|
|
builder: (_) => _BaseDialog(
|
|
title:
|
|
'Selamat!! 🎉\nTargetmu Telah Tercapai,\nklik Buka untuk membuka celengan',
|
|
labelBatal: 'Batal',
|
|
labelLanjut: 'Buka',
|
|
onLanjut: () {
|
|
Navigator.of(context).pop();
|
|
onKonfirmasiBuka();
|
|
},
|
|
lanjutColor: const Color(0xFF5B9BD5),
|
|
),
|
|
);
|
|
}
|
|
|
|
// ─── Flow 2: Target belum tercapai — Step 1 ──────────────────────────────
|
|
|
|
static void _showBelumTercapaiStep1(
|
|
BuildContext context, {
|
|
required VoidCallback onKonfirmasiBuka,
|
|
}) {
|
|
showDialog(
|
|
context: context,
|
|
barrierDismissible: false,
|
|
builder: (_) => _BaseDialog(
|
|
title: 'Anda Belum Mencapai Target,\nYakin ingin membuka celengan?',
|
|
labelBatal: 'Batal',
|
|
labelLanjut: 'Lanjut',
|
|
onLanjut: () {
|
|
Navigator.of(context).pop();
|
|
_showYakinStep2(context, onKonfirmasiBuka: onKonfirmasiBuka);
|
|
},
|
|
lanjutColor: const Color(0xFFE09B3D),
|
|
),
|
|
);
|
|
}
|
|
|
|
// ─── Flow 2: Step 2 — Yakin / Tidak Yakin ────────────────────────────────
|
|
|
|
static void _showYakinStep2(
|
|
BuildContext context, {
|
|
required VoidCallback onKonfirmasiBuka,
|
|
}) {
|
|
showDialog(
|
|
context: context,
|
|
barrierDismissible: false,
|
|
builder: (_) => _BaseDialog(
|
|
title: 'Seberapa yakin anda untuk\nmembuka celengan?',
|
|
labelBatal: 'Tidak Yakin',
|
|
labelLanjut: 'Yakin',
|
|
onLanjut: () {
|
|
Navigator.of(context).pop();
|
|
_showKonfirmasiAkhirStep3(
|
|
context,
|
|
onKonfirmasiBuka: onKonfirmasiBuka,
|
|
);
|
|
},
|
|
lanjutColor: const Color(0xFFE09B3D),
|
|
),
|
|
);
|
|
}
|
|
|
|
// ─── Flow 2: Step 3 — Konfirmasi akhir ───────────────────────────────────
|
|
|
|
static void _showKonfirmasiAkhirStep3(
|
|
BuildContext context, {
|
|
required VoidCallback onKonfirmasiBuka,
|
|
}) {
|
|
showDialog(
|
|
context: context,
|
|
barrierDismissible: false,
|
|
builder: (_) => _BaseDialog(
|
|
title: 'Saya tanya sekali lagi apakah kamu benar ingin membuka?',
|
|
labelBatal: 'Batal',
|
|
labelLanjut: 'Buka',
|
|
onLanjut: () {
|
|
Navigator.of(context).pop();
|
|
onKonfirmasiBuka();
|
|
},
|
|
lanjutColor: const Color(0xFFE09B3D),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
// ─── Widget: Dialog dasar (teks + 2 tombol) ──────────────────────────────────
|
|
|
|
class _BaseDialog extends StatelessWidget {
|
|
final String title;
|
|
final String labelBatal;
|
|
final String labelLanjut;
|
|
final VoidCallback onLanjut;
|
|
final Color lanjutColor;
|
|
|
|
const _BaseDialog({
|
|
required this.title,
|
|
required this.labelBatal,
|
|
required this.labelLanjut,
|
|
required this.onLanjut,
|
|
required this.lanjutColor,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Dialog(
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
|
backgroundColor: Colors.white,
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 32),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(
|
|
title,
|
|
textAlign: TextAlign.center,
|
|
style: const TextStyle(
|
|
fontSize: 17,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.black87,
|
|
height: 1.4,
|
|
),
|
|
),
|
|
const SizedBox(height: 28),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: _DialogButton(
|
|
label: labelBatal,
|
|
color: Colors.grey.shade300,
|
|
textColor: Colors.black87,
|
|
onTap: () => Navigator.of(context).pop(),
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: _DialogButton(
|
|
label: labelLanjut,
|
|
color: lanjutColor,
|
|
textColor: Colors.white,
|
|
onTap: onLanjut,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
// ─── Widget: Tombol reusable ──────────────────────────────────────────────────
|
|
|
|
class _DialogButton extends StatelessWidget {
|
|
final String label;
|
|
final Color color;
|
|
final Color textColor;
|
|
final VoidCallback? onTap;
|
|
|
|
const _DialogButton({
|
|
required this.label,
|
|
required this.color,
|
|
required this.textColor,
|
|
this.onTap,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GestureDetector(
|
|
onTap: onTap,
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(vertical: 14),
|
|
decoration: BoxDecoration(
|
|
color: color,
|
|
borderRadius: BorderRadius.circular(14),
|
|
),
|
|
child: Center(
|
|
child: Text(
|
|
label,
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
color: textColor,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|