import 'dart:convert'; import 'dart:math'; import 'package:fikoyt_sistem/apps/uyar/core/services/uyar_service.dart'; import 'package:fikoyt_ui/fikoyt_ui.dart'; import 'package:fikoyt_ui/ui/fikoyt_card.dart'; import 'package:fikoyt_ui/ui/yazi_kutulari/yazi_kutulari.dart'; import 'package:flutter/material.dart'; import 'package:image_picker/image_picker.dart'; import 'dart:io'; import 'package:dio/dio.dart' as Dio; class KullaniciEkleFormService extends GetxService { Map form = { "isim": null, "soyisim": null, "kullaniciAdi": null, "parola": null, "parolaTekrar": null, "telefon": null, "eposta": null, "uygulamalar": ["Uyar Döküm"], "profilResmi": null, }; Rx profilResmi = Rx(null); @override void onInit() { super.onInit(); } profilResmiSec() async { final ImagePicker picker = ImagePicker(); // Pick an image. profilResmi.value = await picker.pickImage(source: ImageSource.gallery); } profilResmiSil() async { profilResmi.value = null; } } class KullaniciEkleForm extends StatefulWidget { const KullaniciEkleForm({Key? key}) : super(key: key); @override _KullaniciEkleFormState createState() => _KullaniciEkleFormState(); } class _KullaniciEkleFormState extends State { KullaniciEkleFormService logic = Get.put(KullaniciEkleFormService()); UyarService uyarService = Get.put(UyarService()); @override void dispose() { // TODO: implement dispose Get.delete(); super.dispose(); } @override Widget build(BuildContext context) { return Column( spacing: 5, mainAxisSize: MainAxisSize.max, children: [ Column( children: [ Row(children: [FikoYTButton(text: "👤 Kullanıcı Ekle")]), ], ), Center( child: Obx( () => FikoytOvalResim( resimUrl: logic.profilResmi.value == null ? "👨🏻‍💼" : logic.profilResmi.value!, // İşte burada XFile'dan resim gösteriliyor tema: FikoYTOvalResimTheme(borderColor: Colors.blue, radius: 42, spacing: 7), ), ), ), Obx( () => Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ AnimatedSwitcher( duration: const Duration(milliseconds: 500), child: logic.profilResmi.value == null ? FikoYTButton( key: const ValueKey("Resim Seç Button"), text: "📸 Resim Seç", tema: FikoYTButtonTheme( fontSize: 12, edgePadding: EdgeInsets.symmetric(horizontal: 5, vertical: 3), fontWeight: FontWeight.bold, textColor: Colors.white, borderColor: Colors.blue.shade200, backgroundColor: Colors.blue.shade500, ), onPressed: () { logic.profilResmiSec(); }, ) : FikoYTButton( key: const ValueKey("Resim Sil Button"), text: "📸 Resim Sil", tema: FikoYTButtonTheme( fontSize: 12, edgePadding: EdgeInsets.symmetric(horizontal: 5, vertical: 3), fontWeight: FontWeight.bold, textColor: Colors.white, borderColor: Colors.red.shade200, backgroundColor: Colors.red.shade500, ), onPressed: () { logic.profilResmiSil(); }, ), ), ], ), ), FikoYaziKutusu( baslik: "İsim", simgeSol: const Text("🖋", style: TextStyle(fontSize: 14)), yaziBoyutu: 12.0, radius: 5.0, degeri: logic.form["isim"], degisti: (value) { logic.form["isim"] = value; }, oneriOtomatikDoldurma: [AutofillHints.name, AutofillHints.givenName], ), FikoYaziKutusu( baslik: "Soyisim", simgeSol: const Text("👪", style: TextStyle(fontSize: 14)), yaziBoyutu: 12.0, radius: 5.0, degeri: logic.form["soyisim"], degisti: (value) { logic.form["soyisim"] = value; }, oneriOtomatikDoldurma: [AutofillHints.familyName], ), FikoYaziKutusu( baslik: "Kullanıcı Adı", simgeSol: const Text("👩🏻", style: TextStyle(fontSize: 14)), yaziBoyutu: 12.0, radius: 5.0, degeri: logic.form["kullaniciAdi"], degisti: (value) { logic.form["kullaniciAdi"] = value; }, oneriOtomatikDoldurma: [AutofillHints.newUsername, AutofillHints.username], ), FikoYaziKutusu( baslik: "E-Posta", simgeSol: const Text("📧", style: TextStyle(fontSize: 14)), yaziBoyutu: 12.0, radius: 5.0, degeri: logic.form["eposta"], degisti: (value) { logic.form["eposta"] = value; }, oneriOtomatikDoldurma: [AutofillHints.email], ), FikoYaziKutusu( baslik: "Parola", simgeSol: const Text("🔐", style: TextStyle(fontSize: 14)), gizli: true, obscuringCharacter: "♥", yaziBoyutu: 12.0, radius: 5.0, degeri: logic.form["parola"], degisti: (value) { logic.form["parola"] = value; }, oneriOtomatikDoldurma: [AutofillHints.newPassword, AutofillHints.password], ), FikoYaziKutusu( baslik: "Parola Tekrar", simgeSol: const Text("🔐", style: TextStyle(fontSize: 14)), gizli: true, obscuringCharacter: "♥", yaziBoyutu: 12.0, radius: 5.0, degeri: logic.form["parolaTekrar"], degisti: (value) { logic.form["parolaTekrar"] = value; }, oneriOtomatikDoldurma: [AutofillHints.newPassword, AutofillHints.password], ), FikoYaziKutusu( baslik: "Telefon", simgeSol: const Text("📱", style: TextStyle(fontSize: 14)), yaziBoyutu: 12.0, radius: 5.0, degeri: logic.form["telefon"], degisti: (value) { logic.form["telefon"] = value; }, oneriOtomatikDoldurma: [AutofillHints.telephoneNumber], ), /// SizedBox(height: 5), Row( children: [ Spacer(), Stack( children: [ FikoYTButton( text: Obx(() { uyarService.logicKullanici.ekleIstek.isBusy.value; return Row( children: [ uyarService.logicKullanici.ekleIstek.isBusy.value ? SizedBox(height: 16,width: 16,child: const CircularProgressIndicator(color: Colors.white, )) : const Text("➕"), // const Text("➕"), FikoYTButton( text: "Ekle", tema: FikoYTButtonTheme( textColor: Colors.white, backgroundColor: Colors.transparent, // fontWeight: FontWeight.w700, edgePadding: EdgeInsets.all(3), borderColor: Colors.transparent, elevation: 3, fontSize: 12, ), ), ], ); }), tema: FikoYTButtonTheme( textColor: Colors.white, backgroundColor: Colors.blue, // fontWeight: FontWeight.w700, edgePadding: EdgeInsets.all(3), borderColor: Colors.blueAccent, elevation: 3, fontSize: 12, ), onPressed: () async { var formData = Dio.FormData(); logic.form["profilResmi"] = null; if (logic.profilResmi.value != null) { var resimId = ObjectId().oid; logic.form["profilResmi"] = null; formData.files.add( MapEntry(resimId, Dio.MultipartFile.fromFileSync(logic.profilResmi.value!.path,headers: {"realpath": logic.profilResmi.value!.path})), ); logic.form["profilResmi"] = resimId; } formData.fields.add(MapEntry("req_body", jsonEncode(logic.form).toString())); uyarService.logicKullanici.ekleIstek.parameters = formData; // uyarService.logicKullanici.ekleIstek.clearEvents(); // uyarService.logicKullanici.ekleIstek.onResult((p0, p1) { // print(p1.result); // }); uyarService.logicKullanici.ekleIstek.startWithQueue(); }, ), ], ), ], ), ], ); } }