kelola penyewa dan beberapa error fix

This commit is contained in:
Andreas Malvino
2025-07-09 16:01:10 +07:00
parent 0423c2fdf9
commit 47766bbdda
90 changed files with 2705 additions and 1555 deletions

View File

@ -570,8 +570,34 @@ class WargaSewaView extends GetView<WargaSewaController> {
if ((rental['status'] ?? '').toString().toUpperCase() ==
'MENUNGGU PEMBAYARAN' &&
rental['updated_at'] != null)
CountdownTimerWidget(
updatedAt: DateTime.parse(rental['updated_at']),
Builder(
builder: (context) {
final updatedAtStr = rental['updated_at'];
debugPrint('DEBUG status: ${rental['status']}');
debugPrint('DEBUG updated_at: $updatedAtStr');
if (updatedAtStr != null) {
try {
final updatedAt = DateTime.parse(updatedAtStr);
debugPrint(
'DEBUG parsed updated_at: ${updatedAt.toIso8601String()}',
);
return CountdownTimerWidget(
updatedAt: updatedAt,
);
} catch (e) {
debugPrint('ERROR parsing updated_at: $e');
return Text(
'Format tanggal salah',
style: TextStyle(
color: Colors.red,
fontSize: 12,
),
);
}
}
return SizedBox.shrink();
},
),
],
),
@ -1856,32 +1882,46 @@ class CountdownTimerWidget extends StatefulWidget {
class _CountdownTimerWidgetState extends State<CountdownTimerWidget> {
late Duration remaining;
Timer? timer;
@override
void initState() {
super.initState();
debugPrint(
'CountdownTimerWidget initialized with updatedAt: ${widget.updatedAt}',
);
updateRemaining();
timer = Timer.periodic(
const Duration(seconds: 1),
(_) => updateRemaining(),
);
print('DEBUG updated_at: ${widget.updatedAt}');
}
void updateRemaining() {
final now = DateTime.now();
final deadline = widget.updatedAt.add(const Duration(hours: 1));
debugPrint('Current time: $now');
debugPrint('Deadline: $deadline');
setState(() {
remaining = deadline.difference(now);
debugPrint('Remaining time: ${remaining.inSeconds} seconds');
if (remaining.isNegative) {
debugPrint('Countdown expired, setting to zero');
remaining = Duration.zero;
timer?.cancel();
widget.onTimeout?.call();
if (widget.onTimeout != null) {
debugPrint('Calling onTimeout callback');
widget.onTimeout?.call();
}
}
});
}
@override
void dispose() {
debugPrint('CountdownTimerWidget disposed');
timer?.cancel();
super.dispose();
}
@ -1891,9 +1931,15 @@ class _CountdownTimerWidgetState extends State<CountdownTimerWidget> {
if (remaining.inSeconds <= 0) {
return Text('Waktu habis', style: TextStyle(color: Colors.red));
}
final h = remaining.inHours;
final m = remaining.inMinutes % 60;
final s = remaining.inSeconds % 60;
final timeString =
'${h.toString().padLeft(2, '0')}:${m.toString().padLeft(2, '0')}:${s.toString().padLeft(2, '0')}';
debugPrint('Rendering countdown: $timeString');
return Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: BoxDecoration(
@ -1907,7 +1953,7 @@ class _CountdownTimerWidgetState extends State<CountdownTimerWidget> {
Icon(Icons.timer_outlined, size: 14, color: Colors.red),
const SizedBox(width: 4),
Text(
'Bayar dalam ${h.toString().padLeft(2, '0')}:${m.toString().padLeft(2, '0')}:${s.toString().padLeft(2, '0')}',
'Bayar dalam $timeString',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,