Ingen beskrivning
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

settings_screen.dart 41KB

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