Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

home_screen.dart 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. import 'dart:async';
  2. import 'dart:convert';
  3. import 'dart:typed_data';
  4. import 'package:connectivity_plus/connectivity_plus.dart';
  5. import 'package:double_back_to_close/double_back_to_close.dart';
  6. import 'package:flutter/cupertino.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:fluttertoast/fluttertoast.dart';
  9. import 'package:focus_detector/focus_detector.dart';
  10. import 'package:google_fonts/google_fonts.dart';
  11. import 'package:employee_selfservice_mobile/Screens/Menu/About/about_screen.dart';
  12. import 'package:employee_selfservice_mobile/Screens/Menu/Absensi/absensi_screen.dart';
  13. import 'package:employee_selfservice_mobile/Screens/Menu/AjukanCuti/ajukancuti_screen.dart';
  14. import 'package:employee_selfservice_mobile/Screens/Menu/Reimburse/reimburse_screen.dart';
  15. import 'package:employee_selfservice_mobile/Screens/Settings/settings_screen.dart';
  16. import 'package:lottie/lottie.dart';
  17. import 'package:progress_dialog_null_safe/progress_dialog_null_safe.dart';
  18. import 'package:shared_preferences/shared_preferences.dart';
  19. import 'dart:developer' as logDev;
  20. import '../Settings/RequestHttp/getDetail_post.dart';
  21. import '../Settings/RequestHttp/getProfileImage_post.dart';
  22. import 'package:internet_connection_checker/internet_connection_checker.dart';
  23. late String nameShared;
  24. String name = "",
  25. statusDetail = "",
  26. dateOfBirth = "",
  27. phone = "",
  28. email = "",
  29. address = "",
  30. position = "";
  31. var _imageToShow;
  32. class HomeView extends StatefulWidget {
  33. @override
  34. _HomeView createState() => _HomeView();
  35. }
  36. class _HomeView extends State<HomeView> {
  37. late StreamSubscription subscription;
  38. bool isDeviceConnected = false;
  39. bool isAlertSet = false;
  40. //var _imageToShow;
  41. @override
  42. initState() {
  43. getConnectivity();
  44. /*getDetail();*/
  45. _imageToShow = AssetImage('assets/images/ic_pp_2.png');
  46. WidgetsBinding.instance.addPostFrameCallback((_) {
  47. //getProfileImage();
  48. _imageToShow = AssetImage('assets/icons/ic_pp_2.png');
  49. });
  50. super.initState();
  51. }
  52. getConnectivity() =>
  53. subscription = Connectivity().onConnectivityChanged.listen(
  54. (ConnectivityResult result) async {
  55. isDeviceConnected = await InternetConnectionChecker().hasConnection;
  56. if (!isDeviceConnected && isAlertSet == false) {
  57. showConnectivityDialogBox();
  58. setState(() => isAlertSet = true);
  59. }
  60. },
  61. );
  62. @override
  63. void dispose() {
  64. subscription.cancel();
  65. super.dispose();
  66. }
  67. //Get Profile image
  68. /*getProfileImage() async {
  69. final SharedPreferences prefs = await SharedPreferences.getInstance();
  70. final session = prefs.getString('session');
  71. ProgressDialog loading = ProgressDialog(context);
  72. loading = ProgressDialog(context,
  73. type: ProgressDialogType.normal,
  74. isDismissible: false,
  75. 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,
  90. fontSize: 15.0,
  91. fontWeight: FontWeight.w600));
  92. await loading.show();
  93. GetProfileImage_Post.connectToAPI(session!).then((valueResult) async {
  94. Map<String, dynamic> object = json.decode(valueResult);
  95. if (object.containsKey("result").toString() == "true") {
  96. String status = object['result']['status'].toString();
  97. logDev.log(status, name: "STATUS GET PROFILE");
  98. if (status == "success") {
  99. String photo = object['result']['photo'].toString();
  100. if (photo == "false") {
  101. setState(() {
  102. _imageToShow = AssetImage('assets/icons/ic_pp_2.png');
  103. });
  104. } else if (photo != "false") {
  105. Uint8List decodedBytes = Base64Decoder().convert(photo);
  106. setState(() {
  107. _imageToShow = Image.memory(decodedBytes, gaplessPlayback: true).image;
  108. });
  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. } else {
  121. Fluttertoast.showToast(
  122. msg: "Server Response Error",
  123. toastLength: Toast.LENGTH_SHORT,
  124. gravity: ToastGravity.CENTER,
  125. timeInSecForIosWeb: 1,
  126. textColor: Colors.white,
  127. fontSize: 16.0);
  128. }
  129. await loading.hide();
  130. });
  131. return _imageToShow;
  132. }*/
  133. //GetDetail
  134. getDetail() async {
  135. GetDetail_Post.connectToAPI().then((valueResult) async {
  136. Map<String, dynamic> object = json.decode(valueResult);
  137. if (object.containsKey("result").toString() == "true") {
  138. statusDetail = object['result']['status'].toString();
  139. String message = object['result']['message'].toString();
  140. if (statusDetail == "failed" || message == "User Not Found") {
  141. Fluttertoast.showToast(
  142. msg: message + ", Please login again!",
  143. toastLength: Toast.LENGTH_SHORT,
  144. gravity: ToastGravity.CENTER,
  145. timeInSecForIosWeb: 1,
  146. textColor: Colors.white,
  147. fontSize: 16.0);
  148. } else if (statusDetail != "failed") {
  149. name = object['result']['name'].toString();
  150. dateOfBirth = object['result']['date_of_birth'].toString();
  151. phone = object['result']['phone'].toString();
  152. email = object['result']['email'].toString();
  153. address = object['result']['address'].toString();
  154. position = object['result']['position'].toString();
  155. var prefs = await SharedPreferences.getInstance();
  156. if (position == "false") {
  157. position = "-";
  158. await prefs.setString('position', position);
  159. } else {
  160. await prefs.setString('position', position);
  161. }
  162. }
  163. } else {
  164. Fluttertoast.showToast(
  165. msg: "Server Response Error",
  166. toastLength: Toast.LENGTH_SHORT,
  167. gravity: ToastGravity.CENTER,
  168. timeInSecForIosWeb: 1,
  169. textColor: Colors.white,
  170. fontSize: 16.0);
  171. }
  172. });
  173. }
  174. int _selectedIndex = 0;
  175. void _onItemTapped(int index) {
  176. setState(() {
  177. _selectedIndex = index;
  178. if (index == 0) {
  179. }
  180. });
  181. }
  182. @override
  183. Widget build(BuildContext context) {
  184. return MaterialApp(
  185. home: DoubleBack(
  186. /*onFirstBackPress: (context) {
  187. final snackBar = SnackBar(content: Text("Double Back Press to Exit"));
  188. ScaffoldMessenger.of(context).showSnackBar(snackBar);
  189. },*/
  190. message: "Double Back Press to Exit",
  191. background: Colors.black38,
  192. backgroundRadius: 10,
  193. textStyle: TextStyle(
  194. fontSize: 16, fontWeight: FontWeight.bold, color: Colors.white),
  195. child: Scaffold(
  196. resizeToAvoidBottomInset: false,
  197. //backgroundColor: Colors.white,
  198. body: Stack(
  199. children: <Widget>[
  200. //Background(),
  201. //HomeScreen(),
  202. BottomNavBar()
  203. ],
  204. )),
  205. ),
  206. );
  207. }
  208. showConnectivityDialogBox() =>
  209. showCupertinoDialog<String>(
  210. context: context,
  211. builder: (BuildContext context) =>
  212. CupertinoAlertDialog(
  213. title: const Text('No Connection'),
  214. content: const Text('Please check your internet connectivity'),
  215. actions: <Widget>[
  216. Column(
  217. children: [
  218. SizedBox(
  219. width: 250,
  220. height: 250,
  221. child: LottieBuilder.asset(
  222. //'assets/animation/animation_no_internet.json',
  223. 'assets/animation/animation_no_internet_3.json',
  224. repeat: true),
  225. ),
  226. ],
  227. ),
  228. TextButton(
  229. onPressed: () async {
  230. Navigator.pop(context, 'Cancel');
  231. setState(() => isAlertSet = false);
  232. isDeviceConnected =
  233. await InternetConnectionChecker().hasConnection;
  234. if (!isDeviceConnected && isAlertSet == false) {
  235. showConnectivityDialogBox();
  236. setState(() => isAlertSet = true);
  237. }
  238. },
  239. child: const Text('Retry'),
  240. ),
  241. ],
  242. ),
  243. );
  244. }
  245. class BottomNavBar extends StatefulWidget {
  246. const BottomNavBar({Key? key}) : super(key: key);
  247. @override
  248. State<BottomNavBar> createState() => _BottomNavBarState();
  249. }
  250. class _BottomNavBarState extends State<BottomNavBar> {
  251. List<Widget> _widgetOptions = <Widget>[
  252. HomeScreen(),
  253. SettingsScreen(),
  254. ];
  255. int _selectedIndex = 0;
  256. void _onItemTapped(int index) {
  257. setState(() {
  258. _selectedIndex = index;
  259. });
  260. }
  261. @override
  262. Widget build(BuildContext context) {
  263. return Scaffold(
  264. body: _widgetOptions.elementAt(_selectedIndex),
  265. bottomNavigationBar: BottomNavigationBar(
  266. items: const <BottomNavigationBarItem>[
  267. BottomNavigationBarItem(
  268. icon: Icon(Icons.home),
  269. label: 'Home',
  270. ),
  271. BottomNavigationBarItem(
  272. icon: Icon(Icons.notifications),
  273. label: 'Notification',
  274. ), BottomNavigationBarItem(
  275. icon: Icon(Icons.person),
  276. label: 'Profile',
  277. ),
  278. ],
  279. currentIndex: _selectedIndex,
  280. selectedItemColor: Colors.white,
  281. backgroundColor: Color(0xFF5666b7),
  282. onTap: _onItemTapped),
  283. );
  284. }
  285. }
  286. class HomeScreen extends StatefulWidget {
  287. @override
  288. State<HomeScreen> createState() => _HomeScreenState();
  289. }
  290. class _HomeScreenState extends State<HomeScreen> {
  291. //Get Profile image
  292. /*getProfileImage() async {
  293. final SharedPreferences prefs = await SharedPreferences.getInstance();
  294. final session = prefs.getString('session');
  295. GetProfileImage_Post.connectToAPI(session!).then((valueResult) async {
  296. Map<String, dynamic> object = json.decode(valueResult);
  297. if (object.containsKey("result").toString() == "true") {
  298. String status = object['result']['status'].toString();
  299. logDev.log(status, name: "STATUS GET PROFILE");
  300. if (status == "success") {
  301. String photo = object['result']['photo'].toString();
  302. if (photo == "false") {
  303. setState(() {
  304. _imageToShow = AssetImage('assets/icons/ic_pp_2.png');
  305. });
  306. } else if (photo != "false") {
  307. Uint8List decodedBytes = Base64Decoder().convert(photo);
  308. //logDev.log(decodedBytes.toString(), name: "DECODED BYTES photo");
  309. setState(() {
  310. _imageToShow = Image.memory(decodedBytes, gaplessPlayback: true).image;
  311. });
  312. }
  313. } else if (status == "failed") {
  314. String message = object['result']['message'].toString();
  315. Fluttertoast.showToast(
  316. msg: message,
  317. toastLength: Toast.LENGTH_LONG,
  318. gravity: ToastGravity.CENTER,
  319. timeInSecForIosWeb: 1,
  320. textColor: Colors.white,
  321. fontSize: 16.0);
  322. }
  323. } else {
  324. Fluttertoast.showToast(
  325. msg: "Server Response Error",
  326. toastLength: Toast.LENGTH_SHORT,
  327. gravity: ToastGravity.CENTER,
  328. timeInSecForIosWeb: 1,
  329. textColor: Colors.white,
  330. fontSize: 16.0);
  331. }
  332. });
  333. return _imageToShow;
  334. }*/
  335. @override
  336. Widget build(BuildContext context) {
  337. var size = MediaQuery
  338. .of(context)
  339. .size;
  340. return FocusDetector(
  341. /*onVisibilityGained: (){
  342. getProfileImage();
  343. },
  344. onVisibilityLost: (){
  345. getProfileImage();
  346. },
  347. onFocusLost: (){
  348. getProfileImage();
  349. },*/
  350. onFocusGained: () {
  351. _imageToShow = AssetImage('assets/icons/ic_pp_2.png');
  352. },
  353. /* onForegroundLost: (){
  354. getProfileImage();
  355. },
  356. onForegroundGained: (){
  357. getProfileImage();
  358. },*/
  359. child: Scaffold(
  360. body: SingleChildScrollView(
  361. child: Stack(
  362. children: <Widget>[
  363. Container(
  364. height: size.height * 0.3,
  365. decoration: BoxDecoration(
  366. gradient: LinearGradient(
  367. begin: Alignment.topRight,
  368. end: Alignment.bottomRight,
  369. colors: [
  370. Color(0xFF4858A7),
  371. Color(0xFF6474C6),
  372. //Color(0xFF8C99DD),
  373. ])),
  374. ),
  375. SafeArea(
  376. child: Padding(
  377. padding: EdgeInsets.all(20),
  378. child: Column(
  379. children: <Widget>[
  380. Container(
  381. child: Stack(
  382. alignment: Alignment.topLeft,
  383. children: [
  384. Container(
  385. margin: EdgeInsets.only(
  386. top: (((size.width - 20) * 0.33) * 0.5) + 40),
  387. child: Card(
  388. elevation: 15,
  389. child: Container(
  390. height: size.width * 0.35,
  391. width: size.width - 20,
  392. padding: EdgeInsets.all(15),
  393. decoration: BoxDecoration(
  394. color: Colors.white,
  395. borderRadius:
  396. BorderRadius.all(
  397. Radius.circular(10))),
  398. child: Column(mainAxisAlignment: MainAxisAlignment.end,
  399. crossAxisAlignment: CrossAxisAlignment.center,
  400. children: <Widget>[
  401. Text("Ginro",
  402. maxLines: 2,
  403. overflow: TextOverflow.ellipsis,
  404. textAlign: TextAlign.center,
  405. style: GoogleFonts.inter(
  406. fontSize: size.width * 0.045,
  407. color: Colors.black,
  408. fontWeight: FontWeight.bold),
  409. ),
  410. Text("General Manager",
  411. textAlign: TextAlign.center,
  412. style: GoogleFonts.inter(
  413. fontSize: size.width * 0.035,
  414. color: Colors.black),
  415. ),
  416. ],
  417. )),
  418. ),
  419. ),
  420. Align(
  421. alignment: Alignment.topCenter,
  422. child: Container(
  423. margin: EdgeInsets.only(left: 15, top: 40),
  424. alignment: Alignment.topLeft,
  425. height: (size.width - 20) * 0.33,
  426. width: (size.width - 20) * 0.33,
  427. decoration: BoxDecoration(
  428. color: Colors.black,
  429. image: DecorationImage(
  430. image: _imageToShow,
  431. fit: BoxFit.cover,
  432. ),
  433. shape: BoxShape.circle,
  434. ),
  435. ),
  436. ),
  437. ],
  438. ),
  439. ),
  440. GridView.count(
  441. shrinkWrap: true,
  442. physics: NeverScrollableScrollPhysics(),
  443. padding: EdgeInsets.only(top: 25, left: 5, right: 5),
  444. crossAxisSpacing: 15,
  445. mainAxisSpacing: 15,
  446. crossAxisCount: 2,
  447. childAspectRatio: 1.0,
  448. children: <Widget>[
  449. InkWell(
  450. child: Container(
  451. width: size.width,
  452. height: size.height,
  453. decoration: BoxDecoration(
  454. color: Color(0xFFD0D0D0),
  455. borderRadius: BorderRadius.circular(5)),
  456. child: Center(
  457. child: Column(
  458. crossAxisAlignment: CrossAxisAlignment.center,
  459. mainAxisAlignment: MainAxisAlignment.center,
  460. children: <Widget>[
  461. Container(
  462. width: size.width * 0.18,
  463. child: Image.asset(
  464. "assets/icons/menu/ic_absensi_3.png",
  465. fit: BoxFit.contain)
  466. ),
  467. Container(
  468. margin: EdgeInsets.only(top: 5),
  469. child: Text(
  470. 'Canvasing',
  471. textAlign: TextAlign.center,
  472. style: GoogleFonts.acme(
  473. fontSize: size.width * 0.045,
  474. color: Colors.black),
  475. ),
  476. )
  477. ],
  478. ),
  479. )
  480. ),
  481. onTap: () {
  482. Navigator.push(
  483. context,
  484. MaterialPageRoute(
  485. builder: (context) =>
  486. AbsensiScreen()));
  487. }),
  488. InkWell(
  489. child: Container(
  490. width: size.width,
  491. height: size.height,
  492. decoration: BoxDecoration(
  493. color: Color(0xFFD0D0D0),
  494. borderRadius: BorderRadius.circular(5)),
  495. child: Column(
  496. crossAxisAlignment: CrossAxisAlignment.center,
  497. mainAxisAlignment: MainAxisAlignment.center,
  498. children: <Widget>[
  499. Container(
  500. width: size.width * 0.18,
  501. child: Image.asset(
  502. "assets/icons/menu/ic_cuti_4.png",
  503. fit: BoxFit.contain),
  504. ),
  505. Container(
  506. margin: EdgeInsets.only(top: 5),
  507. child: Text(
  508. 'Leaves',
  509. textAlign: TextAlign.center,
  510. style: GoogleFonts.acme(
  511. fontSize: size.width * 0.045,
  512. color: Colors.black),
  513. ),
  514. )
  515. ],
  516. ),
  517. ),
  518. onTap: () {
  519. Navigator.push(
  520. context,
  521. MaterialPageRoute(
  522. builder: (context) =>
  523. AjukanCutiScreen()));
  524. },
  525. ),
  526. InkWell(
  527. child: Container(
  528. width: size.width,
  529. height: size.height,
  530. decoration: BoxDecoration(
  531. color: Color(0xFFD0D0D0),
  532. borderRadius: BorderRadius.circular(5)),
  533. child: Column(
  534. crossAxisAlignment: CrossAxisAlignment.center,
  535. mainAxisAlignment: MainAxisAlignment.center,
  536. children: <Widget>[
  537. Container(
  538. width: size.width * 0.18,
  539. child: Image.asset(
  540. "assets/icons/menu/ic_reimburse_4.png",
  541. fit: BoxFit.contain,
  542. ),
  543. ),
  544. Container(
  545. margin: EdgeInsets.only(top: 5),
  546. child: Text(
  547. 'Reimburse',
  548. textAlign: TextAlign.center,
  549. style: GoogleFonts.acme(
  550. fontSize: size.width * 0.045,
  551. color: Colors.black),
  552. ),
  553. )
  554. ],
  555. ),
  556. ),
  557. onTap: () {
  558. Navigator.push(
  559. context,
  560. MaterialPageRoute(
  561. builder: (context) =>
  562. ReimburseScreen()));
  563. },
  564. ),
  565. InkWell(
  566. child: Container(
  567. width: size.width,
  568. height: size.height,
  569. decoration: BoxDecoration(
  570. color: Color(0xFFD0D0D0),
  571. borderRadius: BorderRadius.circular(5)),
  572. child: Column(
  573. crossAxisAlignment: CrossAxisAlignment.center,
  574. mainAxisAlignment: MainAxisAlignment.center,
  575. children: <Widget>[
  576. Container(
  577. width: size.width * 0.18,
  578. child: Image.asset(
  579. "assets/icons/menu/ic_about_9.png",
  580. fit: BoxFit.contain,
  581. ),
  582. ),
  583. Container(
  584. margin: EdgeInsets.only(top: 5),
  585. child: Text(
  586. 'About',
  587. textAlign: TextAlign.center,
  588. style: GoogleFonts.acme(
  589. fontSize: size.width * 0.045,
  590. color: Colors.black),
  591. ),
  592. )
  593. ],
  594. ),
  595. ),
  596. onTap: () {
  597. Navigator.push(
  598. context,
  599. MaterialPageRoute(
  600. builder: (context) => AboutScreen()));
  601. },
  602. ),
  603. ],
  604. )
  605. ],
  606. ),
  607. ),
  608. ),
  609. /*Center(
  610. child: _widgetOptions.elementAt(_selectedIndex),
  611. )*/
  612. ],
  613. ),
  614. )
  615. ),
  616. );
  617. }
  618. }