121 lines
4.1 KiB
Dart
121 lines
4.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
|
|
void TambahKeluarga(BuildContext context) {
|
|
String norumah = '';
|
|
String namakepala = '';
|
|
String nomortelepon = '';
|
|
String noalat = '';
|
|
String idnomer = '';
|
|
|
|
showModalBottomSheet(
|
|
isScrollControlled: true,
|
|
backgroundColor: Colors.white,
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return SingleChildScrollView(
|
|
child: Padding(
|
|
padding: EdgeInsets.only(
|
|
top: 20,
|
|
right: 20,
|
|
left: 20,
|
|
bottom: MediaQuery.of(context).viewInsets.bottom + 20,
|
|
),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Center(
|
|
child: Text(
|
|
"Tambah Data Penghuni",
|
|
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
TextField(
|
|
onChanged: (value) {
|
|
norumah = value;
|
|
},
|
|
decoration: const InputDecoration(
|
|
labelText: "No Rumah",
|
|
hintText: "A0000",
|
|
),
|
|
),
|
|
TextField(
|
|
onChanged: (value) {
|
|
namakepala = value;
|
|
},
|
|
decoration: const InputDecoration(
|
|
labelText: "Nama Kepala Keluarga",
|
|
hintText: "Bapak/Ibu",
|
|
),
|
|
),
|
|
TextField(
|
|
onChanged: (value) {
|
|
nomortelepon = value;
|
|
},
|
|
decoration: const InputDecoration(
|
|
labelText: "No Telepon",
|
|
hintText: "Nomor Telepon Penghuni",
|
|
),
|
|
),
|
|
TextField(
|
|
onChanged: (value) {
|
|
idnomer = value;
|
|
},
|
|
decoration: const InputDecoration(
|
|
labelText: "No ID",
|
|
hintText: "ID Nomer Penghuni Rumah",
|
|
),
|
|
),
|
|
TextField(
|
|
onChanged: (value) {
|
|
noalat = value;
|
|
},
|
|
decoration: const InputDecoration(
|
|
labelText: "Nomor Seri Alat",
|
|
hintText: "Nomor Seri ESP",
|
|
),
|
|
),
|
|
const SizedBox(height: 20,),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
if (norumah.isEmpty || namakepala.isEmpty || nomortelepon.isEmpty || noalat.isEmpty || idnomer.isEmpty) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(
|
|
content: Text('Data Wajib Terisi Semua Dengan Benar'),
|
|
),
|
|
);
|
|
Navigator.pop(context);
|
|
} else {
|
|
FirebaseFirestore.instance.collection('Penghuni').add({
|
|
'norumah': norumah,
|
|
'namakepala': namakepala,
|
|
'nomortelepon': nomortelepon,
|
|
'noalat': noalat,
|
|
'idnomer': idnomer,
|
|
}).then((_) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(
|
|
content: Text('Data keluarga berhasil ditambahkan'),
|
|
),
|
|
);
|
|
Navigator.pop(context);
|
|
}).catchError((error) {
|
|
print('Error adding family data: $error');
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(
|
|
content: Text('Gagal menambahkan data keluarga'),
|
|
),
|
|
);
|
|
});
|
|
}
|
|
},
|
|
child: const Text("Tambah"),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
} |