93 lines
3.2 KiB
Dart
93 lines
3.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../providers/history_provider.dart';
|
|
|
|
class ControlHistoryPage extends StatefulWidget {
|
|
const ControlHistoryPage({super.key});
|
|
|
|
@override
|
|
State<ControlHistoryPage> createState() => _ControlHistoryPageState();
|
|
}
|
|
|
|
class _ControlHistoryPageState extends State<ControlHistoryPage> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
context.read<HistoryProvider>().startControlListener();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final provider = context.watch<HistoryProvider>();
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Histori Kontrol'),
|
|
actions: [
|
|
IconButton(
|
|
icon: const Icon(Icons.delete_outline, color: Colors.redAccent),
|
|
tooltip: 'Hapus Histori',
|
|
onPressed: () {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: const Text('Hapus Histori'),
|
|
content: const Text('Apakah Anda yakin ingin menghapus semua data histori kontrol? Tindakan ini tidak dapat dibatalkan.'),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('Batal'),
|
|
),
|
|
TextButton(
|
|
onPressed: () async {
|
|
Navigator.pop(context);
|
|
try {
|
|
await context.read<HistoryProvider>().clearControlHistory();
|
|
if (context.mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('Histori kontrol berhasil dihapus')),
|
|
);
|
|
}
|
|
} catch (e) {
|
|
if (context.mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text('Gagal menghapus histori: $e')),
|
|
);
|
|
}
|
|
}
|
|
},
|
|
child: const Text('Hapus', style: TextStyle(color: Colors.red)),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
body: provider.controlHistory.isEmpty
|
|
? const Center(
|
|
child: Text(
|
|
'Belum ada data histori kontrol.',
|
|
style: TextStyle(color: Colors.grey),
|
|
),
|
|
)
|
|
: ListView.builder(
|
|
itemCount: provider.controlHistory.length,
|
|
itemBuilder: (context, index) {
|
|
final item = provider.controlHistory[index];
|
|
|
|
return Card(
|
|
child: ListTile(
|
|
title: Text(item.action),
|
|
subtitle: Text('${item.source}\n${item.timestamp}'),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|