214 lines
7.0 KiB
Dart
214 lines
7.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:firebase_database/firebase_database.dart';
|
|
import 'admin_keluarga.dart'; // Import file family_screen.dart
|
|
import 'tambah_satpam.dart'; // Import file tambah_satpam.dart
|
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
import 'package:ta_kebakaran_aplikasi/pages/editDataSatpam.dart';
|
|
import 'package:ta_kebakaran_aplikasi/pages/DaftarEspScreen.dart';
|
|
|
|
final databaseReference = FirebaseDatabase.instance.reference();
|
|
|
|
class HomeAdmin extends StatefulWidget {
|
|
@override
|
|
_HomeAdminState createState() => _HomeAdminState();
|
|
}
|
|
|
|
class _HomeAdminState extends State<HomeAdmin> {
|
|
int _selectedIndex = 0;
|
|
|
|
static List<Widget> _widgetOptions = <Widget>[
|
|
HomeSatpamBody(),
|
|
FamilyScreen(),
|
|
];
|
|
|
|
void _onItemTapped(int index) {
|
|
if (index == 2) {
|
|
Navigator.pushReplacementNamed(context, '/login');
|
|
return;
|
|
}
|
|
setState(() {
|
|
_selectedIndex = index;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
automaticallyImplyLeading: false,
|
|
backgroundColor: Colors.black,
|
|
title: Row(
|
|
children: [
|
|
SizedBox(width: 8),
|
|
Text(
|
|
"ADMIN",
|
|
style: TextStyle(fontSize: 20),
|
|
),
|
|
],
|
|
),
|
|
actions: <Widget>[
|
|
IconButton(
|
|
icon: Icon(Icons.warning),
|
|
onPressed: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(builder: (context) => DaftarEspScreen()),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
body: _widgetOptions.elementAt(_selectedIndex),
|
|
bottomNavigationBar: BottomNavigationBar(
|
|
backgroundColor: Colors.black,
|
|
items: [
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.home, color: Colors.white),
|
|
label: 'Home',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.group, color: Colors.white),
|
|
label: 'Penghuni',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.logout, color: Colors.white),
|
|
label: 'Log Out',
|
|
),
|
|
],
|
|
currentIndex: _selectedIndex,
|
|
selectedItemColor: Colors.blueAccent,
|
|
unselectedItemColor: Colors.white,
|
|
onTap: _onItemTapped,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class HomeSatpamBody extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.blue[900],
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: () {
|
|
TambahSatpam(context); // Panggil fungsi TambahSatpam untuk menampilkan modal bottom sheet
|
|
},
|
|
child: const Icon(Icons.add),
|
|
),
|
|
body: StreamBuilder(
|
|
stream: FirebaseFirestore.instance.collection('satpam').snapshots(),
|
|
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
return Center(
|
|
child: CircularProgressIndicator(),
|
|
);
|
|
}
|
|
if (snapshot.hasError) {
|
|
return Center(
|
|
child: Text('Error: ${snapshot.error}'),
|
|
);
|
|
}
|
|
return ListView(
|
|
children: (snapshot.data?.docs ?? []).map((DocumentSnapshot document) {
|
|
Map<String, dynamic> data = document.data() as Map<String, dynamic>;
|
|
return Container(
|
|
margin: EdgeInsets.symmetric(vertical: 5.0),
|
|
padding: EdgeInsets.all(10.0),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(10.0),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: const Color.fromARGB(255, 168, 145, 145).withOpacity(0.5),
|
|
spreadRadius: 1,
|
|
blurRadius: 2,
|
|
offset: Offset(0, 1), // changes position of shadow
|
|
),
|
|
],
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'Nama Satpam: ${data['nama']}',
|
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
|
),
|
|
SizedBox(height: 8.0),
|
|
Text(
|
|
'Nomor Satpam: ${data['nomor']}',
|
|
style: TextStyle(fontSize: 16),
|
|
),
|
|
SizedBox(height: 8.0),
|
|
Text(
|
|
'Email: ${data['email']}',
|
|
style: TextStyle(fontSize: 16),
|
|
),
|
|
SizedBox(height: 8.0),
|
|
Text(
|
|
'Password: ${data['password']}',
|
|
style: TextStyle(fontSize: 16),
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
// Aksi untuk tombol edit
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => EditSatpamScreen(documentId: document.id),
|
|
),
|
|
);
|
|
},
|
|
style: ElevatedButton.styleFrom(backgroundColor: Colors.green),
|
|
child: Text('Edit'),
|
|
),
|
|
SizedBox(width: 8.0),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
_showDeleteConfirmationDialog(context, document.id);
|
|
},
|
|
style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
|
|
child: Text('Hapus'),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}).toList(),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
void _showDeleteConfirmationDialog(BuildContext context, String documentId) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return AlertDialog(
|
|
title: Text('Konfirmasi Hapus'),
|
|
content: Text('Apakah Anda yakin ingin menghapus data ini?'),
|
|
actions: <Widget>[
|
|
TextButton(
|
|
child: Text('Batal'),
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
),
|
|
TextButton(
|
|
child: Text('Hapus'),
|
|
onPressed: () {
|
|
FirebaseFirestore.instance.collection('satpam').doc(documentId).delete();
|
|
Navigator.of(context).pop();
|
|
},
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|