Brak opisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

settings_screen.dart 41KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/services.dart';
  5. import 'package:fluttertoast/fluttertoast.dart';
  6. import 'package:google_fonts/google_fonts.dart';
  7. import 'package:employee_selfservice_mobile/Screens/Settings/RequestHttp/changePassword_post.dart';
  8. import 'package:employee_selfservice_mobile/Screens/Settings/RequestHttp/changeprofileimage_post.dart';
  9. import 'package:employee_selfservice_mobile/Screens/Settings/RequestHttp/getDetail_post.dart';
  10. import 'package:employee_selfservice_mobile/Screens/Settings/RequestHttp/getProfileImage_post.dart';
  11. import 'package:employee_selfservice_mobile/Screens/Settings/RequestHttp/logout_post.dart';
  12. import 'package:image_picker/image_picker.dart';
  13. import 'package:progress_dialog_null_safe/progress_dialog_null_safe.dart';
  14. import 'package:shared_preferences/shared_preferences.dart';
  15. import '../Login/login_screen.dart';
  16. import '../Settings/inputWidget.dart';
  17. import 'dart:developer' as logDev;
  18. class SettingsScreen extends StatefulWidget {
  19. const SettingsScreen({Key? key}) : super(key: key);
  20. @override
  21. State<SettingsScreen> createState() => _SettingsScreenState();
  22. }
  23. class _SettingsScreenState extends State<SettingsScreen> {
  24. bool visible = false;
  25. bool visiblePersonalInformation = false;
  26. File? _imagePath;
  27. String name = "",
  28. statusDetail = "",
  29. dateOfBirth = "",
  30. phone = "",
  31. email = "",
  32. address = "",
  33. position = "";
  34. var _imageToShow;
  35. @override
  36. initState() {
  37. super.initState();
  38. passwordController.clear();
  39. newPasswordController.clear();
  40. retypeNewPasswordController.clear();
  41. getDetail();
  42. _imageToShow = AssetImage('assets/images/ic_administrator.png');
  43. WidgetsBinding.instance.addPostFrameCallback((_) {
  44. _imageToShow = getProfileImage();
  45. });
  46. }
  47. //Get Profile image
  48. getProfileImage() async {
  49. final SharedPreferences prefs = await SharedPreferences.getInstance();
  50. final session = prefs.getString('session');
  51. ProgressDialog loading = ProgressDialog(context);
  52. loading = ProgressDialog(context,
  53. type: ProgressDialogType.normal, isDismissible: false, showLogs: true);
  54. loading.style(
  55. message: 'Please Wait .....',
  56. borderRadius: 5,
  57. backgroundColor: Colors.white,
  58. progressWidget: CircularProgressIndicator(),
  59. elevation: 10.0,
  60. padding: EdgeInsets.all(10),
  61. insetAnimCurve: Curves.easeInOut,
  62. progress: 0.0,
  63. maxProgress: 100.0,
  64. progressTextStyle: TextStyle(
  65. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  66. messageTextStyle: TextStyle(
  67. color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600));
  68. await loading.show();
  69. GetProfileImage_Post.connectToAPI(session!).then((valueResult) async {
  70. Map<String, dynamic> object = json.decode(valueResult);
  71. if (object.containsKey("result").toString() == "true") {
  72. String status = object['result']['status'].toString();
  73. logDev.log(status, name: "STATUS GET PROFILE");
  74. if (status == "success") {
  75. String photo = object['result']['photo'].toString();
  76. if (photo == "false") {
  77. setState(() {
  78. _imageToShow = AssetImage('assets/icons/ic_pp_2.png');
  79. });
  80. } else if (photo != "false") {
  81. Uint8List decodedBytes = Base64Decoder().convert(photo);
  82. //logDev.log(decodedBytes.toString(), name: "DECODED BYTES photo");
  83. setState(() {
  84. _imageToShow = Image.memory(decodedBytes, gaplessPlayback: true).image;
  85. });
  86. }
  87. } else if (status == "failed") {
  88. String message = object['result']['message'].toString();
  89. Fluttertoast.showToast(
  90. msg: message,
  91. toastLength: Toast.LENGTH_LONG,
  92. gravity: ToastGravity.CENTER,
  93. timeInSecForIosWeb: 1,
  94. textColor: Colors.white,
  95. fontSize: 16.0);
  96. }
  97. await loading.hide();
  98. } else {
  99. Fluttertoast.showToast(
  100. msg: "Server Response Error",
  101. toastLength: Toast.LENGTH_SHORT,
  102. gravity: ToastGravity.CENTER,
  103. timeInSecForIosWeb: 1,
  104. textColor: Colors.white,
  105. fontSize: 16.0);
  106. await loading.hide();
  107. }
  108. });
  109. await loading.hide();
  110. return _imageToShow;
  111. }
  112. //Get Detail
  113. getDetail() async {
  114. GetDetail_Post.connectToAPI().then((valueResult) async {
  115. Map<String, dynamic> object = json.decode(valueResult);
  116. if (object.containsKey("result").toString() == "true") {
  117. statusDetail = object['result']['status'].toString();
  118. String message = object['result']['message'].toString();
  119. if (statusDetail == "failed" || message == "User Not Found") {
  120. Fluttertoast.showToast(
  121. msg: message + ", Please restart the Application!",
  122. toastLength: Toast.LENGTH_SHORT,
  123. gravity: ToastGravity.CENTER,
  124. timeInSecForIosWeb: 1,
  125. textColor: Colors.white,
  126. fontSize: 16.0);
  127. } else if (statusDetail != "failed") {
  128. name = object['result']['name'].toString();
  129. dateOfBirth = object['result']['date_of_birth'].toString();
  130. phone = object['result']['phone'].toString();
  131. email = object['result']['email'].toString();
  132. address = object['result']['address'].toString();
  133. position = object['result']['position'].toString();
  134. var prefs = await SharedPreferences.getInstance();
  135. if (position == "false"){
  136. position = "-";
  137. await prefs.setString('position', position);
  138. } else {
  139. await prefs.setString('position', position);
  140. }
  141. if (name == "false"){
  142. name = "-";
  143. }
  144. if (dateOfBirth == "false"){
  145. dateOfBirth = "-";
  146. }
  147. if (phone == "false"){
  148. phone = "-";
  149. }
  150. if (email == "false"){
  151. email = "-";
  152. }
  153. if (address == "false"){
  154. address = "-";
  155. }
  156. }
  157. } else {
  158. Fluttertoast.showToast(
  159. msg: "Server Response Error",
  160. toastLength: Toast.LENGTH_SHORT,
  161. gravity: ToastGravity.CENTER,
  162. timeInSecForIosWeb: 1,
  163. textColor: Colors.white,
  164. fontSize: 16.0);
  165. }
  166. });
  167. }
  168. @override
  169. Widget build(BuildContext context) {
  170. var size = MediaQuery.of(context).size;
  171. ProgressDialog loading = ProgressDialog(context);
  172. loading = ProgressDialog(context,
  173. type: ProgressDialogType.normal, isDismissible: false, showLogs: true);
  174. loading.style(
  175. message: 'Please Wait .....',
  176. borderRadius: 5,
  177. backgroundColor: Colors.white,
  178. progressWidget: CircularProgressIndicator(),
  179. elevation: 10.0,
  180. padding: EdgeInsets.all(10),
  181. insetAnimCurve: Curves.easeInOut,
  182. progress: 0.0,
  183. maxProgress: 100.0,
  184. progressTextStyle: TextStyle(
  185. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  186. messageTextStyle: TextStyle(
  187. color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600));
  188. return Scaffold(
  189. body: SingleChildScrollView(
  190. child: Stack(
  191. children: <Widget>[
  192. Container(
  193. height: size.height * 0.3,
  194. decoration: BoxDecoration(
  195. gradient: LinearGradient(
  196. begin: Alignment.topRight,
  197. end: Alignment.bottomRight,
  198. colors: [
  199. Color(0xFF4858A7),
  200. Color(0xFF6474C6),
  201. ])),
  202. ),
  203. SafeArea(
  204. child: Padding(
  205. padding: EdgeInsets.all(20),
  206. child: Column(
  207. children: <Widget>[
  208. Stack(
  209. alignment: Alignment.topCenter,
  210. children: [
  211. Container(
  212. margin: EdgeInsets.only(top: (((size.width - 20) * 0.33) * 0.5)),
  213. child: Card(
  214. elevation: 15,
  215. child: Container(
  216. height: (size.height * 0.28) * .7,
  217. width: size.width - 20,
  218. padding: EdgeInsets.all(15),
  219. decoration: BoxDecoration(
  220. color: Colors.white,
  221. borderRadius:
  222. BorderRadius.all(Radius.circular(10))),
  223. child: Column(
  224. mainAxisAlignment: MainAxisAlignment.end,
  225. crossAxisAlignment: CrossAxisAlignment.center,
  226. children: <Widget>[
  227. Text(name,
  228. maxLines: 2,
  229. overflow: TextOverflow.ellipsis,
  230. textAlign: TextAlign.center,
  231. style: GoogleFonts.inter(
  232. fontSize: size.width*0.045,
  233. color: Colors.black,
  234. fontWeight: FontWeight.bold),
  235. ),
  236. Text(position,
  237. textAlign: TextAlign.center,
  238. style: GoogleFonts.inter(
  239. fontSize: size.width*0.035, color: Colors.black),
  240. ),
  241. ],
  242. )),
  243. ),
  244. ),
  245. Container(
  246. height: (size.width - 20) * 0.33,
  247. width: (size.width - 20) * 0.33,
  248. decoration: BoxDecoration(
  249. color: Colors.black,
  250. image: DecorationImage(
  251. image: _imageToShow,
  252. fit: BoxFit.cover ,
  253. ),
  254. shape: BoxShape.circle,
  255. ),
  256. ),
  257. InkWell(
  258. child: Container(
  259. height: ((size.width - 20) * 0.33) * 0.25,
  260. width: ((size.width - 20) * 0.33) * 0.25,
  261. margin: EdgeInsets.only(
  262. top: (((size.width - 20) * 0.33) - 20),
  263. left: ((size.width - 20) * 0.33) - 10),
  264. decoration: BoxDecoration(
  265. color: Colors.yellow,
  266. image: DecorationImage(
  267. image: AssetImage('assets/images/ic_camera.png'),
  268. scale: 3,
  269. fit: BoxFit.scaleDown,
  270. ),
  271. shape: BoxShape.circle,
  272. ),
  273. ),
  274. onTap: () async {
  275. final ImagePicker _picker = ImagePicker();
  276. final XFile? imagePicked = await _picker.pickImage(
  277. source: ImageSource.gallery);
  278. if (imagePicked != null) {
  279. _imagePath = File(imagePicked.path);
  280. List<int> imageBytes = _imagePath!.readAsBytesSync();
  281. String base64Image = base64Encode(imageBytes);
  282. //logDev.log(base64Image, name: "String base64");
  283. await loading.show();
  284. ChangeProfileImage_Post.connectToAPI(base64Image).then((valueResult) async {
  285. Map<String, dynamic> object = json.decode(valueResult);
  286. if (object.containsKey("result").toString() == "true") {
  287. String status = object['result']['status'].toString();
  288. String message = object['result']['message'].toString();
  289. if (status == "success") {
  290. _imageToShow = FileImage(File(imagePicked.path));
  291. /* Fluttertoast.showToast(
  292. msg: message,
  293. toastLength: Toast.LENGTH_LONG,
  294. gravity: ToastGravity.CENTER,
  295. timeInSecForIosWeb: 1,
  296. textColor: Colors.white,
  297. fontSize: 16.0);*/
  298. await loading.hide();
  299. showAlertDialogChangeProfile(context, "Success, " + message, "Ok");
  300. } else if (status == "failed") {
  301. /* Fluttertoast.showToast(
  302. msg: message,
  303. toastLength: Toast.LENGTH_LONG,
  304. gravity: ToastGravity.CENTER,
  305. timeInSecForIosWeb: 1,
  306. textColor: Colors.white,
  307. fontSize: 16.0);*/
  308. await loading.hide();
  309. showAlertDialogChangeProfile(context, "Failed, " + message, "Back");
  310. }
  311. } else {
  312. Fluttertoast.showToast(
  313. msg: "Server Response Error",
  314. toastLength: Toast.LENGTH_SHORT,
  315. gravity: ToastGravity.CENTER,
  316. timeInSecForIosWeb: 1,
  317. textColor: Colors.white,
  318. fontSize: 16.0);
  319. await loading.hide();
  320. }
  321. setState(() {});
  322. });
  323. } else if (imagePicked == null) {
  324. //_imagePath = await getImageFileFromAssets('assets/images/ic_administrator.png') as File?;
  325. }
  326. },
  327. )
  328. ],
  329. ),
  330. InkWell(
  331. child: roundedRectButton(
  332. "Personal Information", Gradients1, 20, 5),
  333. onTap: () async {
  334. setState(() {
  335. visiblePersonalInformation =
  336. !visiblePersonalInformation;
  337. });
  338. },
  339. ),
  340. Visibility(
  341. visible: visiblePersonalInformation,
  342. child: Container(
  343. margin: EdgeInsets.only(top: 10),
  344. width: size.width - 50,
  345. padding: EdgeInsets.all(15),
  346. decoration: BoxDecoration(
  347. color: Color(0xFFD9D9D9),
  348. borderRadius: BorderRadius.all(Radius.circular(5))),
  349. child: Column(
  350. children: [
  351. Column(
  352. crossAxisAlignment: CrossAxisAlignment.start,
  353. children: <Widget>[
  354. Padding(
  355. padding: EdgeInsets.only(bottom: 5),
  356. child: Text(
  357. "Name",
  358. style: TextStyle(
  359. fontSize: 16, color: Colors.black87),
  360. ),
  361. ),
  362. Stack(
  363. alignment: Alignment.bottomRight,
  364. children: <Widget>[
  365. roundDetail(name, 0, 5, 3),
  366. ],
  367. ),
  368. ],
  369. ),
  370. Column(
  371. crossAxisAlignment: CrossAxisAlignment.start,
  372. children: <Widget>[
  373. Padding(
  374. padding: EdgeInsets.only(bottom: 5),
  375. child: Text(
  376. "Status",
  377. style: TextStyle(
  378. fontSize: 16, color: Colors.black87),
  379. ),
  380. ),
  381. Stack(
  382. alignment: Alignment.bottomRight,
  383. children: <Widget>[
  384. roundDetail(statusDetail, 0, 5, 3),
  385. ],
  386. ),
  387. ],
  388. ),
  389. Column(
  390. crossAxisAlignment: CrossAxisAlignment.start,
  391. children: <Widget>[
  392. Padding(
  393. padding: EdgeInsets.only(bottom: 5),
  394. child: Text(
  395. "Date of Birth",
  396. style: TextStyle(
  397. fontSize: 16, color: Colors.black87),
  398. ),
  399. ),
  400. Stack(
  401. alignment: Alignment.bottomRight,
  402. children: <Widget>[
  403. roundDetail(dateOfBirth, 0, 5, 3),
  404. ],
  405. ),
  406. ],
  407. ),
  408. Column(
  409. crossAxisAlignment: CrossAxisAlignment.start,
  410. children: <Widget>[
  411. Padding(
  412. padding: EdgeInsets.only(bottom: 5),
  413. child: Text(
  414. "Phone Number",
  415. style: TextStyle(
  416. fontSize: 16, color: Colors.black87),
  417. ),
  418. ),
  419. Stack(
  420. alignment: Alignment.bottomRight,
  421. children: <Widget>[
  422. roundDetail(phone, 0, 5, 3),
  423. ],
  424. ),
  425. ],
  426. ),
  427. Column(
  428. crossAxisAlignment: CrossAxisAlignment.start,
  429. children: <Widget>[
  430. Padding(
  431. padding: EdgeInsets.only(bottom: 5),
  432. child: Text(
  433. "Email Address",
  434. style: TextStyle(
  435. fontSize: 16, color: Colors.black87),
  436. ),
  437. ),
  438. Stack(
  439. alignment: Alignment.bottomRight,
  440. children: <Widget>[
  441. roundDetail(email, 0, 5, 3),
  442. ],
  443. ),
  444. ],
  445. ),
  446. Column(
  447. crossAxisAlignment: CrossAxisAlignment.start,
  448. children: <Widget>[
  449. Padding(
  450. padding: EdgeInsets.only(bottom: 5),
  451. child: Text(
  452. "Address",
  453. style: TextStyle(
  454. fontSize: 16, color: Colors.black87),
  455. ),
  456. ),
  457. Stack(
  458. alignment: Alignment.bottomRight,
  459. children: <Widget>[
  460. roundDetail(address, 0, 5, 3),
  461. ],
  462. ),
  463. ],
  464. ),
  465. /*InkWell(
  466. child: roundedRectButton(
  467. "Save Password", Gradients2, 10, 10),
  468. onTap: () {
  469. if (!validateFormSavePassword(context)) {
  470. return;
  471. } else if (validateFormSavePassword(context)) {
  472. if (newPasswordController.text.toString() ==
  473. retypeNewPasswordController.text
  474. .toString()) {
  475. if (passwordController.text.toString() ==
  476. newPasswordController.text
  477. .toString() ||
  478. passwordController.text.toString() ==
  479. retypeNewPasswordController.text
  480. .toString()) {
  481. Fluttertoast.showToast(
  482. msg:
  483. "Your new password is the same with your old password, please change with new password!",
  484. toastLength: Toast.LENGTH_LONG,
  485. gravity: ToastGravity.CENTER,
  486. timeInSecForIosWeb: 1,
  487. textColor: Colors.white,
  488. fontSize: 16.0);
  489. } else {
  490. showAlertDialogSavePassword(context);
  491. }
  492. } else if (newPasswordController.text
  493. .toString() !=
  494. retypeNewPasswordController.text
  495. .toString()) {
  496. Fluttertoast.showToast(
  497. msg:
  498. "Your retype password was entered incorrectly.\nPlease enter it again!",
  499. toastLength: Toast.LENGTH_LONG,
  500. gravity: ToastGravity.CENTER,
  501. timeInSecForIosWeb: 1,
  502. textColor: Colors.white,
  503. fontSize: 16.0);
  504. }
  505. }
  506. }),*/
  507. ],
  508. ),
  509. ),
  510. ),
  511. InkWell(
  512. child:
  513. roundedRectButton("Edit Password", Gradients1, 10, 5),
  514. onTap: () {
  515. setState(() {
  516. visible = !visible;
  517. });
  518. },
  519. ),
  520. Visibility(
  521. visible: visible,
  522. child: Container(
  523. margin: EdgeInsets.only(top: 10),
  524. width: size.width - 50,
  525. padding: EdgeInsets.all(15),
  526. decoration: BoxDecoration(
  527. color: Color(0xFFD9D9D9),
  528. borderRadius: BorderRadius.all(Radius.circular(5))),
  529. child: Column(
  530. children: [
  531. Column(
  532. crossAxisAlignment: CrossAxisAlignment.start,
  533. children: <Widget>[
  534. Padding(
  535. padding: EdgeInsets.only(bottom: 5),
  536. child: Text(
  537. "Type your current Password",
  538. style: TextStyle(
  539. fontSize: 16, color: Colors.black87),
  540. ),
  541. ),
  542. Stack(
  543. alignment: Alignment.bottomRight,
  544. children: <Widget>[
  545. InputWidgetCurrentPassword(
  546. "Current Password"),
  547. ],
  548. ),
  549. ],
  550. ),
  551. Column(
  552. crossAxisAlignment: CrossAxisAlignment.start,
  553. children: <Widget>[
  554. Padding(
  555. padding: EdgeInsets.only(bottom: 5),
  556. child: Text(
  557. "Type your New Password",
  558. style: TextStyle(
  559. fontSize: 16, color: Colors.black87),
  560. ),
  561. ),
  562. Stack(
  563. alignment: Alignment.bottomRight,
  564. children: <Widget>[
  565. InputWidgetNewPassword("New Password"),
  566. ],
  567. ),
  568. ],
  569. ),
  570. Column(
  571. crossAxisAlignment: CrossAxisAlignment.start,
  572. children: <Widget>[
  573. Padding(
  574. padding: EdgeInsets.only(bottom: 5),
  575. child: Text(
  576. "Re-type your New Password",
  577. style: TextStyle(
  578. fontSize: 16, color: Colors.black87),
  579. ),
  580. ),
  581. Stack(
  582. alignment: Alignment.bottomRight,
  583. children: <Widget>[
  584. InputWidgetRetypeNewPassword(
  585. "Re-type New Password"),
  586. ],
  587. ),
  588. ],
  589. ),
  590. InkWell(
  591. child: roundedRectButton(
  592. "Save Password", Gradients2, 10, 10),
  593. onTap: () {
  594. if (!validateFormSavePassword(context)) {
  595. return;
  596. } else if (validateFormSavePassword(context)) {
  597. if (newPasswordController.text.toString() ==
  598. retypeNewPasswordController.text
  599. .toString()) {
  600. if (passwordController.text.toString() ==
  601. newPasswordController.text
  602. .toString() ||
  603. passwordController.text.toString() ==
  604. retypeNewPasswordController.text
  605. .toString()) {
  606. Fluttertoast.showToast(
  607. msg:
  608. "Your new password is the same with your old password, please change with new password!",
  609. toastLength: Toast.LENGTH_LONG,
  610. gravity: ToastGravity.CENTER,
  611. timeInSecForIosWeb: 1,
  612. textColor: Colors.white,
  613. fontSize: 16.0);
  614. } else {
  615. showAlertDialogSavePassword(context);
  616. }
  617. } else if (newPasswordController.text
  618. .toString() !=
  619. retypeNewPasswordController.text
  620. .toString()) {
  621. Fluttertoast.showToast(
  622. msg:
  623. "Your retype password was entered incorrectly.\nPlease enter it again!",
  624. toastLength: Toast.LENGTH_LONG,
  625. gravity: ToastGravity.CENTER,
  626. timeInSecForIosWeb: 1,
  627. textColor: Colors.white,
  628. fontSize: 16.0);
  629. }
  630. }
  631. }),
  632. ],
  633. ),
  634. ),
  635. ),
  636. InkWell(
  637. child: roundedRectButton("Logout", Gradients1, 10, 5),
  638. onTap: () {
  639. showAlertDialogLogout(context);
  640. }),
  641. ],
  642. ),
  643. ),
  644. ),
  645. ],
  646. ),
  647. ));
  648. }
  649. }
  650. Widget roundedRectButton(String title, List<Color> gradient, double marginTop,
  651. double radiusCircular) {
  652. return Builder(builder: (BuildContext mContext) {
  653. return Align(
  654. alignment: Alignment.center,
  655. child: Stack(
  656. children: <Widget>[
  657. Container(
  658. margin: EdgeInsets.only(top: marginTop),
  659. alignment: Alignment.center,
  660. height: 55,
  661. width: MediaQuery.of(mContext).size.width - 50,
  662. decoration: ShapeDecoration(
  663. shape: RoundedRectangleBorder(
  664. borderRadius:
  665. BorderRadius.all(Radius.circular(radiusCircular))),
  666. gradient: LinearGradient(
  667. colors: gradient,
  668. begin: Alignment.topLeft,
  669. end: Alignment.bottomRight),
  670. ),
  671. child: Padding(
  672. padding: EdgeInsets.fromLTRB(10, 3, 10, 3),
  673. child: Text(title,
  674. style: TextStyle(
  675. color: Colors.white,
  676. fontSize: 19,
  677. fontWeight: FontWeight.w500)),
  678. ),
  679. padding: EdgeInsets.all(10),
  680. )
  681. ],
  682. ),
  683. );
  684. });
  685. }
  686. Widget roundDetail(String detail, double marginTop, double marginBottom,
  687. double radiusCircular) {
  688. return Builder(builder: (BuildContext mContext) {
  689. return Align(
  690. alignment: Alignment.center,
  691. child: Stack(
  692. children: <Widget>[
  693. Container(
  694. margin: EdgeInsets.only(top: marginTop, bottom: marginBottom),
  695. alignment: Alignment.centerLeft,
  696. height: 45,
  697. width: MediaQuery.of(mContext).size.width - 50,
  698. decoration: ShapeDecoration(
  699. shape: RoundedRectangleBorder(
  700. borderRadius:
  701. BorderRadius.all(Radius.circular(radiusCircular))),
  702. color: Colors.blueGrey,
  703. ),
  704. child: Padding(
  705. padding: EdgeInsets.fromLTRB(3, 3, 3, 3),
  706. child: Text(detail,
  707. style: TextStyle(
  708. color: Colors.white,
  709. fontSize: 15,
  710. fontWeight: FontWeight.w500)),
  711. ),
  712. padding: EdgeInsets.all(10),
  713. )
  714. ],
  715. ),
  716. );
  717. });
  718. }
  719. const List<Color> Gradients1 = [
  720. //Color(0xFF0EDED2),
  721. Color(0xFF03A0FE),
  722. Color(0xFF4858A7),
  723. //Color(0xFF6474C6),
  724. ];
  725. const List<Color> Gradients2 = [
  726. Color(0xFFFF9945),
  727. Color(0xFFFc6076),
  728. ];
  729. //Save New Password
  730. showAlertDialogSavePassword(BuildContext context) {
  731. // set up the button
  732. Widget okButton = TextButton(
  733. child: Text("Yes"),
  734. onPressed: () async {
  735. ProgressDialog loading = ProgressDialog(context);
  736. loading = ProgressDialog(context,
  737. type: ProgressDialogType.normal,
  738. isDismissible: false,
  739. showLogs: true);
  740. loading.style(
  741. message: 'Please Wait .....',
  742. borderRadius: 5,
  743. backgroundColor: Colors.white,
  744. progressWidget: CircularProgressIndicator(),
  745. elevation: 10.0,
  746. padding: EdgeInsets.all(10),
  747. insetAnimCurve: Curves.easeInOut,
  748. progress: 0.0,
  749. maxProgress: 100.0,
  750. progressTextStyle: TextStyle(
  751. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  752. messageTextStyle: TextStyle(
  753. color: Colors.black,
  754. fontSize: 15.0,
  755. fontWeight: FontWeight.w600));
  756. await loading.show();
  757. ChangePassword_Post.connectToAPI(passwordController.text.toString(), newPasswordController.text.toString()).then((valueResult) async {
  758. Map<String, dynamic> object = json.decode(valueResult);
  759. if (object.containsKey("result").toString() == "true") {
  760. String status = object['result']['status'].toString();
  761. String message = object['result']['message'].toString();
  762. if (status == "success") {
  763. Fluttertoast.showToast(
  764. msg: message + ", Please login again!",
  765. toastLength: Toast.LENGTH_SHORT,
  766. gravity: ToastGravity.CENTER,
  767. timeInSecForIosWeb: 1,
  768. textColor: Colors.white,
  769. fontSize: 16.0);
  770. passwordController.clear();
  771. newPasswordController.clear();
  772. retypeNewPasswordController.clear();
  773. final SharedPreferences prefs = await SharedPreferences.getInstance();
  774. await prefs.remove('session');
  775. await loading.hide();
  776. Navigator.of(context, rootNavigator: true).pop();
  777. Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => LoginView()));
  778. } else if (status == "failed") {
  779. Fluttertoast.showToast(
  780. msg: message,
  781. toastLength: Toast.LENGTH_SHORT,
  782. gravity: ToastGravity.CENTER,
  783. timeInSecForIosWeb: 1,
  784. textColor: Colors.white,
  785. fontSize: 16.0);
  786. Navigator.of(context, rootNavigator: true).pop();
  787. await loading.hide();
  788. }
  789. } else {
  790. Fluttertoast.showToast(
  791. msg: "Server Response Error",
  792. toastLength: Toast.LENGTH_SHORT,
  793. gravity: ToastGravity.CENTER,
  794. timeInSecForIosWeb: 1,
  795. textColor: Colors.white,
  796. fontSize: 16.0);
  797. await loading.hide();
  798. }
  799. });
  800. },
  801. );
  802. Widget noButton = TextButton(
  803. child: Text("No"),
  804. onPressed: () {
  805. Navigator.of(context, rootNavigator: true).pop();
  806. },
  807. );
  808. // set up the AlertDialog
  809. AlertDialog alert = AlertDialog(
  810. title: Text("Employee Self Service"),
  811. content: Text("Save New Password?"),
  812. actions: [noButton, okButton],
  813. );
  814. // show the dialog
  815. showDialog(
  816. context: context,
  817. barrierDismissible: false,
  818. builder: (BuildContext context) {
  819. return alert;
  820. },
  821. );
  822. }
  823. //Validate Form Change Password
  824. bool validateFormSavePassword(BuildContext context) {
  825. bool result = true;
  826. if (passwordController.text.toString().isEmpty) {
  827. Fluttertoast.showToast(
  828. msg: "Old Password Required!",
  829. toastLength: Toast.LENGTH_SHORT,
  830. gravity: ToastGravity.CENTER,
  831. timeInSecForIosWeb: 1,
  832. textColor: Colors.white,
  833. fontSize: 16.0);
  834. result = false;
  835. }
  836. if (newPasswordController.text.toString().isEmpty) {
  837. Fluttertoast.showToast(
  838. msg: "New Password Required",
  839. toastLength: Toast.LENGTH_SHORT,
  840. gravity: ToastGravity.CENTER,
  841. timeInSecForIosWeb: 1,
  842. textColor: Colors.white,
  843. fontSize: 16.0);
  844. result = false;
  845. }
  846. if (retypeNewPasswordController.text.toString().isEmpty) {
  847. Fluttertoast.showToast(
  848. msg: "Retype New Password Required",
  849. toastLength: Toast.LENGTH_SHORT,
  850. gravity: ToastGravity.CENTER,
  851. timeInSecForIosWeb: 1,
  852. textColor: Colors.white,
  853. fontSize: 16.0);
  854. result = false;
  855. }
  856. return result;
  857. }
  858. //LOGOUT
  859. showAlertDialogLogout(BuildContext context) {
  860. // set up the button
  861. Widget okButton = TextButton(
  862. child: Text("Yes"),
  863. onPressed: () async {
  864. ProgressDialog loading = ProgressDialog(context);
  865. loading = ProgressDialog(context,
  866. type: ProgressDialogType.normal,
  867. isDismissible: false,
  868. showLogs: true);
  869. loading.style(
  870. message: 'Please Wait .....',
  871. borderRadius: 5,
  872. backgroundColor: Colors.white,
  873. progressWidget: CircularProgressIndicator(),
  874. elevation: 10.0,
  875. padding: EdgeInsets.all(10),
  876. insetAnimCurve: Curves.easeInOut,
  877. progress: 0.0,
  878. maxProgress: 100.0,
  879. progressTextStyle: TextStyle(
  880. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  881. messageTextStyle: TextStyle(
  882. color: Colors.black,
  883. fontSize: 15.0,
  884. fontWeight: FontWeight.w600));
  885. await loading.show();
  886. Logout_Post.connectToAPI().then((valueResult) async {
  887. Map<String, dynamic> object = json.decode(valueResult);
  888. if (object.containsKey("result").toString() == "true") {
  889. String status = object['result']['status'].toString();
  890. if (status == "success") {
  891. final SharedPreferences prefs = await SharedPreferences.getInstance();
  892. await prefs.remove('session');
  893. Navigator.of(context, rootNavigator: true).pop();
  894. await loading.hide();
  895. Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: (context) => LoginView()), (route) => false);
  896. } else if (status == "failed") {
  897. String message = object['result']['message'].toString();
  898. Fluttertoast.showToast(
  899. msg: message,
  900. toastLength: Toast.LENGTH_SHORT,
  901. gravity: ToastGravity.CENTER,
  902. timeInSecForIosWeb: 1,
  903. textColor: Colors.white,
  904. fontSize: 16.0);
  905. await loading.hide();
  906. Navigator.of(context, rootNavigator: true).pop();
  907. }
  908. } else {
  909. Fluttertoast.showToast(
  910. msg: "Server Response Error",
  911. toastLength: Toast.LENGTH_SHORT,
  912. gravity: ToastGravity.CENTER,
  913. timeInSecForIosWeb: 1,
  914. textColor: Colors.white,
  915. fontSize: 16.0);
  916. await loading.hide();
  917. Navigator.of(context, rootNavigator: true).pop();
  918. }
  919. });
  920. },
  921. );
  922. Widget noButton = TextButton(
  923. child: Text("No"),
  924. onPressed: () {
  925. Navigator.of(context, rootNavigator: true).pop();
  926. },
  927. );
  928. // set up the AlertDialog
  929. AlertDialog alert = AlertDialog(
  930. title: Text("Employee Self Service"),
  931. content: Text("Are you sure you want to logout from this Application?"),
  932. //content: Text("Apakah Anda yakin ingin keluar dari aplikasi ini?"),
  933. actions: [noButton, okButton],
  934. );
  935. // show the dialog
  936. showDialog(
  937. context: context,
  938. barrierDismissible: false,
  939. builder: (BuildContext context) {
  940. return alert;
  941. },
  942. );
  943. }
  944. //Alert Change Profile
  945. showAlertDialogChangeProfile(BuildContext context, String message, String buttonMessage) {
  946. // set up the button
  947. Widget okButton = TextButton(
  948. child: Text(buttonMessage),
  949. onPressed: () {
  950. Navigator.of(context, rootNavigator: true).pop();
  951. },
  952. );
  953. // set up the AlertDialog
  954. AlertDialog alert = AlertDialog(
  955. title: Text("Employee Self Service"),
  956. content: Text(message),
  957. actions: [okButton],
  958. );
  959. // show the dialog
  960. showDialog(
  961. context: context,
  962. barrierDismissible: false,
  963. builder: (BuildContext context) {
  964. return alert;
  965. },
  966. );
  967. }