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 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  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. child: Text(
  324. 'Absensi',
  325. textAlign: TextAlign.center,
  326. style: GoogleFonts.acme(
  327. fontSize: 18, color: Colors.black),
  328. ),
  329. ),
  330. ],
  331. ),
  332. ),
  333. onTap: () {
  334. Navigator.push(
  335. context,
  336. MaterialPageRoute(
  337. builder: (context) => AbsensiScreen()));
  338. }),
  339. InkWell(
  340. child: Container(
  341. decoration: BoxDecoration(
  342. color: Color(0xFFD0D0D0),
  343. borderRadius: BorderRadius.circular(5)),
  344. child: Column(
  345. crossAxisAlignment: CrossAxisAlignment.center,
  346. mainAxisAlignment: MainAxisAlignment.center,
  347. children: <Widget>[
  348. Container(
  349. width: 75,
  350. height: 75,
  351. child: Image.asset(
  352. "assets/icons/menu/ic_slipgaji_2.png",
  353. fit: BoxFit.fill,
  354. alignment: Alignment.center),
  355. ),
  356. Container(
  357. margin: EdgeInsets.only(top: 10),
  358. child: Text(
  359. 'Slip Gaji',
  360. textAlign: TextAlign.center,
  361. style: GoogleFonts.acme(
  362. fontSize: 18, color: Colors.black),
  363. ),
  364. ),
  365. ],
  366. ),
  367. ),
  368. onTap: () {
  369. Navigator.push(
  370. context,
  371. MaterialPageRoute(
  372. builder: (context) => SlipGajiScreen()));
  373. },
  374. ),
  375. InkWell(
  376. child: Container(
  377. decoration: BoxDecoration(
  378. color: Color(0xFFD0D0D0),
  379. borderRadius: BorderRadius.circular(5)),
  380. child: Column(
  381. crossAxisAlignment: CrossAxisAlignment.center,
  382. mainAxisAlignment: MainAxisAlignment.center,
  383. children: <Widget>[
  384. Container(
  385. width: 70,
  386. height: 70,
  387. child: Image.asset(
  388. "assets/icons/menu/ic_cuti_2.png",
  389. fit: BoxFit.fill,
  390. alignment: Alignment.center),
  391. ),
  392. Container(
  393. margin: EdgeInsets.only(top: 10),
  394. child: Text(
  395. 'Ajukan Cuti',
  396. textAlign: TextAlign.center,
  397. style: GoogleFonts.acme(
  398. fontSize: 18, color: Colors.black),
  399. ),
  400. ),
  401. ],
  402. ),
  403. ),
  404. onTap: () {
  405. Navigator.push(
  406. context,
  407. MaterialPageRoute(
  408. builder: (context) => AjukanCutiScreen()));
  409. },
  410. ),
  411. /*InkWell(
  412. child: Container(
  413. decoration: BoxDecoration(
  414. color: Color(0xFFD0D0D0),
  415. borderRadius: BorderRadius.circular(5)),
  416. child: Column(
  417. crossAxisAlignment: CrossAxisAlignment.center,
  418. mainAxisAlignment: MainAxisAlignment.center,
  419. children: <Widget>[
  420. Container(
  421. width: 75,
  422. height: 75,
  423. child: Image.asset(
  424. "assets/icons/menu/ic_menu_berita2.png"),
  425. ),
  426. Container(
  427. margin: EdgeInsets.only(top: 10),
  428. child: Text(
  429. 'Berita',
  430. textAlign: TextAlign.center,
  431. style: GoogleFonts.acme(
  432. fontSize: 18, color: Colors.black),
  433. ),
  434. ),
  435. ],
  436. ),
  437. ),
  438. onTap: () {
  439. Navigator.push(
  440. context,
  441. MaterialPageRoute(
  442. builder: (context) => BeritaScreen()));
  443. },
  444. ),*/
  445. InkWell(
  446. child: Container(
  447. decoration: BoxDecoration(
  448. color: Color(0xFFD0D0D0),
  449. borderRadius: BorderRadius.circular(5)),
  450. child: Column(
  451. crossAxisAlignment: CrossAxisAlignment.center,
  452. mainAxisAlignment: MainAxisAlignment.center,
  453. children: <Widget>[
  454. Container(
  455. width: 70,
  456. height: 70,
  457. child: Image.asset(
  458. "assets/icons/menu/ic_surattugas_2.png",
  459. fit: BoxFit.fill,
  460. alignment: Alignment.center,
  461. ),
  462. ),
  463. Container(
  464. margin: EdgeInsets.only(top: 10),
  465. child: Text(
  466. 'Surat Tugas',
  467. textAlign: TextAlign.center,
  468. style: GoogleFonts.acme(
  469. fontSize: 18, color: Colors.black),
  470. ),
  471. ),
  472. ],
  473. ),
  474. ),
  475. onTap: () {
  476. Navigator.push(
  477. context,
  478. MaterialPageRoute(
  479. builder: (context) => SuratTugas_Screen()));
  480. },
  481. ),
  482. InkWell(
  483. child: Container(
  484. decoration: BoxDecoration(
  485. color: Color(0xFFD0D0D0),
  486. borderRadius: BorderRadius.circular(5)),
  487. child: Column(
  488. crossAxisAlignment: CrossAxisAlignment.center,
  489. mainAxisAlignment: MainAxisAlignment.center,
  490. children: <Widget>[
  491. Container(
  492. width: 70,
  493. height: 70,
  494. child: Image.asset(
  495. "assets/icons/menu/ic_reimburse.png",
  496. fit: BoxFit.fill,
  497. alignment: Alignment.center),
  498. ),
  499. Container(
  500. margin: EdgeInsets.only(top: 10),
  501. child: Text(
  502. 'Reimburse',
  503. textAlign: TextAlign.center,
  504. style: GoogleFonts.acme(
  505. fontSize: 18, color: Colors.black),
  506. ),
  507. ),
  508. ],
  509. ),
  510. ),
  511. onTap: () {
  512. Navigator.push(
  513. context,
  514. MaterialPageRoute(
  515. builder: (context) => ReimburseScreen()));
  516. },
  517. ),
  518. InkWell(
  519. child: Container(
  520. decoration: BoxDecoration(
  521. color: Color(0xFFD0D0D0),
  522. borderRadius: BorderRadius.circular(5)),
  523. child: Column(
  524. crossAxisAlignment: CrossAxisAlignment.center,
  525. mainAxisAlignment: MainAxisAlignment.center,
  526. children: <Widget>[
  527. Container(
  528. width: 70,
  529. height: 70,
  530. child: Image.asset(
  531. "assets/icons/menu/ic_about_2.png",
  532. fit: BoxFit.fill,
  533. alignment: Alignment.center),
  534. ),
  535. Container(
  536. margin: EdgeInsets.only(top: 10),
  537. child: Text(
  538. 'About',
  539. textAlign: TextAlign.center,
  540. style: GoogleFonts.acme(
  541. fontSize: 18, color: Colors.black),
  542. ),
  543. ),
  544. ],
  545. ),
  546. ),
  547. onTap: () {
  548. Navigator.push(
  549. context,
  550. MaterialPageRoute(
  551. builder: (context) => AboutScreen()));
  552. },
  553. ),
  554. ],
  555. )
  556. ],
  557. ),
  558. ),
  559. ),
  560. ],
  561. ),
  562. ));
  563. }
  564. }