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.

home_screen.dart 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. import 'dart:convert';
  2. import 'dart:typed_data';
  3. import 'package:double_back_to_close/double_back_to_close.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:fluttertoast/fluttertoast.dart';
  6. import 'package:google_fonts/google_fonts.dart';
  7. import 'package:hris_selfservice_mobile/Screens/Menu/About/about_screen.dart';
  8. import 'package:hris_selfservice_mobile/Screens/Menu/Absensi/absensi_screen.dart';
  9. import 'package:hris_selfservice_mobile/Screens/Menu/AjukanCuti/ajukancuti_screen.dart';
  10. import 'package:hris_selfservice_mobile/Screens/Menu/Reimburse/reimburse_screen.dart';
  11. import 'package:hris_selfservice_mobile/Screens/Menu/SlipGaji/slipgaji_screen.dart';
  12. import 'package:hris_selfservice_mobile/Screens/Menu/SuratTugas/surattugas_screen.dart';
  13. import 'package:hris_selfservice_mobile/Screens/Settings/settings_screen.dart';
  14. import 'package:progress_dialog_null_safe/progress_dialog_null_safe.dart';
  15. import 'package:shared_preferences/shared_preferences.dart';
  16. import 'dart:developer' as logDev;
  17. import '../Settings/RequestHttp/getDetail_post.dart';
  18. import '../Settings/RequestHttp/getProfileImage_post.dart';
  19. import 'package:location/location.dart';
  20. var _imageToShow;
  21. late String nameShared;
  22. String name = "",
  23. statusDetail = "",
  24. dateOfBirth = "",
  25. phone = "",
  26. email = "",
  27. address = "",
  28. position = "";
  29. class HomeView extends StatefulWidget {
  30. @override
  31. _HomeView createState() => _HomeView();
  32. }
  33. class _HomeView extends State<HomeView> {
  34. @override
  35. initState() {
  36. getDetail();
  37. _imageToShow = AssetImage('assets/images/ic_administrator.png');
  38. WidgetsBinding.instance.addPostFrameCallback((_) async {
  39. /* final location = await getLocation();
  40. logDev.log("Location: ${location.latitude}, ${location.longitude}");*/
  41. ProgressDialog loading = ProgressDialog(context);
  42. loading = ProgressDialog(context,
  43. type: ProgressDialogType.normal,
  44. isDismissible: false,
  45. showLogs: true);
  46. loading.style(
  47. message: 'Please Wait .....',
  48. borderRadius: 5,
  49. backgroundColor: Colors.white,
  50. progressWidget: CircularProgressIndicator(),
  51. elevation: 10.0,
  52. padding: EdgeInsets.all(10),
  53. insetAnimCurve: Curves.easeInOut,
  54. progress: 0.0,
  55. maxProgress: 100.0,
  56. progressTextStyle: TextStyle(
  57. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  58. messageTextStyle: TextStyle(
  59. color: Colors.black,
  60. fontSize: 15.0,
  61. fontWeight: FontWeight.w600));
  62. loading.show();
  63. _imageToShow = getProfileImage();
  64. });
  65. }
  66. //Get Profile image
  67. getProfileImage() async {
  68. final SharedPreferences prefs = await SharedPreferences.getInstance();
  69. final session = prefs.getString('session');
  70. ProgressDialog loading = ProgressDialog(context);
  71. loading = ProgressDialog(context,
  72. type: ProgressDialogType.normal,
  73. isDismissible: false,
  74. showLogs: true);
  75. loading.style(
  76. message: 'Please Wait .....',
  77. borderRadius: 5,
  78. backgroundColor: Colors.white,
  79. progressWidget: CircularProgressIndicator(),
  80. elevation: 10.0,
  81. padding: EdgeInsets.all(10),
  82. insetAnimCurve: Curves.easeInOut,
  83. progress: 0.0,
  84. maxProgress: 100.0,
  85. progressTextStyle: TextStyle(
  86. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  87. messageTextStyle: TextStyle(
  88. color: Colors.black,
  89. fontSize: 15.0,
  90. 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. setState(() {
  100. _imageToShow = AssetImage('assets/images/ic_administrator.png');
  101. });
  102. } else if (photo != "false") {
  103. Uint8List decodedBytes = Base64Decoder().convert(photo);
  104. logDev.log(decodedBytes.toString(), name: "DECODED BYTES photo");
  105. setState(() {
  106. _imageToShow = Image
  107. .memory(decodedBytes, gaplessPlayback: true)
  108. .image;
  109. });
  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 _imageToShow;
  134. }
  135. //GetDetail
  136. getDetail() async {
  137. final SharedPreferences prefs = await SharedPreferences.getInstance();
  138. final session = prefs.getString('session');
  139. GetDetail_Post.connectToAPI(session!).then((valueResult) async {
  140. Map<String, dynamic> object = json.decode(valueResult);
  141. if (object.containsKey("result").toString() == "true") {
  142. statusDetail = object['result']['status'].toString();
  143. String message = object['result']['message'].toString();
  144. if (statusDetail == "failed" || message == "User Not Found") {
  145. Fluttertoast.showToast(
  146. msg: message + ", Please login again!",
  147. toastLength: Toast.LENGTH_SHORT,
  148. gravity: ToastGravity.CENTER,
  149. timeInSecForIosWeb: 1,
  150. textColor: Colors.white,
  151. fontSize: 16.0);
  152. } else if (statusDetail != "failed") {
  153. name = object['result']['name'].toString();
  154. dateOfBirth = object['result']['date_of_birth'].toString();
  155. phone = object['result']['phone'].toString();
  156. email = object['result']['email'].toString();
  157. address = object['result']['address'].toString();
  158. position = object['result']['position'].toString();
  159. }
  160. } else {
  161. Fluttertoast.showToast(
  162. msg: "Server Response Error",
  163. toastLength: Toast.LENGTH_SHORT,
  164. gravity: ToastGravity.CENTER,
  165. timeInSecForIosWeb: 1,
  166. textColor: Colors.white,
  167. fontSize: 16.0);
  168. }
  169. });
  170. }
  171. @override
  172. Widget build(BuildContext context) {
  173. return MaterialApp(
  174. home: DoubleBack(
  175. /*onFirstBackPress: (context) {
  176. final snackBar = SnackBar(content: Text("Double Back Press to Exit"));
  177. ScaffoldMessenger.of(context).showSnackBar(snackBar);
  178. },*/
  179. message: "Double Back Press to Exit",
  180. background: Colors.black38,
  181. backgroundRadius: 10,
  182. textStyle: TextStyle(
  183. fontSize: 16, fontWeight: FontWeight.bold, color: Colors.white),
  184. child: Scaffold(
  185. resizeToAvoidBottomInset: false,
  186. //backgroundColor: Colors.white,
  187. body: Stack(
  188. children: <Widget>[
  189. //Background(),
  190. HomeScreen(),
  191. ],
  192. )),
  193. ),
  194. );
  195. }
  196. }
  197. class HomeScreen extends StatelessWidget {
  198. @override
  199. Widget build(BuildContext context) {
  200. var size = MediaQuery.of(context).size;
  201. return Scaffold(
  202. body: SingleChildScrollView(
  203. child: Stack(
  204. children: <Widget>[
  205. Container(
  206. height: size.height * 0.3,
  207. decoration: BoxDecoration(
  208. gradient: LinearGradient(
  209. begin: Alignment.topRight,
  210. end: Alignment.bottomRight,
  211. colors: [
  212. Color(0xFFD21404),
  213. Color(0xFFFD7267),
  214. ])),
  215. ),
  216. SafeArea(
  217. child: Padding(
  218. padding: EdgeInsets.all(20),
  219. child: Column(
  220. children: <Widget>[
  221. Align(
  222. alignment: Alignment.topRight,
  223. child: InkWell(
  224. child: Container(
  225. alignment: Alignment.center,
  226. height: 40,
  227. width: 40,
  228. child: Image.asset('assets/images/ic_settings.png')),
  229. onTap: () {
  230. Navigator.push(
  231. context,
  232. MaterialPageRoute(
  233. builder: (context) => SettingsScreen()));
  234. },
  235. ),
  236. ),
  237. Container(
  238. child: Stack(
  239. alignment: Alignment.topLeft,
  240. children: [
  241. Container(
  242. margin: EdgeInsets.only(top: ((size.width - 20) * 0.33) * 0.5),
  243. child: Card(
  244. elevation: 15,
  245. child: Container(
  246. height: size.width * 0.35,
  247. width: size.width - 20,
  248. padding: EdgeInsets.all(15),
  249. decoration: BoxDecoration(
  250. color: Colors.white,
  251. borderRadius:
  252. BorderRadius.all(Radius.circular(10))),
  253. child: Column(
  254. mainAxisAlignment: MainAxisAlignment.end,
  255. crossAxisAlignment: CrossAxisAlignment.center,
  256. children: <Widget>[
  257. Text(name,
  258. maxLines: 2,
  259. overflow: TextOverflow.ellipsis,
  260. textAlign: TextAlign.center,
  261. style: GoogleFonts.inter(
  262. fontSize: 18,
  263. color: Colors.black,
  264. fontWeight: FontWeight.bold),
  265. ),
  266. Text(position,
  267. textAlign: TextAlign.center,
  268. style: GoogleFonts.inter(
  269. fontSize: 17, color: Colors.black),
  270. ),
  271. ],
  272. )),
  273. ),
  274. ),
  275. Align(
  276. alignment: Alignment.topCenter,
  277. child: Container(
  278. margin: EdgeInsets.only(left: 15),
  279. alignment: Alignment.topLeft,
  280. height: (size.width - 20) * 0.33,
  281. width: (size.width - 20) * 0.33,
  282. decoration: BoxDecoration(
  283. color: Colors.black,
  284. image: DecorationImage(
  285. image: _imageToShow,
  286. fit: BoxFit.fill,
  287. ),
  288. shape: BoxShape.circle,
  289. ),
  290. ),
  291. ),
  292. ],
  293. ),
  294. ),
  295. GridView.count(
  296. shrinkWrap: true,
  297. physics: NeverScrollableScrollPhysics(),
  298. padding: EdgeInsets.only(top: 25, left: 5, right: 5),
  299. crossAxisSpacing: 15,
  300. mainAxisSpacing: 15,
  301. crossAxisCount: 2,
  302. children: <Widget>[
  303. InkWell(
  304. child: Container(
  305. decoration: BoxDecoration(
  306. color: Color(0xFFD0D0D0),
  307. borderRadius: BorderRadius.circular(5)),
  308. child: Column(
  309. crossAxisAlignment: CrossAxisAlignment.center,
  310. mainAxisAlignment: MainAxisAlignment.center,
  311. children: <Widget>[
  312. Container(
  313. width: 75,
  314. height: 75,
  315. child: Image.asset(
  316. "assets/icons/menu/ic_absensi.png",
  317. fit: BoxFit.fill,
  318. alignment: Alignment.center,
  319. ),
  320. ),
  321. Container(
  322. margin: EdgeInsets.only(top: 10),
  323. padding: EdgeInsets.all(5),
  324. child: Text(
  325. 'Attendance',
  326. textAlign: TextAlign.center,
  327. style: GoogleFonts.acme(
  328. fontSize: 18, color: Colors.black),
  329. ),
  330. ),
  331. ],
  332. ),
  333. ),
  334. onTap: () {
  335. Navigator.push(
  336. context,
  337. MaterialPageRoute(
  338. builder: (context) => AbsensiScreen()));
  339. }),
  340. InkWell(
  341. child: Container(
  342. decoration: BoxDecoration(
  343. color: Color(0xFFD0D0D0),
  344. borderRadius: BorderRadius.circular(5)),
  345. child: Column(
  346. crossAxisAlignment: CrossAxisAlignment.center,
  347. mainAxisAlignment: MainAxisAlignment.center,
  348. children: <Widget>[
  349. Container(
  350. width: 75,
  351. height: 75,
  352. child: Image.asset(
  353. "assets/icons/menu/ic_slipgaji_2.png",
  354. fit: BoxFit.fill,
  355. alignment: Alignment.center),
  356. ),
  357. Container(
  358. margin: EdgeInsets.only(top: 10),
  359. padding: EdgeInsets.all(5),
  360. child: Text(
  361. 'Salary Slip',
  362. textAlign: TextAlign.center,
  363. style: GoogleFonts.acme(
  364. fontSize: 18, color: Colors.black),
  365. ),
  366. ),
  367. ],
  368. ),
  369. ),
  370. onTap: () {
  371. Navigator.push(
  372. context,
  373. MaterialPageRoute(
  374. builder: (context) => SlipGajiScreen()));
  375. },
  376. ),
  377. InkWell(
  378. child: Container(
  379. decoration: BoxDecoration(
  380. color: Color(0xFFD0D0D0),
  381. borderRadius: BorderRadius.circular(5)),
  382. child: Column(
  383. crossAxisAlignment: CrossAxisAlignment.center,
  384. mainAxisAlignment: MainAxisAlignment.center,
  385. children: <Widget>[
  386. Container(
  387. width: 70,
  388. height: 70,
  389. child: Image.asset(
  390. "assets/icons/menu/ic_cuti_2.png",
  391. fit: BoxFit.fill,
  392. alignment: Alignment.center),
  393. ),
  394. Container(
  395. margin: EdgeInsets.only(top: 10),
  396. padding: EdgeInsets.all(5),
  397. child: Text(
  398. 'Time Off Submission',
  399. textAlign: TextAlign.center,
  400. style: GoogleFonts.acme(
  401. fontSize: 18, color: Colors.black),
  402. ),
  403. ),
  404. ],
  405. ),
  406. ),
  407. onTap: () {
  408. Navigator.push(
  409. context,
  410. MaterialPageRoute(
  411. builder: (context) => AjukanCutiScreen()));
  412. },
  413. ),
  414. /*InkWell(
  415. child: Container(
  416. decoration: BoxDecoration(
  417. color: Color(0xFFD0D0D0),
  418. borderRadius: BorderRadius.circular(5)),
  419. child: Column(
  420. crossAxisAlignment: CrossAxisAlignment.center,
  421. mainAxisAlignment: MainAxisAlignment.center,
  422. children: <Widget>[
  423. Container(
  424. width: 75,
  425. height: 75,
  426. child: Image.asset(
  427. "assets/icons/menu/ic_menu_berita2.png"),
  428. ),
  429. Container(
  430. margin: EdgeInsets.only(top: 10),
  431. padding: EdgeInsets.all(5),
  432. child: Text(
  433. 'Berita',
  434. textAlign: TextAlign.center,
  435. style: GoogleFonts.acme(
  436. fontSize: 18, color: Colors.black),
  437. ),
  438. ),
  439. ],
  440. ),
  441. ),
  442. onTap: () {
  443. Navigator.push(
  444. context,
  445. MaterialPageRoute(
  446. builder: (context) => BeritaScreen()));
  447. },
  448. ),*/
  449. InkWell(
  450. child: Container(
  451. decoration: BoxDecoration(
  452. color: Color(0xFFD0D0D0),
  453. borderRadius: BorderRadius.circular(5)),
  454. child: Column(
  455. crossAxisAlignment: CrossAxisAlignment.center,
  456. mainAxisAlignment: MainAxisAlignment.center,
  457. children: <Widget>[
  458. Container(
  459. width: 70,
  460. height: 70,
  461. child: Image.asset(
  462. "assets/icons/menu/ic_surattugas_2.png",
  463. fit: BoxFit.fill,
  464. alignment: Alignment.center,
  465. ),
  466. ),
  467. Container(
  468. margin: EdgeInsets.only(top: 10),
  469. padding: EdgeInsets.all(5),
  470. child: Text(
  471. 'Assignment Letter',
  472. textAlign: TextAlign.center,
  473. style: GoogleFonts.acme(
  474. fontSize: 18, color: Colors.black),
  475. ),
  476. ),
  477. ],
  478. ),
  479. ),
  480. onTap: () {
  481. Navigator.push(
  482. context,
  483. MaterialPageRoute(
  484. builder: (context) => SuratTugas_Screen()));
  485. },
  486. ),
  487. InkWell(
  488. child: Container(
  489. decoration: BoxDecoration(
  490. color: Color(0xFFD0D0D0),
  491. borderRadius: BorderRadius.circular(5)),
  492. child: Column(
  493. crossAxisAlignment: CrossAxisAlignment.center,
  494. mainAxisAlignment: MainAxisAlignment.center,
  495. children: <Widget>[
  496. Container(
  497. width: 70,
  498. height: 70,
  499. child: Image.asset(
  500. "assets/icons/menu/ic_reimburse.png",
  501. fit: BoxFit.fill,
  502. alignment: Alignment.center),
  503. ),
  504. Container(
  505. margin: EdgeInsets.only(top: 10),
  506. padding: EdgeInsets.all(5),
  507. child: Text(
  508. 'Reimburse',
  509. textAlign: TextAlign.center,
  510. style: GoogleFonts.acme(
  511. fontSize: 18, color: Colors.black),
  512. ),
  513. ),
  514. ],
  515. ),
  516. ),
  517. onTap: () {
  518. Navigator.push(
  519. context,
  520. MaterialPageRoute(
  521. builder: (context) => ReimburseScreen()));
  522. },
  523. ),
  524. InkWell(
  525. child: Container(
  526. decoration: BoxDecoration(
  527. color: Color(0xFFD0D0D0),
  528. borderRadius: BorderRadius.circular(5)),
  529. child: Column(
  530. crossAxisAlignment: CrossAxisAlignment.center,
  531. mainAxisAlignment: MainAxisAlignment.center,
  532. children: <Widget>[
  533. Container(
  534. width: 70,
  535. height: 70,
  536. child: Image.asset(
  537. "assets/icons/menu/ic_about_2.png",
  538. fit: BoxFit.fill,
  539. alignment: Alignment.center),
  540. ),
  541. Container(
  542. margin: EdgeInsets.only(top: 10),
  543. padding: EdgeInsets.all(5),
  544. child: Text(
  545. 'About',
  546. textAlign: TextAlign.center,
  547. style: GoogleFonts.acme(
  548. fontSize: 18, color: Colors.black),
  549. ),
  550. ),
  551. ],
  552. ),
  553. ),
  554. onTap: () {
  555. Navigator.push(
  556. context,
  557. MaterialPageRoute(
  558. builder: (context) => AboutScreen()));
  559. },
  560. ),
  561. ],
  562. )
  563. ],
  564. ),
  565. ),
  566. ),
  567. ],
  568. ),
  569. ));
  570. }
  571. }