class _ChildListState extends State<ChildList>
with SingleTickerProviderStateMixin {
DatabaseHelper? _hastaListe;
late List<HastaListeModel> kidList;
TextEditingController? adsoyad;
TextEditingController? dogumTarihi;
TextEditingController? dogumTarihigizli;
String? cinsiyet;
late AnimationController _controller;
late Animation<double> _animation;
final formKey = GlobalKey<FormState>();
static String? platform;
DateTime? _dogumTarihi;
double? anneboy;
double? bababoy;
Color? maleColor;
Color? femaleColor;
double? femaleOpacity;
double? maleOpacity;
@override
void initState() {
_controller = AnimationController(
vsync: this, duration: Duration(milliseconds: 1000));
_animation = Tween(begin: 0.0, end: 1.0).animate(_controller);
platformSelect();
super.initState();
adsoyad = TextEditingController();
dogumTarihi = TextEditingController();
dogumTarihigizli = TextEditingController();
kidList = [];
_hastaListe = DatabaseHelper();
cinsiyet = null;
femaleOpacity = 1;
maleOpacity = 1;
}
void platformSelect() {
if (Platform.isIOS) {
setState(() {
platform = 'OS';
});
} else if (Platform.isAndroid) {
setState(() {
platform = 'Android';
});
}
}
@override
void dispose() {
_controller.dispose();
adsoyad?.dispose();
dogumTarihi?.dispose();
dogumTarihigizli?.dispose();
// TODO: implement dispose
super.dispose();
}
@override
Widget build(BuildContext context) {
_controller.forward();
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () => yenihastaEkle(context),
child: Icon(Icons.add),
),
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
title: const Text(
"Çocuk Listesi",
style: TextStyle(color: Colors.black),
),
),
body: FutureBuilder(
future: _hastaListe!.hastaListesi(),
builder: (context, AsyncSnapshot<List<HastaListeModel>> snapshot) {
if (snapshot.hasData) {
kidList = snapshot.data!;
return ListView.builder(
itemCount: kidList.length,
itemBuilder: (context, index) {
return Slidable(
// The end action pane is the one at the right or the bottom side.
endActionPane: ActionPane(
motion: const ScrollMotion(),
children: [
SlidableAction(
onPressed: (context) {
_hastaListe!
.hastaSil(snapshot.data![index].hastaID!);
_controller.reverse();
setState(() {});
},
backgroundColor: Colors.red,
foregroundColor: Colors.white,
icon: Icons.delete,
label: 'Sil',
),
],
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: FadeTransition(
opacity: _animation,
child: ListTile(
leading: const Icon(Icons.girl_sharp),
title: Text(kidList[index].hastaAdSoyad ?? ""),
trailing: Text(kidList[index].cinsiyet ?? ""),
),
),
));
});
} else {
return const Center(
child: CircularProgressIndicator(),
);
}
}),
);
}
Widget ColumnDate() {
return Column(
children: [
Formverileri(
benkimim: 'tarih',
labeltext: "Doğum Tarihi",
controller: dogumTarihi,
onTap: () {
//FocusScope.of(context).requestFocus(FocusNode());
if (platform == 'OS') {
CalenderChooser()
.getDateCupertino(context, dogumTarihi!, dogumTarihigizli!);
} else {
CalenderChooser().getDateAndroid(
ctx: context,
controller: dogumTarihi,
controllerGizli: dogumTarihigizli);
}
},
),
Visibility(
visible: false,
child: Formverileri(
controller: dogumTarihigizli!,
benkimim: 'tarihgizli',
)),
],
);
}
yenihastaEkle(BuildContext context) async {
await Future.delayed(const Duration(milliseconds: 50));
adsoyad!.clear();
dogumTarihi!.clear();
dogumTarihigizli!.clear();
return showDialog(
barrierDismissible: true,
context: context,
builder: (context) {
return StatefulBuilder(
builder: (BuildContext context, StateSetter setstate) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30)),
alignment: Alignment.center,
contentPadding: const EdgeInsets.all(30),
title: const Text("Yeni Hasta Ekle"),
content: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Form(
key: formKey,
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
controller: adsoyad,
decoration:
const InputDecoration(labelText: "Ad Soyad"),
),
),
ColumnDate(),
genderSelect(),
],
)),
ButtonBar(
children: [
TextButton(
onPressed: () {
formKey.currentState!.reset();
Navigator.pop(context);
},
child: const Text("İptal")),
TextButton(
onPressed: () {
setState(() {
_hastaListe!.hastaEkle(HastaListeModel(
adsoyad!.text,
dogumTarihigizli!.text,
cinsiyet!));
});
formKey.currentState!.reset();
Navigator.pop(context);
},
child: const Text("Kaydet")),
],
),
],
),
);
});
});
}
Widget genderSelect() {
return StatefulBuilder(
builder: (BuildContext context, StateSetter setstate) {
return Row(
children: [
GestureDetector(
onTap: () {
setState(() {
cinsiyet = "kiz";
if (cinsiyet == "kiz") {
femaleOpacity = 1;
maleOpacity = 0.3;
}
});
},
child: Opacity(
opacity: femaleOpacity ?? 1,
child: Image.asset(
"Assets/img/girlcartoon.png",
height: 80,
width: 80,
)),
),
GestureDetector(
onTap: () {
setState(() {
cinsiyet = "erkek";
if (cinsiyet == "erkek") {
femaleOpacity = 0.3;
maleOpacity = 1;
}
});
},
child: Opacity(
opacity: maleOpacity ?? 1,
child: Image.asset(
"Assets/img/boycartoon.png",
height: 80,
width: 80,
)),
),
],
);
});
}
}