Нема описа
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

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