import 'dart:async'; import 'dart:convert'; import 'dart:io'; import 'package:path/path.dart' as path; import 'package:flutter_map/flutter_map.dart'; import 'package:image_picker/image_picker.dart'; import 'package:latlong2/latlong.dart' as latlong; import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:geolocator/geolocator.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:progress_dialog_null_safe/progress_dialog_null_safe.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:tower_app/Screens/Menu/Survey/sendSurvey_post.dart'; import 'package:tower_app/Screens/Menu/Survey/surveylist_screen.dart'; import 'dart:developer' as logDev; import '../../background.dart'; import '../Canvasing/canvasingDetail_screen.dart'; TextEditingController isiDesaTeksController = TextEditingController(); TextEditingController isiKecamatanTeksController = TextEditingController(); TextEditingController isiKabupatenTeksController = TextEditingController(); TextEditingController isiProvinsiTeksController = TextEditingController(); TextEditingController isiJumlahPendudukTeksController = TextEditingController(); TextEditingController isiSignal2TeksController = TextEditingController(); TextEditingController isiSignal3TeksController = TextEditingController(); TextEditingController isiSignal4TeksController = TextEditingController(); TextEditingController isiCatatanTeksController = TextEditingController(); class EditSurveyScreen extends StatefulWidget { const EditSurveyScreen({Key? key}) : super(key: key); @override State createState() => _EditSurveyScreen(); } class _EditSurveyScreen extends State { bool visibleNamaDesa = true; bool visibleEditDesa = true; bool visibleFormDesa = false; bool visibleNamaKecamatan = true; bool visibleEditKecamatan = true; bool visibleFormKecamatan = false; bool visibleNamaKabupaten = true; bool visibleEditKabupaten = true; bool visibleFormKabupaten = false; bool visibleNamaProvinsi = true; bool visibleEditProvinsi = true; bool visibleFormProvinsi = false; final List _jenisTempat = []; final List _km = []; final List _ambilFoto = []; File? _imagePath; final List _keteranganFoto = []; final List _pathFoto = []; final List _base64Foto = []; latlong.LatLng point = latlong.LatLng(-6.183580253674716, 106.93103973792664); late Position position; MapController _mapController = MapController(); late String titik; late String survey_name; late String nama_desa, nama_kecamatan, nama_kabupaten, nama_provinsi; initState(){ isiDesaTeksController.clear(); isiKecamatanTeksController.clear(); isiKabupatenTeksController.clear(); isiProvinsiTeksController.clear(); isiJumlahPendudukTeksController.clear(); isiSignal2TeksController.clear(); isiSignal3TeksController.clear(); isiSignal4TeksController.clear(); isiCatatanTeksController.clear(); survey_name = "Survey"; nama_desa = ""; nama_kecamatan = ""; nama_kabupaten = ""; nama_provinsi = ""; titik = ""; WidgetsBinding.instance.addPostFrameCallback((_) { getSurveyName(); _addFieldTempat(); }); super.initState(); } _addFieldTempat(){ setState(() { _jenisTempat.add(TextEditingController()); _km.add(TextEditingController()); }); } _removeItemTempat(i){ setState(() { _jenisTempat.removeAt(i); _km.removeAt(i); }); } _addFieldFoto(){ setState(() { _ambilFoto.add(InkWell()); _pathFoto.add(" "); _base64Foto.add(" "); _keteranganFoto.add(TextEditingController()); }); } _removeItemFoto(i){ setState(() { _ambilFoto.removeAt(i); _pathFoto.removeAt(i); _base64Foto.removeAt(i); _keteranganFoto.removeAt(i); }); } /*Timer? timer; void initTimer(){ if (timer != null && timer!.isActive) return; timer = Timer.periodic(Duration(seconds: 10), (timer) { setState(() { updatePosition(); }); }); } @override void dispose() { timer?.cancel(); super.dispose(); }*/ getSurveyName() async { ProgressDialog loading = ProgressDialog(context); loading = ProgressDialog(context, type: ProgressDialogType.normal, isDismissible: false, showLogs: true); loading.style( message: 'Please Wait .....', borderRadius: 3, backgroundColor: Colors.white, progressWidget: CircularProgressIndicator(), elevation: 10.0, padding: EdgeInsets.all(10), insetAnimCurve: Curves.easeInOut, progress: 0.0, maxProgress: 100.0, progressTextStyle: TextStyle(color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400), messageTextStyle: TextStyle(color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600)); await loading.show(); final SharedPreferences prefs = await SharedPreferences.getInstance(); survey_name = prefs.getString('nameDetail')!; logDev.log(survey_name, name: "Nama Survey"); determinePosition(); } determinePosition() async { StreamSubscription serviceStatusStream = Geolocator.getServiceStatusStream().listen( (ServiceStatus status) { print(status); }); ProgressDialog loading = ProgressDialog(context); loading = ProgressDialog(context, type: ProgressDialogType.normal, isDismissible: false, showLogs: true); loading.style( message: 'Please Wait .....', borderRadius: 3, backgroundColor: Colors.white, progressWidget: CircularProgressIndicator(), elevation: 10.0, padding: EdgeInsets.all(10), insetAnimCurve: Curves.easeInOut, progress: 0.0, maxProgress: 100.0, progressTextStyle: TextStyle(color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400), messageTextStyle: TextStyle(color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600)); bool serviceEnabled = await Geolocator.isLocationServiceEnabled(); logDev.log(serviceEnabled.toString(), name: "ON/OFF LOCATION SERVICE"); if (!serviceEnabled) { return Future.error('Location services are disabled.'); } LocationPermission permission = await Geolocator.checkPermission(); if (permission == LocationPermission.deniedForever) { await loading.hide(); //return Future.error('Location permissions are permanently denied, we cannot request permissions.'); return alertDialogPermissionDeniedForever(context); } else if (permission == LocationPermission.denied) { permission = await Geolocator.requestPermission(); if (permission != LocationPermission.whileInUse && permission != LocationPermission.always) { await loading.hide(); //return Future.error('Location permissions are denied (actual value: $permission).'); return alertDialogPermissionDenied(context); } } position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high); logDev.log(position.toString(), name: "Position GEOLOCATOR"); if (position.isMocked) { await loading.hide(); setState(() { alertDialogFakeGPSDetected(context); }); } else { setState(() { point = latlong.LatLng(position.latitude, position.longitude); logDev.log(point.toString(), name: "POINT GEOLOCATOR"); _mapController.move(point, 18); titik = position.latitude.toString() + "," + position.longitude.toString(); }); } logDev.log("DAH SELESE BUILD NAVIGATENYA!", name: "UDAH?"); await loading.hide(); //initTimer(); } Future updatePosition() async { logDev.log("NAH BARU MULAI!", name: "MULAI?"); ProgressDialog loading = ProgressDialog(context); loading = ProgressDialog(context, type: ProgressDialogType.normal, isDismissible: false, showLogs: true); loading.style( message: 'Please Wait .....', borderRadius: 3, backgroundColor: Colors.white, progressWidget: CircularProgressIndicator(), elevation: 10.0, padding: EdgeInsets.all(10), insetAnimCurve: Curves.easeInOut, progress: 0.0, maxProgress: 100.0, progressTextStyle: TextStyle( color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400), messageTextStyle: TextStyle( color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600)); bool serviceEnabled; LocationPermission permission; serviceEnabled = await Geolocator.isLocationServiceEnabled(); if (!serviceEnabled) { await loading.hide(); return Future.error('Location services are disabled.'); } permission = await Geolocator.checkPermission(); if (permission == LocationPermission.deniedForever) { await loading.hide(); return alertDialogPermissionDeniedForever(context); } else if (permission == LocationPermission.denied) { permission = await Geolocator.requestPermission(); if (permission != LocationPermission.whileInUse && permission != LocationPermission.always) { await loading.hide(); return alertDialogPermissionDenied(context); } } position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high); if (position.isMocked) { await loading.hide(); setState(() { alertDialogFakeGPSDetected(context); }); } else { await loading.hide(); point = latlong.LatLng(position.latitude, position.longitude); logDev.log(point.toString(), name: "UPDATE POINT GEOLOCATOR"); _mapController.move(point, 18); position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high); String titik = position.latitude.toString() + "," + position.longitude.toString(); logDev.log(titik, name: "TITIK UPDATE"); setState(() async { if (position.isMocked) { await loading.hide(); setState(() { alertDialogFakeGPSDetected(context); }); } else { setState(() { point = latlong.LatLng(position.latitude, position.longitude); logDev.log(point.toString(), name: "POINT GEOLOCATOR"); _mapController.move(point, 18); titik = position.latitude.toString() + "," + position.longitude.toString(); }); } }); } } @override Widget build(BuildContext context) { var size = MediaQuery.sizeOf(context); return Scaffold( body: SingleChildScrollView( child: Column( children: [ Stack( children: [ WavyHeader(), Container( margin: EdgeInsets.only(top: MediaQuery.of(context).size.height/6 - 20), padding: EdgeInsets.fromLTRB(20, 5, 25, 5), child: Row( mainAxisAlignment: MainAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end, children: [ Text( //'Survey\t\t', "Edit Survey\t\t", maxLines: 2, style: GoogleFonts.luckiestGuy( fontSize: 28, color: Color(0xFF4858A7), fontStyle: FontStyle.italic, ), ), Image.asset("assets/icons/menu/survey_3.png", width: 40, height: 40, ), ], )), SafeArea( child: Container( width: MediaQuery.of(context).size.width, margin: EdgeInsets.only( top: MediaQuery.of(context).size.height / 5, left: 10, right: 10, bottom : 15, ), child: Column( children: [ Container( child: Card( elevation: 10, child: Container( decoration: BoxDecoration( color: Color(0XFFFAF7EE), borderRadius: BorderRadius.circular(10)), child: Column( children: [ Container( margin: EdgeInsets.only( left: 10, right: 10, top: 15, bottom: 10), child: Text(survey_name, style: GoogleFonts.ubuntu(fontSize: 19, fontWeight: FontWeight.bold, /*decoration: TextDecoration.underline*/ decorationStyle: TextDecorationStyle.dashed),), ), Container( margin: EdgeInsets.only(left: 10, right: 10, top: 15), child: Column( children: [ Container( width: size.width, child: Row ( children: [ Align( alignment: Alignment.centerLeft, child: Text( 'Desa', style: GoogleFonts.inconsolata( fontSize: 16, fontWeight: FontWeight.bold, ), ), ), SizedBox(width: 15), Align( alignment: Alignment.centerLeft, child: Visibility( visible: visibleEditDesa, child: InkWell( child: Container( width: 25, height: 25, alignment: Alignment.center, margin: EdgeInsets.only(top: 2), decoration: BoxDecoration( shape: BoxShape.rectangle, color: Colors.blueAccent, borderRadius: BorderRadius.circular(5), ), child: const Icon( Icons.edit, color: Color(0XFFFAF7EE), size: 20, ) ), onTap: (){ setState(() { visibleNamaDesa = !visibleNamaDesa; visibleEditDesa = !visibleEditDesa; visibleFormDesa = !visibleFormDesa; }); }, ) ), ) ], ) ), Stack( children: [ Container( margin: EdgeInsets.only (top: 5), width: size.width, child:Visibility( visible: visibleNamaDesa, child: Text(nama_desa, overflow: TextOverflow.fade, softWrap: true), ), ), Visibility( visible: visibleFormDesa, child: Container( width: size.width, margin: EdgeInsets.only(top: 5), child: Row( children:[ Expanded( flex: 8, child: Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(5)), child: Padding( padding: EdgeInsets.only( left: 10, right: 10, top: 2, bottom: 5), child: TextFormField( keyboardType: TextInputType.multiline, controller: isiDesaTeksController, maxLines: null, textInputAction: TextInputAction.done, decoration: InputDecoration( border: InputBorder.none, hintText: "desa")), ) )), Expanded( flex:2, child: InkWell( child: Container( child: const Icon( Icons.check_box_rounded, color: Colors.blueAccent, //color: Color(0xFF6B74D6), size: 40, ) ), onTap: (){ setState(() { visibleNamaDesa = !visibleNamaDesa; visibleEditDesa = !visibleEditDesa; visibleFormDesa = !visibleFormDesa; nama_desa = isiDesaTeksController.text.toString(); }); }, ) ), ] ), )) ], ) ], ), ), Container( margin: EdgeInsets.only(left: 10, right: 10, top: 15), child: Column( children: [ Container( width: size.width, child: Row( children: [ Align( alignment: Alignment.centerLeft, child: Text( 'Kecamatan', style: GoogleFonts.inconsolata( fontSize: 16, fontWeight: FontWeight.bold), ), ), SizedBox(width: 15), Align( alignment: Alignment.centerLeft, child: Visibility( visible: visibleEditKecamatan, child: InkWell( child: Container( width: 25, height: 25, alignment: Alignment.center, margin: EdgeInsets.only(top: 2), decoration: BoxDecoration( shape: BoxShape.rectangle, color: Colors.blueAccent, borderRadius: BorderRadius.circular(5), ), child: const Icon( Icons.edit, color: Color(0XFFFAF7EE), size: 20, ) ), onTap: (){ setState(() { visibleNamaKecamatan = !visibleNamaKecamatan; visibleEditKecamatan = !visibleEditKecamatan; visibleFormKecamatan = !visibleFormKecamatan; }); }, ) ), ) ], ) ), Stack( children: [ Container( margin: EdgeInsets.only (top: 5), width: size.width, child:Visibility( visible: visibleNamaKecamatan, child: Text(nama_kecamatan, overflow: TextOverflow.fade, softWrap: true), ), ), Visibility( visible: visibleFormKecamatan, child: Container( width: size.width, margin: EdgeInsets.only(top: 5), child: Row( children:[ Expanded( flex: 8, child: Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(5)), child: Padding( padding: EdgeInsets.only( left: 10, right: 10, top: 2, bottom: 5), child: TextFormField( keyboardType: TextInputType.multiline, controller: isiKecamatanTeksController, maxLines: null, textInputAction: TextInputAction.done, decoration: InputDecoration( border: InputBorder.none, hintText: "kecamatan")), ) )), Expanded( flex:2, child: InkWell( child: Container( child: const Icon( Icons.check_box_rounded, color: Colors.blueAccent, //color: Color(0xFF6B74D6), size: 40, ) ), onTap: (){ setState(() { visibleNamaKecamatan = !visibleNamaKecamatan; visibleEditKecamatan = !visibleEditKecamatan; visibleFormKecamatan = !visibleFormKecamatan; nama_kecamatan = isiKecamatanTeksController.text.toString(); }); }, ) ), ] ), )) ], ) ], ), ), Container( margin: EdgeInsets.only(left: 10, right: 10, top: 15), child: Column( children: [ Container( width: size.width, child: Row( children:[ Align( alignment: Alignment.centerLeft, child: Text( 'Kabupaten', style: GoogleFonts.inconsolata( fontSize: 16, fontWeight: FontWeight.bold), ), ), SizedBox(width: 15), Align( alignment: Alignment.centerLeft, child: Visibility( visible: visibleEditKabupaten, child: InkWell( child: Container( width: 25, height: 25, alignment: Alignment.center, margin: EdgeInsets.only(top: 2), decoration: BoxDecoration( shape: BoxShape.rectangle, color: Colors.blueAccent, borderRadius: BorderRadius.circular(5), ), child: const Icon( Icons.edit, color: Color(0XFFFAF7EE), size: 20, ) ), onTap: (){ setState(() { visibleNamaKabupaten = !visibleNamaKabupaten; visibleEditKabupaten = !visibleEditKabupaten; visibleFormKabupaten = !visibleFormKabupaten; }); }, ) ), ) ] ) ), Stack( children:[ Container( margin: EdgeInsets.only(top: 5), width: size.width, child:Visibility( visible: visibleNamaKabupaten, child: Text(nama_kabupaten, overflow: TextOverflow.fade, softWrap: true), ), ), Visibility( visible: visibleFormKabupaten, child: Container( width: size.width, margin: EdgeInsets.only(top: 5), child: Row( children:[ Expanded( flex: 8, child: Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(5)), child: Padding( padding: EdgeInsets.only( left: 10, right: 10, top: 2, bottom: 5), child: TextFormField( keyboardType: TextInputType.multiline, controller: isiKabupatenTeksController, maxLines: null, textInputAction: TextInputAction.done, decoration: InputDecoration( border: InputBorder.none, hintText: "kabupaten")), ) )), Expanded( flex:2, child: InkWell( child: Container( child: const Icon( Icons.check_box_rounded, color: Colors.blueAccent, //color: Color(0xFF6B74D6), size: 40, ) ), onTap: (){ setState(() { visibleNamaKabupaten = !visibleNamaKabupaten; visibleEditKabupaten = !visibleEditKabupaten; visibleFormKabupaten = !visibleFormKabupaten; nama_kabupaten = isiKabupatenTeksController.text.toString(); }); }, ) ), ] ), )) ] ) ], ), ), Container( margin: EdgeInsets.only(left: 10, right: 10, top: 15), child: Column( children: [ Container( width: size.width, child: Row( children:[ Align( alignment: Alignment.centerLeft, child: Text( 'Provinsi', style: GoogleFonts.inconsolata( fontSize: 16, fontWeight: FontWeight.bold), ), ), SizedBox(width: 15), Align( alignment: Alignment.centerLeft, child: Visibility( visible: visibleEditProvinsi, child: InkWell( child: Container( width: 25, height: 25, alignment: Alignment.center, margin: EdgeInsets.only(top: 2), decoration: BoxDecoration( shape: BoxShape.rectangle, color: Colors.blueAccent, borderRadius: BorderRadius.circular(5), ), child: const Icon( Icons.edit, color: Color(0XFFFAF7EE), size: 20, ) ), onTap: (){ setState(() { visibleNamaProvinsi = !visibleNamaProvinsi; visibleEditProvinsi = !visibleEditProvinsi; visibleFormProvinsi = !visibleFormProvinsi; }); }, ) ), ) ] ) ), Stack( children:[ Container( margin: EdgeInsets.only(top:5), width: size.width, child: Visibility( visible: visibleNamaProvinsi, child: Text(nama_provinsi, overflow: TextOverflow.fade, softWrap: true), ), ), Visibility( visible: visibleFormProvinsi, child: Container( width: size.width, margin: EdgeInsets.only(top: 2), child: Row( children:[ Expanded( flex: 8, child: Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(5)), child: Padding( padding: EdgeInsets.only( left: 10, right: 10, top: 2, bottom: 5), child: TextFormField( keyboardType: TextInputType.multiline, controller: isiProvinsiTeksController, maxLines: null, textInputAction: TextInputAction.done, decoration: InputDecoration( border: InputBorder.none, hintText: "provinsi")), ) )), Expanded( flex:2, child: InkWell( child: Container( child: const Icon( Icons.check_box_rounded, color: Colors.blueAccent, //color: Color(0xFF6B74D6), size: 40, ) ), onTap: (){ setState(() { visibleNamaProvinsi = !visibleNamaProvinsi; visibleEditProvinsi = !visibleEditProvinsi; visibleFormProvinsi = !visibleFormProvinsi; nama_provinsi = isiProvinsiTeksController.text.toString(); }); }, ) ), ] ), )) ] ) ], ), ), Container( margin: EdgeInsets.only(left: 10, right: 10, top: 15), child: Column( children: [ Align( alignment: Alignment.centerLeft, child: Text( 'Jumlah Penduduk', style: GoogleFonts.inconsolata( fontSize: 16, fontWeight: FontWeight.bold), )), Container( margin: EdgeInsets.only(top: 2), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(5)), child: Padding( padding: EdgeInsets.only( left: 10, right: 10, top: 5, bottom: 5), child: TextFormField( keyboardType: TextInputType.number, controller: isiJumlahPendudukTeksController, maxLines: null, textInputAction: TextInputAction.done, decoration: InputDecoration( border: InputBorder.none, hintText: "jumlah penduduk")), ) ) ], ), ), Container( margin: EdgeInsets.only(left: 10, right: 10, top: 15), child: Column( children: [ Align( alignment: Alignment.centerLeft, child: Text( 'Posisi', style: GoogleFonts.inconsolata( fontSize: 16, fontWeight: FontWeight.bold), )), Container( height: size.height*0.4, width: size.width, margin: EdgeInsets.only(top: 2), decoration: BoxDecoration( borderRadius: BorderRadius.circular(5) ), child: Stack( children:[ FlutterMap( mapController: _mapController, options: new MapOptions( onTap: (p, point) async {}, center: point, zoom: 15), children: [ TileLayer( minZoom: 1, maxZoom: 22, maxNativeZoom: 18, minNativeZoom: 1, backgroundColor: Colors.black54, urlTemplate: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', subdomains: ['a', 'b', 'c'], ), MarkerLayer(markers: [ Marker( width: 135, height: 135, point: point, builder: (ctx) => Container( child: Icon( Icons.location_on, color: Colors.red, ), )) ]) ], ), Container( alignment: AlignmentDirectional.bottomEnd, child: Container( margin: EdgeInsets.only(bottom: 10), /*margin: EdgeInsets.fromLTRB(10, 15, 0, (size.height*0.4) + 15),*/ child: RawMaterialButton( onPressed: () { setState(() { updatePosition(); }); }, elevation: 5.0, fillColor: Colors.white, child: Image.asset('assets/images/location1.png', height: 35, width: 35), padding: EdgeInsets.all(5.0), shape: CircleBorder(), ), ), ),] ) ), ], ), ), Container( margin: EdgeInsets.only( left: 10, right: 10, top: 5), child:Align( alignment: Alignment.center, child: Text( titik, overflow: TextOverflow.fade, softWrap: true, style: GoogleFonts.inconsolata( fontSize: 16, fontWeight: FontWeight.bold), ) ) ), Container( margin: EdgeInsets.only(left: 10, right: 10, top: 15), child: Column( children: [ Align( alignment: Alignment.centerLeft, child: Text( 'Signal 2G (dBm)', style: GoogleFonts.inconsolata( fontSize: 16, fontWeight: FontWeight.bold), )), Container( margin: EdgeInsets.only(top: 2), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(5)), child: Padding( padding: EdgeInsets.only( left: 10, right: 10, top: 5, bottom: 5), child: TextFormField( keyboardType: TextInputType.multiline, controller: isiSignal2TeksController, maxLines: null, textInputAction: TextInputAction.done, decoration: InputDecoration( border: InputBorder.none, hintText: "signal 2G")), ) ) ], ), ), Container( margin: EdgeInsets.only(left: 10, right: 10, top: 15), child: Column( children: [ Align( alignment: Alignment.centerLeft, child: Text( 'Signal 3G (dBm)', style: GoogleFonts.inconsolata( fontSize: 16, fontWeight: FontWeight.bold), )), Container( margin: EdgeInsets.only(top: 7), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(5)), child: Padding( padding: EdgeInsets.only( left: 10, right: 10, top: 5, bottom: 5), child: TextFormField( keyboardType: TextInputType.multiline, controller: isiSignal3TeksController, maxLines: null, textInputAction: TextInputAction.done, decoration: InputDecoration( border: InputBorder.none, hintText: "signal 3G")), ) ) ], ), ), Container( margin: EdgeInsets.only(left: 10, right: 10, top: 15), child: Column( children: [ Align( alignment: Alignment.centerLeft, child: Text( 'Signal 4G (dBm)', style: GoogleFonts.inconsolata( fontSize: 16, fontWeight: FontWeight.bold), )), Container( margin: EdgeInsets.only(top: 2), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(5)), child: Padding( padding: EdgeInsets.only( left: 10, right: 10, top: 5, bottom: 5), child: TextFormField( keyboardType: TextInputType.multiline, controller: isiSignal4TeksController, maxLines: null, textInputAction: TextInputAction.done, decoration: InputDecoration( border: InputBorder.none, hintText: "signal 4G")), ) ) ], ), ), Container( margin: EdgeInsets.only(left: 10, right: 10, top: 15), child: Column( children: [ Align( alignment: Alignment.centerLeft, child: Text( 'Tempat Keramaian (Contoh: Sekolah, Pasar, dll)', style: GoogleFonts.inconsolata( fontSize: 16, fontWeight: FontWeight.bold), ), ), ListView.builder( shrinkWrap: true, itemCount: _jenisTempat.length, itemBuilder: (context, i) { return Padding( padding: const EdgeInsets.only(top: 2), child: Row( children: [ Expanded( flex: 7, child: Container( padding: const EdgeInsets.symmetric(horizontal: 10), //height: 60, alignment: Alignment.center, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(5), ), child: TextFormField( controller: _jenisTempat[i], autofocus: false, style: const TextStyle(color: Colors.black), decoration: const InputDecoration( border: InputBorder.none, hintText: "Jenis Tempat", hintStyle: TextStyle( color: Color.fromARGB(255, 132, 140, 155)), ), ), ), ), SizedBox(width: 5), Expanded( flex: 3, child: Container( padding: const EdgeInsets.symmetric(horizontal: 10), //height: 60, alignment: Alignment.center, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(5), ), child: TextFormField( controller: _km[i], autofocus: false, style: const TextStyle(color: Colors.black), decoration: const InputDecoration( border: InputBorder.none, hintText: "KM", hintStyle: TextStyle( color: Color.fromARGB(255, 132, 140, 155)), ), ), ), ), i != 0 ? GestureDetector( onTap: (){ setState(() { _removeItemTempat(i); }); }, child: const Icon( Icons.delete, color: Color(0xFF6B74D6), size: 40, ), ) : const SizedBox() ], ), ); }, ), const SizedBox( height: 10, ), GestureDetector( onTap: () { setState(() { _addFieldTempat(); }); }, child: Center( child: Container( width: size.width, padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10), decoration: BoxDecoration( color: Colors.blueAccent, borderRadius: BorderRadius.circular(5)), child: Align( alignment: Alignment.center, child: Text("Tambah Data Tempat+", style: GoogleFonts.nunito(color: const Color(0xFFF8F8FF))), ), ), ), ), ], ), ), Container( margin: EdgeInsets.only(left: 10, right: 10, top: 15), child: Column( children: [ Align( alignment: Alignment.centerLeft, child: Text( 'Catatan', style: GoogleFonts.inconsolata( fontSize: 16, fontWeight: FontWeight.bold), )), Container( margin: EdgeInsets.only(top: 2), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(5)), child: Padding( padding: EdgeInsets.only( left: 10, right: 10, top: 5, bottom: 5), child: TextFormField( keyboardType: TextInputType.multiline, controller: isiCatatanTeksController, maxLines: null, textInputAction: TextInputAction.done, decoration: InputDecoration( border: InputBorder.none, hintText: "catatan")), ) ) ], ), ), Container( margin: EdgeInsets.only(left: 10, right: 10, top: 15), child: Column( children: [ Align( alignment: Alignment.centerLeft, child: Text( 'Foto', style: GoogleFonts.inconsolata( fontSize: 16, fontWeight: FontWeight.bold, ), ), ), ListView.builder( shrinkWrap: true, itemCount: _ambilFoto.length, itemBuilder: (context, i) { return Padding( padding: const EdgeInsets.only(top: 2), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded( child: Column( children:[ Visibility ( child: Align( alignment: Alignment.centerLeft, child: InkWell( child: Container( padding: EdgeInsets.all(5), //width: size.width * 0.5, decoration: BoxDecoration( borderRadius: BorderRadius.circular(5), gradient: LinearGradient( colors: [ Colors.redAccent, Colors.redAccent ], ), ), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( "Ambil Foto\t\t", textAlign: TextAlign.center, style: TextStyle( color: Colors.white, //fontSize: 17, fontWeight: FontWeight.w500, ), ), const Icon( Icons.camera_alt, //color: Color(0xFF6B74D6), size: 25, ), ], ), ), onTap: () async { final ImagePicker _picker = ImagePicker(); final XFile? imagePicked = await _picker.pickImage( source: ImageSource.camera); if (imagePicked != null) { _imagePath = File(imagePicked.path); logDev.log(_imagePath.toString(), name: "IMAGE PATH"); List imageBytes = _imagePath!.readAsBytesSync(); String base64Image = base64Encode(imageBytes); //logDev.log(base64Image, name: "String base64"); setState(() { logDev.log(_ambilFoto.length.toString(), name: "ada berapa banyak buttonambil foto"); _pathFoto[i] = path.basename(_imagePath.toString()); _base64Foto[i] = base64Image; logDev.log(_pathFoto.length.toString(), name: "Banyak path foto"); logDev.log(_base64Foto.length.toString(), name: "Banyak Base64"); logDev.log(_pathFoto.toString(), name: "Isi Path FOTO"); }); } else if (imagePicked == null) { //_imagePath = await getImageFileFromAssets('assets/images/ic_administrator.png') as File?; } }, ), ), ), Visibility( child: Align( alignment: Alignment.centerLeft, child: FittedBox( fit: BoxFit.scaleDown, // Sesuaikan teks agar tidak melebihi lebar container child: Text( _pathFoto[i] /*style: TextStyle(fontSize: size.width),*/ ), ), ) ), ] ) ), GestureDetector( onTap: () { setState(() { _removeItemFoto(i); logDev.log(_pathFoto.length.toString(), name: "Banyak path foto"); logDev.log(_pathFoto.toString(), name: "Isi Path FOTO"); }); }, child: const Icon( Icons.delete, color: Color(0xFF6B74D6), size: 40, ) ) ], ), ); }, ), const SizedBox( height: 5, ), GestureDetector( onTap: () { setState(() { _addFieldFoto(); }); }, child: Center( child: Container( width: MediaQuery.of(context).size.width, padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10), decoration: BoxDecoration( color: Colors.blueAccent, borderRadius: BorderRadius.circular(5), ), child: Align( alignment: Alignment.center, child: Text( "Tambah Foto+", style: GoogleFonts.nunito( color: const Color(0xFFF8F8FF), ), ), ), ), ), ), ], ), ), InkWell( child: Container( margin: EdgeInsets.only(left: 10, right: 10, top:15, bottom: 15), padding: EdgeInsets.fromLTRB( 10, 10, 10, 10), width: double.infinity, decoration: BoxDecoration( borderRadius: BorderRadius.circular(5), gradient: LinearGradient(colors: [ Color(0xFF2D4059), Color(0xFF2D4059), /*Color(0xFF444C60), Color(0xFF444C60),*/ ])), child: Text('KIRIM', textAlign: TextAlign.center, style: TextStyle( color: Colors.white, fontSize: 17, fontWeight: FontWeight.w500)), ), onTap: () async { ProgressDialog loading = ProgressDialog(context); loading = ProgressDialog(context, type: ProgressDialogType.normal, isDismissible: false, showLogs: true); loading.style( message: 'Please Wait .....', borderRadius: 3, backgroundColor: Colors.white, progressWidget: CircularProgressIndicator(), elevation: 10.0, padding: EdgeInsets.all(10), insetAnimCurve: Curves.easeInOut, progress: 0.0, maxProgress: 100.0, progressTextStyle: TextStyle( color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400), messageTextStyle: TextStyle( color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600)); List> tempatKeramaian = []; tempatKeramaian = List.generate(_jenisTempat.length, (index) => [_jenisTempat.map((controller) => controller.text).toList()[index], _km.map((controller) => controller.text).toList()[index]]); logDev.log(tempatKeramaian.toString(), name:"list tempat keramaian"); List> fotoKeterangan = []; fotoKeterangan = List.generate(_base64Foto.length, (index) => [_base64Foto[index], "Keterangan Foto"]); logDev.log(fotoKeterangan.toString(), name:"Foto dan Keterangan"); if (!validateFormSurvey(context)){ return; } else if (validateFormSurvey(context)){ await loading.show(); final SharedPreferences prefs = await SharedPreferences.getInstance(); int? idDetail = prefs.getInt('idDetail'); int? user_id = prefs.getInt('user_id'); SendSurvey_Post.connectToAPI(user_id!, idDetail!, nama_desa, nama_kecamatan, nama_kabupaten, nama_provinsi, int.parse(isiJumlahPendudukTeksController.text.toString()), titik, isiSignal2TeksController.text.toString(), isiSignal3TeksController.text.toString(), isiSignal4TeksController.text.toString(), isiCatatanTeksController.text.toString(), tempatKeramaian, fotoKeterangan).then((valueResult) async { Map object = json.decode(valueResult); String status = object['result']['status'].toString(); logDev.log(status, name: "STATUS!!!!!!!"); if (status == "success") { //String status = object['status'].toString(); //logDev.log(status, name: "Statusnya"); await loading.hide(); Widget okButton = TextButton( child: Text("OK"), onPressed: () { Navigator.of(context, rootNavigator: true).pop(); Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => ListSurveyScreen())); }, ); // set up the AlertDialog AlertDialog alert = AlertDialog( title: Text("POC Bakti"), content: Text("Success Submit"), actions: [ okButton, ], ); // show the dialog showDialog( context: context, barrierDismissible: false, builder: ( BuildContext context) { return alert; }, ); } else { await loading.hide(); alertDialogFailedResponse( context); } }); } }, ), ], ), ), ), ), ], ), ), ), ], ), ], )), ); } //Validasi Form Survey bool validateFormSurvey(BuildContext context) { bool result = true; if (nama_desa == "" && visibleFormDesa == false) { Fluttertoast.showToast( msg: "Nama Desa Harus Diisi!", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, textColor: Colors.white, fontSize: 16.0); result = false; } else if (visibleFormDesa == true){ Fluttertoast.showToast( msg: "Mohon Konfirmasi Data Desa Terlebih Dahulu!", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, textColor: Colors.white, fontSize: 16.0); result = false; } else if (nama_kecamatan == "" && visibleFormKecamatan == false) { Fluttertoast.showToast( msg: "Nama Kecamatan Harus Diisi!", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, textColor: Colors.white, fontSize: 16.0); result = false; } else if (visibleFormKecamatan == true){ Fluttertoast.showToast( msg: "Mohon Konfirmasi Data Kecamatan Terlebih Dahulu!", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, textColor: Colors.white, fontSize: 16.0); result = false; } else if (nama_kabupaten == "" && visibleFormKabupaten == false) { Fluttertoast.showToast( msg: "Nama Kabupaten Harus Diisi!", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, textColor: Colors.white, fontSize: 16.0); result = false; } else if (visibleFormKabupaten == true){ Fluttertoast.showToast( msg: "Mohon Konfirmasi Data Kabupaten Terlebih Dahulu!", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, textColor: Colors.white, fontSize: 16.0); result = false; } else if (nama_provinsi == "" && visibleFormProvinsi == false) { Fluttertoast.showToast( msg: "Nama Provinsi Harus Diisi!", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, textColor: Colors.white, fontSize: 16.0); result = false; } else if (visibleFormProvinsi == true){ Fluttertoast.showToast( msg: "Mohon Konfirmasi Data Provinsi Terlebih Dahulu!", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, textColor: Colors.white, fontSize: 16.0); result = false; } else if (isiJumlahPendudukTeksController.text.toString().isEmpty) { Fluttertoast.showToast( msg: "Jumlah Penduduk Harus Diisi!", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, textColor: Colors.white, fontSize: 16.0); result = false; } else if (isiSignal2TeksController.text.toString().isEmpty) { Fluttertoast.showToast( msg: "Signal 2G Harus Diisi!", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, textColor: Colors.white, fontSize: 16.0); result = false; } else if (isiSignal3TeksController.text.toString().isEmpty) { Fluttertoast.showToast( msg: "Signal 3G Harus Diisi!", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, textColor: Colors.white, fontSize: 16.0); result = false; } else if (isiSignal4TeksController.text.toString().isEmpty) { Fluttertoast.showToast( msg: "Signal 4G Harus Diisi!", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, textColor: Colors.white, fontSize: 16.0); result = false; } else if (_jenisTempat[0].text.toString().isEmpty){ Fluttertoast.showToast( msg: "Tempat Keramaian Harus Diisi!", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, textColor: Colors.white, fontSize: 16.0); result = false; } else if (_km[0].text.toString().isEmpty){ Fluttertoast.showToast( msg: "Tempat Keramaian Harus Diisi!", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, textColor: Colors.white, fontSize: 16.0); result = false; } /*else if (isiCatatanTeksController.text.toString().isEmpty) { Fluttertoast.showToast( msg: "Catatan Harus Diisi!", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, textColor: Colors.white, fontSize: 16.0); result = false; }*/ return result; } } alertDialogFailedRetrievedData(BuildContext context){ Widget okButton = TextButton( child: Text("Refresh"), onPressed: () { Navigator.of(context, rootNavigator: true).pop(); Navigator.pushReplacement(context, MaterialPageRoute( builder: (context) => EditSurveyScreen())); }, ); Widget noButton = TextButton( child: Text("Back"), onPressed: () { Navigator.of(context, rootNavigator: true).pop(); Navigator.pop(context); }, ); // set up the AlertDialog AlertDialog alert = AlertDialog( title: Text("POC Bakti"), content: Text("Failed to Retrieve Data"), actions: [ noButton, okButton, ], ); // show the dialog showDialog( context: context, barrierDismissible: false, builder: (BuildContext context) { return alert; }, ); } alertDialogFailedResponse(BuildContext context){ Widget okButton = TextButton( child: Text("Refresh"), onPressed: () { Navigator.of(context, rootNavigator: true).pop(); Navigator.pushReplacement(context, MaterialPageRoute( builder: (context) => EditSurveyScreen())); }, ); Widget noButton = TextButton( child: Text("Back"), onPressed: () { Navigator.of(context, rootNavigator: true).pop(); Navigator.pop(context); }, ); // set up the AlertDialog AlertDialog alert = AlertDialog( title: Text("POC Bakti"), content: Text("Server Response Error"), actions: [ noButton, okButton, ], ); // show the dialog showDialog( context: context, barrierDismissible: false, builder: (BuildContext context) { return alert; }, ); }