No Description
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 42KB

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