GSI - Employe Self Service Mobile
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.

1008 lines
41 KiB

2 months ago
  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, double radiusCircular) {
  651. return Builder(builder: (BuildContext mContext) {
  652. return Align(
  653. alignment: Alignment.center,
  654. child: Stack(
  655. children: <Widget>[
  656. Container(
  657. margin: EdgeInsets.only(top: marginTop),
  658. alignment: Alignment.center,
  659. height: 55,
  660. width: MediaQuery.of(mContext).size.width - 50,
  661. decoration: ShapeDecoration(
  662. shape: RoundedRectangleBorder(
  663. borderRadius:
  664. BorderRadius.all(Radius.circular(radiusCircular))),
  665. gradient: LinearGradient(
  666. colors: gradient,
  667. begin: Alignment.topLeft,
  668. end: Alignment.bottomRight),
  669. ),
  670. child: Padding(
  671. padding: EdgeInsets.fromLTRB(10, 3, 10, 3),
  672. child: Text(title,
  673. style: TextStyle(
  674. color: Colors.white,
  675. fontSize: 19,
  676. fontWeight: FontWeight.w500)),
  677. ),
  678. padding: EdgeInsets.all(10),
  679. )
  680. ],
  681. ),
  682. );
  683. });
  684. }
  685. Widget roundDetail(String detail, double marginTop, double marginBottom, double radiusCircular) {
  686. return Builder(builder: (BuildContext mContext) {
  687. return Align(
  688. alignment: Alignment.center,
  689. child: Stack(
  690. children: <Widget>[
  691. Container(
  692. margin: EdgeInsets.only(top: marginTop, bottom: marginBottom),
  693. alignment: Alignment.centerLeft,
  694. height: 45,
  695. width: MediaQuery.of(mContext).size.width - 50,
  696. decoration: ShapeDecoration(
  697. shape: RoundedRectangleBorder(
  698. borderRadius:
  699. BorderRadius.all(Radius.circular(radiusCircular))),
  700. color: Colors.blueGrey,
  701. ),
  702. child: Padding(
  703. padding: EdgeInsets.fromLTRB(3, 3, 3, 3),
  704. child: Text(detail,
  705. style: TextStyle(
  706. color: Colors.white,
  707. fontSize: 15,
  708. fontWeight: FontWeight.w500)),
  709. ),
  710. padding: EdgeInsets.all(10),
  711. )
  712. ],
  713. ),
  714. );
  715. });
  716. }
  717. const List<Color> Gradients1 = [
  718. //Color(0xFF0EDED2),
  719. Color(0xFF03A0FE),
  720. Color(0xFF4858A7),
  721. //Color(0xFF6474C6),
  722. ];
  723. const List<Color> Gradients2 = [
  724. Color(0xFFFF9945),
  725. Color(0xFFFc6076),
  726. ];
  727. //Save New Password
  728. showAlertDialogSavePassword(BuildContext context) {
  729. // set up the button
  730. Widget okButton = TextButton(
  731. child: Text("Yes"),
  732. onPressed: () async {
  733. ProgressDialog loading = ProgressDialog(context);
  734. loading = ProgressDialog(context,
  735. type: ProgressDialogType.normal,
  736. isDismissible: false,
  737. showLogs: true);
  738. loading.style(
  739. message: 'Please Wait .....',
  740. borderRadius: 5,
  741. backgroundColor: Colors.white,
  742. progressWidget: CircularProgressIndicator(),
  743. elevation: 10.0,
  744. padding: EdgeInsets.all(10),
  745. insetAnimCurve: Curves.easeInOut,
  746. progress: 0.0,
  747. maxProgress: 100.0,
  748. progressTextStyle: TextStyle(
  749. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  750. messageTextStyle: TextStyle(
  751. color: Colors.black,
  752. fontSize: 15.0,
  753. fontWeight: FontWeight.w600));
  754. await loading.show();
  755. ChangePassword_Post.connectToAPI(passwordController.text.toString(), newPasswordController.text.toString()).then((valueResult) async {
  756. Map<String, dynamic> object = json.decode(valueResult);
  757. if (object.containsKey("result").toString() == "true") {
  758. String status = object['result']['status'].toString();
  759. String message = object['result']['message'].toString();
  760. if (status == "success") {
  761. Fluttertoast.showToast(
  762. msg: message + ", Please login again!",
  763. toastLength: Toast.LENGTH_SHORT,
  764. gravity: ToastGravity.CENTER,
  765. timeInSecForIosWeb: 1,
  766. textColor: Colors.white,
  767. fontSize: 16.0);
  768. passwordController.clear();
  769. newPasswordController.clear();
  770. retypeNewPasswordController.clear();
  771. final SharedPreferences prefs = await SharedPreferences.getInstance();
  772. await prefs.remove('session');
  773. await loading.hide();
  774. Navigator.of(context, rootNavigator: true).pop();
  775. Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => LoginView()));
  776. } else if (status == "failed") {
  777. Fluttertoast.showToast(
  778. msg: message,
  779. toastLength: Toast.LENGTH_SHORT,
  780. gravity: ToastGravity.CENTER,
  781. timeInSecForIosWeb: 1,
  782. textColor: Colors.white,
  783. fontSize: 16.0);
  784. Navigator.of(context, rootNavigator: true).pop();
  785. await loading.hide();
  786. }
  787. } else {
  788. Fluttertoast.showToast(
  789. msg: "Server Response Error",
  790. toastLength: Toast.LENGTH_SHORT,
  791. gravity: ToastGravity.CENTER,
  792. timeInSecForIosWeb: 1,
  793. textColor: Colors.white,
  794. fontSize: 16.0);
  795. await loading.hide();
  796. }
  797. });
  798. },
  799. );
  800. Widget noButton = TextButton(
  801. child: Text("No"),
  802. onPressed: () {
  803. Navigator.of(context, rootNavigator: true).pop();
  804. },
  805. );
  806. // set up the AlertDialog
  807. AlertDialog alert = AlertDialog(
  808. title: Text("Employee Self Service"),
  809. content: Text("Save New Password?"),
  810. actions: [noButton, okButton],
  811. );
  812. // show the dialog
  813. showDialog(
  814. context: context,
  815. barrierDismissible: false,
  816. builder: (BuildContext context) {
  817. return alert;
  818. },
  819. );
  820. }
  821. //Validate Form Change Password
  822. bool validateFormSavePassword(BuildContext context) {
  823. bool result = true;
  824. if (passwordController.text.toString().isEmpty) {
  825. Fluttertoast.showToast(
  826. msg: "Old Password Required!",
  827. toastLength: Toast.LENGTH_SHORT,
  828. gravity: ToastGravity.CENTER,
  829. timeInSecForIosWeb: 1,
  830. textColor: Colors.white,
  831. fontSize: 16.0);
  832. result = false;
  833. }
  834. if (newPasswordController.text.toString().isEmpty) {
  835. Fluttertoast.showToast(
  836. msg: "New Password Required",
  837. toastLength: Toast.LENGTH_SHORT,
  838. gravity: ToastGravity.CENTER,
  839. timeInSecForIosWeb: 1,
  840. textColor: Colors.white,
  841. fontSize: 16.0);
  842. result = false;
  843. }
  844. if (retypeNewPasswordController.text.toString().isEmpty) {
  845. Fluttertoast.showToast(
  846. msg: "Retype New Password Required",
  847. toastLength: Toast.LENGTH_SHORT,
  848. gravity: ToastGravity.CENTER,
  849. timeInSecForIosWeb: 1,
  850. textColor: Colors.white,
  851. fontSize: 16.0);
  852. result = false;
  853. }
  854. return result;
  855. }
  856. //LOGOUT
  857. showAlertDialogLogout(BuildContext context) {
  858. // set up the button
  859. Widget okButton = TextButton(
  860. child: Text("Yes"),
  861. onPressed: () async {
  862. ProgressDialog loading = ProgressDialog(context);
  863. loading = ProgressDialog(context,
  864. type: ProgressDialogType.normal,
  865. isDismissible: false,
  866. showLogs: true);
  867. loading.style(
  868. message: 'Please Wait .....',
  869. borderRadius: 5,
  870. backgroundColor: Colors.white,
  871. progressWidget: CircularProgressIndicator(),
  872. elevation: 10.0,
  873. padding: EdgeInsets.all(10),
  874. insetAnimCurve: Curves.easeInOut,
  875. progress: 0.0,
  876. maxProgress: 100.0,
  877. progressTextStyle: TextStyle(
  878. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  879. messageTextStyle: TextStyle(
  880. color: Colors.black,
  881. fontSize: 15.0,
  882. fontWeight: FontWeight.w600));
  883. await loading.show();
  884. Logout_Post.connectToAPI().then((valueResult) async {
  885. Map<String, dynamic> object = json.decode(valueResult);
  886. if (object.containsKey("result").toString() == "true") {
  887. String status = object['result']['status'].toString();
  888. if (status == "success") {
  889. final SharedPreferences prefs = await SharedPreferences.getInstance();
  890. await prefs.remove('session');
  891. Navigator.of(context, rootNavigator: true).pop();
  892. await loading.hide();
  893. Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: (context) => LoginView()), (route) => false);
  894. } else if (status == "failed") {
  895. String message = object['result']['message'].toString();
  896. Fluttertoast.showToast(
  897. msg: message,
  898. toastLength: Toast.LENGTH_SHORT,
  899. gravity: ToastGravity.CENTER,
  900. timeInSecForIosWeb: 1,
  901. textColor: Colors.white,
  902. fontSize: 16.0);
  903. await loading.hide();
  904. Navigator.of(context, rootNavigator: true).pop();
  905. }
  906. } else {
  907. Fluttertoast.showToast(
  908. msg: "Server Response Error",
  909. toastLength: Toast.LENGTH_SHORT,
  910. gravity: ToastGravity.CENTER,
  911. timeInSecForIosWeb: 1,
  912. textColor: Colors.white,
  913. fontSize: 16.0);
  914. await loading.hide();
  915. Navigator.of(context, rootNavigator: true).pop();
  916. }
  917. });
  918. },
  919. );
  920. Widget noButton = TextButton(
  921. child: Text("No"),
  922. onPressed: () {
  923. Navigator.of(context, rootNavigator: true).pop();
  924. },
  925. );
  926. // set up the AlertDialog
  927. AlertDialog alert = AlertDialog(
  928. title: Text("Employee Self Service"),
  929. content: Text("Are you sure you want to logout from this Application?"),
  930. //content: Text("Apakah Anda yakin ingin keluar dari aplikasi ini?"),
  931. actions: [noButton, okButton],
  932. );
  933. // show the dialog
  934. showDialog(
  935. context: context,
  936. barrierDismissible: false,
  937. builder: (BuildContext context) {
  938. return alert;
  939. },
  940. );
  941. }
  942. //Alert Change Profile
  943. showAlertDialogChangeProfile(BuildContext context, String message, String buttonMessage) {
  944. // set up the button
  945. Widget okButton = TextButton(
  946. child: Text(buttonMessage),
  947. onPressed: () {
  948. Navigator.of(context, rootNavigator: true).pop();
  949. },
  950. );
  951. // set up the AlertDialog
  952. AlertDialog alert = AlertDialog(
  953. title: Text("Employee Self Service"),
  954. content: Text(message),
  955. actions: [okButton],
  956. );
  957. // show the dialog
  958. showDialog(
  959. context: context,
  960. barrierDismissible: false,
  961. builder: (BuildContext context) {
  962. return alert;
  963. },
  964. );
  965. }