Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'package:employee_selfservice_mobile/Screens/Home/home_screen.dart';
  4. import 'package:employee_selfservice_mobile/Screens/Menu/Canvasing/filingData_post.dart';
  5. import 'package:file_picker/file_picker.dart';
  6. import 'package:flutter/cupertino.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:fluttertoast/fluttertoast.dart';
  9. import 'package:google_fonts/google_fonts.dart';
  10. import 'package:intl/intl.dart';
  11. import 'package:progress_dialog_null_safe/progress_dialog_null_safe.dart';
  12. import 'package:shared_preferences/shared_preferences.dart';
  13. import 'dart:developer' as logDev;
  14. import '../../background.dart';
  15. //List<String> fileAttach = [""];
  16. TextEditingController amountTextController = TextEditingController();
  17. class FilingScreen extends StatefulWidget {
  18. const FilingScreen({Key? key}) : super(key: key);
  19. @override
  20. State<FilingScreen> createState() => _FilingScreen();
  21. }
  22. class _FilingScreen extends State<FilingScreen> {
  23. String _fileTextKK = "";
  24. String _fileTextKTP = "";
  25. String _fileTextNPWP = "";
  26. String base64KK = "";
  27. String base64KTP = "";
  28. String base64NPWP = "";
  29. initState(){
  30. WidgetsBinding.instance.addPostFrameCallback((_) {
  31. base64KK = "";
  32. base64KTP = "";
  33. base64NPWP = "";
  34. });
  35. super.initState();
  36. }
  37. @override
  38. Widget build(BuildContext context) {
  39. var size = MediaQuery.sizeOf(context);
  40. return Scaffold(
  41. body: SingleChildScrollView(
  42. child: Column(
  43. children: <Widget>[
  44. Stack(
  45. children: [
  46. WavyHeader(),
  47. Container(
  48. margin: EdgeInsets.only(top: MediaQuery.of(context).size.height/6 - 20),
  49. padding: EdgeInsets.fromLTRB(20, 5, 25, 5),
  50. child: Row(
  51. mainAxisAlignment: MainAxisAlignment.end,
  52. crossAxisAlignment: CrossAxisAlignment.end,
  53. children: [
  54. Text(
  55. 'Filing\t\t',
  56. maxLines: 2,
  57. style: GoogleFonts.luckiestGuy(
  58. fontSize: 28,
  59. color: Color(0xFF4858A7),
  60. fontStyle: FontStyle.italic,
  61. ),
  62. ),
  63. Image.asset("assets/icons/menu/ic_filing_1.png",
  64. width: 40,
  65. height: 40,
  66. ),
  67. ],
  68. )),
  69. SafeArea(
  70. child: Container(
  71. width: MediaQuery.of(context).size.width,
  72. margin: EdgeInsets.only(
  73. top: MediaQuery.of(context).size.height / 5,
  74. left: 10,
  75. right: 10,
  76. bottom : 15,
  77. ),
  78. child: Column(
  79. children: [
  80. Container(
  81. child: Card(
  82. elevation: 10,
  83. child: Container(
  84. decoration: BoxDecoration(
  85. color: Color(0XFFFAF7EE),
  86. borderRadius: BorderRadius.circular(10)),
  87. child: Column(
  88. children: [
  89. Container(
  90. margin: EdgeInsets.only(
  91. left: 10, right: 10, top: 15, bottom: 10),
  92. child: Text('Filing', style:
  93. GoogleFonts.josefinSans(fontSize: 19, fontWeight: FontWeight.bold, decoration: TextDecoration.underline,
  94. decorationStyle: TextDecorationStyle.dashed),),
  95. ),
  96. Container(
  97. margin: EdgeInsets.only(
  98. left: 10, right: 10, top: 10, bottom: 10),
  99. child: Column(
  100. children: [
  101. Align(
  102. alignment: Alignment.centerLeft,
  103. child: Text(
  104. 'Amount',
  105. style: GoogleFonts.inconsolata(
  106. fontSize: 16, fontWeight: FontWeight.bold),
  107. )
  108. ),
  109. Container(
  110. margin: EdgeInsets.only(top: 7),
  111. decoration: BoxDecoration(
  112. color: Colors.white,
  113. borderRadius:
  114. BorderRadius.circular(5)),
  115. child: Padding(
  116. padding: EdgeInsets.only(
  117. left: 10,
  118. right: 10,
  119. top: 5,
  120. bottom: 5),
  121. child: TextFormField(
  122. keyboardType:
  123. TextInputType.number,
  124. maxLines: 1,
  125. controller: amountTextController,
  126. textInputAction:
  127. TextInputAction.next,
  128. decoration: InputDecoration(
  129. border:
  130. InputBorder.none,
  131. hintText:
  132. "ex. 1500500", )),
  133. )
  134. )
  135. ],
  136. ),
  137. ),
  138. Container(
  139. margin: EdgeInsets.only(
  140. left: 10, right: 10, top: 10),
  141. child: Column(
  142. children: [
  143. Align(
  144. alignment: Alignment.centerLeft,
  145. child: Text(
  146. 'Kartu Keluarga',
  147. style: GoogleFonts.inconsolata(
  148. fontSize: 16, fontWeight: FontWeight.bold),
  149. ),
  150. ),
  151. Container(
  152. child: ElevatedButton(
  153. onPressed: () {
  154. _pickFilesKK();
  155. },
  156. /*style: ElevatedButton.styleFrom(
  157. backgroundColor:
  158. CupertinoColors
  159. .systemGrey2),*/
  160. child: Container(
  161. width: double.infinity,
  162. child: Text("Choose File",
  163. style: TextStyle(
  164. color: Colors.white,
  165. fontSize: 16,
  166. fontWeight:
  167. FontWeight.w400)),
  168. ),
  169. ),
  170. ),
  171. Container(
  172. alignment:
  173. Alignment.centerLeft,
  174. margin: EdgeInsets.only(
  175. left: 15,
  176. right: 15,
  177. bottom: 10),
  178. child: Text(_fileTextKK,
  179. overflow:
  180. TextOverflow.ellipsis,
  181. /*maxLines: 7,*/
  182. style: TextStyle(
  183. color: Colors.black54),
  184. ),
  185. ),
  186. ],
  187. ),
  188. ),
  189. Container(
  190. margin: EdgeInsets.only(
  191. left: 10, right: 10, top: 10),
  192. child: Column(
  193. children: [
  194. Align(
  195. alignment: Alignment.centerLeft,
  196. child: Text(
  197. 'KTP',
  198. style: GoogleFonts.inconsolata(
  199. fontSize: 16, fontWeight: FontWeight.bold),
  200. ),
  201. ),
  202. Container(
  203. child: ElevatedButton(
  204. onPressed: () {
  205. _pickFilesKTP();
  206. },
  207. /*style: ElevatedButton.styleFrom(
  208. backgroundColor:
  209. CupertinoColors
  210. .systemGrey2),*/
  211. child: Container(
  212. width: double.infinity,
  213. child: Text("Choose File",
  214. style: TextStyle(
  215. color: Colors.white,
  216. fontSize: 16,
  217. fontWeight:
  218. FontWeight.w400)),
  219. ),
  220. ),
  221. ),
  222. Container(
  223. alignment:
  224. Alignment.centerLeft,
  225. margin: EdgeInsets.only(
  226. left: 15,
  227. right: 15,
  228. bottom: 10),
  229. child: Text(_fileTextKTP,
  230. overflow:
  231. TextOverflow.ellipsis,
  232. /*maxLines: 7,*/
  233. style: TextStyle(
  234. color: Colors.black54),
  235. ),
  236. ),
  237. ],
  238. ),
  239. ),
  240. Container(
  241. margin: EdgeInsets.only(
  242. left: 10, right: 10, top: 10),
  243. child: Column(
  244. children: [
  245. Align(
  246. alignment: Alignment.centerLeft,
  247. child: Text(
  248. 'NPWP',
  249. style: GoogleFonts.inconsolata(
  250. fontSize: 16, fontWeight: FontWeight.bold),
  251. ),
  252. ),
  253. Container(
  254. child: ElevatedButton(
  255. onPressed: () {
  256. _pickFilesNPWP();
  257. },
  258. /*style: ElevatedButton.styleFrom(
  259. backgroundColor:
  260. CupertinoColors
  261. .systemGrey2),*/
  262. child: Container(
  263. width: double.infinity,
  264. child: Text("Choose File",
  265. style: TextStyle(
  266. color: Colors.white,
  267. fontSize: 16,
  268. fontWeight:
  269. FontWeight.w400)),
  270. ),
  271. ),
  272. ),
  273. Container(
  274. alignment:
  275. Alignment.centerLeft,
  276. margin: EdgeInsets.only(
  277. left: 15,
  278. right: 15,
  279. bottom: 10),
  280. child: Text(_fileTextNPWP,
  281. overflow:
  282. TextOverflow.ellipsis,
  283. /*maxLines: 7,*/
  284. style: TextStyle(
  285. color: Colors.black54),
  286. ),
  287. ),
  288. ],
  289. ),
  290. ),
  291. InkWell(
  292. child: Container(
  293. margin: EdgeInsets.only(left: 10, right: 10, bottom: 15),
  294. padding: EdgeInsets.fromLTRB(
  295. 10, 10, 10, 10),
  296. width: double.infinity,
  297. decoration: BoxDecoration(
  298. borderRadius:
  299. BorderRadius.circular(5),
  300. gradient: LinearGradient(colors: [
  301. Color(0xFFFF9945),
  302. Color(0xFFFc6076)
  303. ])),
  304. child: Text('Submit',
  305. textAlign: TextAlign.center,
  306. style: TextStyle(
  307. color: Colors.white,
  308. fontSize: 17,
  309. fontWeight: FontWeight.w500)),
  310. ),
  311. onTap: () async {
  312. ProgressDialog loading = ProgressDialog(context);
  313. loading = ProgressDialog(context,
  314. type: ProgressDialogType.normal, isDismissible: false, showLogs: true);
  315. loading.style(
  316. message: 'Please Wait .....',
  317. borderRadius: 3,
  318. backgroundColor: Colors.white,
  319. progressWidget: CircularProgressIndicator(),
  320. elevation: 10.0,
  321. padding: EdgeInsets.all(10),
  322. insetAnimCurve: Curves.easeInOut,
  323. progress: 0.0,
  324. maxProgress: 100.0,
  325. progressTextStyle: TextStyle(
  326. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  327. messageTextStyle: TextStyle(
  328. color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600));
  329. if (!validateFormFiling(context)){
  330. return;
  331. } else if (validateFormFiling(context)){
  332. await loading.show();
  333. final SharedPreferences prefs = await SharedPreferences.getInstance();
  334. String? idDetail = prefs.getString('idDetail');
  335. logDev.log(idDetail!, name: "APAKAH ADA ID?");
  336. int? user_id = prefs.getInt('user_id');
  337. FilingData_Post.connectToAPI(idDetail!, amountTextController.text.toString(), base64KK, base64KTP, base64NPWP, user_id!).then((valueResult) async {
  338. Map<String, dynamic> object = json.decode(valueResult);
  339. if (object.containsKey("result").toString() == "true") {
  340. String result = object['result'].toString();
  341. String status = object['result']['status'].toString();
  342. if (status == "success") {
  343. await loading.hide();
  344. Widget okButton = TextButton(
  345. child: Text("OK"),
  346. onPressed: () {
  347. amountTextController.clear();
  348. Navigator.of(context, rootNavigator: true).pop();
  349. Navigator.pushReplacement(context, MaterialPageRoute(
  350. builder: (context) => HomeView()));
  351. },
  352. );
  353. // set up the AlertDialog
  354. AlertDialog alert = AlertDialog(
  355. title: Text("Canvasing"),
  356. content: Text("Data Submitted!"),
  357. actions: [
  358. okButton,
  359. ],
  360. );
  361. // show the dialog
  362. showDialog(
  363. context: context,
  364. barrierDismissible: false,
  365. builder: (BuildContext context) {
  366. return alert;
  367. },
  368. );
  369. }
  370. } else {
  371. await loading.hide();
  372. alertDialogFailedResponse(context);
  373. }
  374. });
  375. }
  376. },
  377. )
  378. ],
  379. ),
  380. ),
  381. ),
  382. ),
  383. ],
  384. ),
  385. ),
  386. ),
  387. ],
  388. ),
  389. ],
  390. )),
  391. );
  392. }
  393. //Pick Files KK
  394. void _pickFilesKK() async {
  395. FilePickerResult? result = await FilePicker.platform.pickFiles(allowMultiple: false, type: FileType.custom, allowedExtensions: ["jpg"]);
  396. if (_fileTextKK != ""){
  397. _fileTextKK = "";
  398. }
  399. if (result != null) {
  400. List<File> files = result.paths.map((path) => File(path!)).toList();
  401. for (int i = 0; i< files.length; i++){
  402. String fileName = files[i].path.split('/').last;
  403. _fileTextKK = _fileTextKK + "\n" + fileName;
  404. List<int> fileInBytes = files[i].readAsBytesSync();
  405. base64KK = base64Encode(fileInBytes);
  406. //logDev.log(toBase64, name: "Base64 nya kah?");
  407. //fileAttach.add(toBase64);
  408. }
  409. //fileAttach.removeAt(0);
  410. /*logDev.log(fileAttach.toString(), name: "File Attach Base64");*/
  411. //logDev.log(fileAttach.length.toString(), name: "Length File Attach");
  412. logDev.log(files.toString(), name: "Files (KK) Picked");
  413. setState(() {
  414. base64KK;
  415. _fileTextKK;
  416. //_totalFile = "Total File : " + files.length.toString();
  417. });
  418. } else {
  419. // User canceled the picker
  420. }
  421. }
  422. //Pick Files KTP
  423. void _pickFilesKTP() async {
  424. FilePickerResult? result = await FilePicker.platform.pickFiles(allowMultiple: false, type: FileType.custom, allowedExtensions: ["jpg"]);
  425. if (_fileTextKTP != ""){
  426. _fileTextKTP = "";
  427. }
  428. if (result != null) {
  429. List<File> files = result.paths.map((path) => File(path!)).toList();
  430. for (int i = 0; i< files.length; i++){
  431. String fileName = files[i].path.split('/').last;
  432. _fileTextKTP = _fileTextKTP + "\n" + fileName;
  433. List<int> fileInBytes = files[i].readAsBytesSync();
  434. base64KTP = base64Encode(fileInBytes);
  435. //fileAttach.add(toBase64);
  436. }
  437. // fileAttach.removeAt(0);
  438. /*logDev.log(fileAttach.toString(), name: "File Attach Base64");*/
  439. //logDev.log(fileAttach.length.toString(), name: "Length File Attach");
  440. logDev.log(files.toString(), name: "Files Picked");
  441. setState(() {
  442. base64KTP;
  443. _fileTextKTP;
  444. //_totalFile = "Total File : " + files.length.toString();
  445. });
  446. } else {
  447. // User canceled the picker
  448. }
  449. }
  450. //Pick Files NPWP
  451. void _pickFilesNPWP() async {
  452. FilePickerResult? result = await FilePicker.platform.pickFiles(allowMultiple: false, type: FileType.custom, allowedExtensions: ["jpg"]);
  453. if (_fileTextNPWP != ""){
  454. _fileTextNPWP = "";
  455. }
  456. if (result != null) {
  457. List<File> files = result.paths.map((path) => File(path!)).toList();
  458. for (int i = 0; i< files.length; i++){
  459. String fileName = files[i].path.split('/').last;
  460. _fileTextNPWP = _fileTextNPWP + "\n" + fileName;
  461. List<int> fileInBytes = files[i].readAsBytesSync();
  462. base64NPWP = base64Encode(fileInBytes);
  463. //fileAttach.add(toBase64);
  464. }
  465. //fileAttach.removeAt(0);
  466. /*logDev.log(fileAttach.toString(), name: "File Attach Base64");*/
  467. //logDev.log(fileAttach.length.toString(), name: "Length File Attach");
  468. logDev.log(files.toString(), name: "Files Picked");
  469. setState(() {
  470. base64NPWP;
  471. _fileTextNPWP;
  472. //_totalFile = "Total File : " + files.length.toString();
  473. });
  474. } else {
  475. // User canceled the picker
  476. }
  477. }
  478. bool validateFormFiling(BuildContext context) {
  479. bool result = true;
  480. if (amountTextController.text.toString().isEmpty) {
  481. Fluttertoast.showToast(
  482. msg: "Amount Required!",
  483. toastLength: Toast.LENGTH_SHORT,
  484. gravity: ToastGravity.CENTER,
  485. timeInSecForIosWeb: 1,
  486. textColor: Colors.white,
  487. fontSize: 16.0);
  488. result = false;
  489. } else if (_fileTextKK.isEmpty) {
  490. Fluttertoast.showToast(
  491. msg: "Karti Keluarga Required!",
  492. toastLength: Toast.LENGTH_SHORT,
  493. gravity: ToastGravity.CENTER,
  494. timeInSecForIosWeb: 1,
  495. textColor: Colors.white,
  496. fontSize: 16.0);
  497. result = false;
  498. } else if (_fileTextKTP.isEmpty) {
  499. Fluttertoast.showToast(
  500. msg: "KTP Required!",
  501. toastLength: Toast.LENGTH_SHORT,
  502. gravity: ToastGravity.CENTER,
  503. timeInSecForIosWeb: 1,
  504. textColor: Colors.white,
  505. fontSize: 16.0);
  506. result = false;
  507. } else if (_fileTextNPWP.isEmpty) {
  508. Fluttertoast.showToast(
  509. msg: "NPWP Required!",
  510. toastLength: Toast.LENGTH_SHORT,
  511. gravity: ToastGravity.CENTER,
  512. timeInSecForIosWeb: 1,
  513. textColor: Colors.white,
  514. fontSize: 16.0);
  515. result = false;
  516. }
  517. return result;
  518. }
  519. }
  520. alertDialogFailedRetrievedData(BuildContext context){
  521. Widget okButton = TextButton(
  522. child: Text("Refresh"),
  523. onPressed: () {
  524. Navigator.of(context, rootNavigator: true).pop();
  525. Navigator.pushReplacement(context, MaterialPageRoute(
  526. builder: (context) => FilingScreen()));
  527. },
  528. );
  529. Widget noButton = TextButton(
  530. child: Text("Back"),
  531. onPressed: () {
  532. Navigator.of(context, rootNavigator: true).pop();
  533. Navigator.pop(context);
  534. },
  535. );
  536. // set up the AlertDialog
  537. AlertDialog alert = AlertDialog(
  538. title: Text("Canvasing"),
  539. content: Text("Failed to Retrieve Data"),
  540. actions: [
  541. noButton,
  542. okButton,
  543. ],
  544. );
  545. // show the dialog
  546. showDialog(
  547. context: context,
  548. barrierDismissible: false,
  549. builder: (BuildContext context) {
  550. return alert;
  551. },
  552. );
  553. }
  554. alertDialogFailedResponse(BuildContext context){
  555. Widget okButton = TextButton(
  556. child: Text("Refresh"),
  557. onPressed: () {
  558. Navigator.of(context, rootNavigator: true).pop();
  559. Navigator.pushReplacement(context, MaterialPageRoute(
  560. builder: (context) => FilingScreen()));
  561. },
  562. );
  563. Widget noButton = TextButton(
  564. child: Text("Back"),
  565. onPressed: () {
  566. Navigator.of(context, rootNavigator: true).pop();
  567. Navigator.pop(context);
  568. },
  569. );
  570. // set up the AlertDialog
  571. AlertDialog alert = AlertDialog(
  572. title: Text("Canvasing"),
  573. content: Text("Server Response Error"),
  574. actions: [
  575. noButton,
  576. okButton,
  577. ],
  578. );
  579. // show the dialog
  580. showDialog(
  581. context: context,
  582. barrierDismissible: false,
  583. builder: (BuildContext context) {
  584. return alert;
  585. },
  586. );
  587. }