Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

home_screen.dart 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. import 'dart:async';
  2. import 'package:connectivity_plus/connectivity_plus.dart';
  3. import 'package:double_back_to_close/double_back_to_close.dart';
  4. import 'package:employee_selfservice_mobile/Screens/Menu/Canvasing/canvasing_screen.dart';
  5. import 'package:employee_selfservice_mobile/Screens/Menu/Dashboard/dashboard_screen.dart';
  6. import 'package:employee_selfservice_mobile/Screens/Menu/History/history_screen.dart';
  7. import 'package:flutter/cupertino.dart';
  8. import 'package:flutter/material.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/Settings/settings_screen.dart';
  13. import 'package:lottie/lottie.dart';
  14. import 'dart:developer' as logDev;
  15. import 'package:internet_connection_checker/internet_connection_checker.dart';
  16. var _imageToShow;
  17. class HomeView extends StatefulWidget {
  18. @override
  19. _HomeView createState() => _HomeView();
  20. }
  21. class _HomeView extends State<HomeView> {
  22. late StreamSubscription subscription;
  23. bool isDeviceConnected = false;
  24. bool isAlertSet = false;
  25. @override
  26. initState() {
  27. getConnectivity();
  28. /*getDetail();*/
  29. _imageToShow = AssetImage('assets/images/ic_pp_2.png');
  30. WidgetsBinding.instance.addPostFrameCallback((_) {
  31. _imageToShow = AssetImage('assets/icons/ic_pp_2.png');
  32. });
  33. super.initState();
  34. }
  35. getConnectivity() =>
  36. subscription = Connectivity().onConnectivityChanged.listen(
  37. (ConnectivityResult result) async {
  38. isDeviceConnected = await InternetConnectionChecker().hasConnection;
  39. if (!isDeviceConnected && isAlertSet == false) {
  40. showConnectivityDialogBox();
  41. setState(() => isAlertSet = true);
  42. }
  43. },
  44. );
  45. @override
  46. void dispose() {
  47. subscription.cancel();
  48. super.dispose();
  49. }
  50. @override
  51. Widget build(BuildContext context) {
  52. return MaterialApp(
  53. home: DoubleBack(
  54. /*onFirstBackPress: (context) {
  55. final snackBar = SnackBar(content: Text("Double Back Press to Exit"));
  56. ScaffoldMessenger.of(context).showSnackBar(snackBar);
  57. },*/
  58. message: "Double Back Press to Exit",
  59. background: Colors.black38,
  60. backgroundRadius: 10,
  61. textStyle: TextStyle(
  62. fontSize: 16, fontWeight: FontWeight.bold, color: Colors.white),
  63. child: Scaffold(
  64. resizeToAvoidBottomInset: false,
  65. //backgroundColor: Colors.white,
  66. body: Stack(
  67. children: <Widget>[
  68. //Background(),
  69. //HomeScreen(),
  70. BottomNavBar()
  71. ],
  72. )),
  73. ),
  74. );
  75. }
  76. showConnectivityDialogBox() =>
  77. showCupertinoDialog<String>(
  78. context: context,
  79. builder: (BuildContext context) =>
  80. CupertinoAlertDialog(
  81. title: const Text('No Connection'),
  82. content: const Text('Please check your internet connectivity'),
  83. actions: <Widget>[
  84. Column(
  85. children: [
  86. SizedBox(
  87. width: 250,
  88. height: 250,
  89. child: LottieBuilder.asset(
  90. //'assets/animation/animation_no_internet.json',
  91. 'assets/animation/animation_no_internet_3.json',
  92. repeat: true),
  93. ),
  94. ],
  95. ),
  96. TextButton(
  97. onPressed: () async {
  98. Navigator.pop(context, 'Cancel');
  99. setState(() => isAlertSet = false);
  100. isDeviceConnected =
  101. await InternetConnectionChecker().hasConnection;
  102. if (!isDeviceConnected && isAlertSet == false) {
  103. showConnectivityDialogBox();
  104. setState(() => isAlertSet = true);
  105. }
  106. },
  107. child: const Text('Retry'),
  108. ),
  109. ],
  110. ),
  111. );
  112. }
  113. class BottomNavBar extends StatefulWidget {
  114. const BottomNavBar({Key? key}) : super(key: key);
  115. @override
  116. State<BottomNavBar> createState() => _BottomNavBarState();
  117. }
  118. class _BottomNavBarState extends State<BottomNavBar> {
  119. List<Widget> _widgetOptions = <Widget>[
  120. HomeScreen(),
  121. HomeScreen(),
  122. HomeScreen(),
  123. ];
  124. int _selectedIndex = 0;
  125. void _onItemTapped(int index) {
  126. setState(() {
  127. _selectedIndex = index;
  128. });
  129. }
  130. @override
  131. Widget build(BuildContext context) {
  132. return Scaffold(
  133. body: _widgetOptions.elementAt(_selectedIndex),
  134. bottomNavigationBar: BottomNavigationBar(
  135. items: const <BottomNavigationBarItem>[
  136. BottomNavigationBarItem(
  137. icon: Icon(Icons.home),
  138. label: 'Home',
  139. ),
  140. BottomNavigationBarItem(
  141. icon: Icon(Icons.notifications),
  142. label: 'Notification',
  143. ), BottomNavigationBarItem(
  144. icon: Icon(Icons.person),
  145. label: 'Profile',
  146. ),
  147. ],
  148. currentIndex: _selectedIndex,
  149. selectedItemColor: Colors.white,
  150. backgroundColor: Color(0xFF5666b7),
  151. onTap: _onItemTapped),
  152. );
  153. }
  154. }
  155. class HomeScreen extends StatefulWidget {
  156. @override
  157. State<HomeScreen> createState() => _HomeScreenState();
  158. }
  159. class _HomeScreenState extends State<HomeScreen> {
  160. @override
  161. Widget build(BuildContext context) {
  162. var size = MediaQuery
  163. .of(context)
  164. .size;
  165. return FocusDetector(
  166. /*onVisibilityGained: (){
  167. getProfileImage();
  168. },
  169. onVisibilityLost: (){
  170. getProfileImage();
  171. },
  172. onFocusLost: (){
  173. getProfileImage();
  174. },*/
  175. onFocusGained: () {
  176. _imageToShow = AssetImage('assets/icons/ic_pp_2.png');
  177. },
  178. /* onForegroundLost: (){
  179. getProfileImage();
  180. },
  181. onForegroundGained: (){
  182. getProfileImage();
  183. },*/
  184. child: Scaffold(
  185. body: SingleChildScrollView(
  186. child: Stack(
  187. children: <Widget>[
  188. Container(
  189. height: size.height * 0.3,
  190. decoration: BoxDecoration(
  191. gradient: LinearGradient(
  192. begin: Alignment.topRight,
  193. end: Alignment.bottomRight,
  194. colors: [
  195. Color(0xFF4858A7),
  196. Color(0xFF6474C6),
  197. //Color(0xFF8C99DD),
  198. ])),
  199. ),
  200. SafeArea(
  201. child: Padding(
  202. padding: EdgeInsets.all(20),
  203. child: Column(
  204. children: <Widget>[
  205. Container(
  206. child: Stack(
  207. alignment: Alignment.topLeft,
  208. children: [
  209. Container(
  210. margin: EdgeInsets.only(
  211. top: (((size.width - 20) * 0.33) * 0.5) + 40),
  212. child: Card(
  213. elevation: 15,
  214. child: Container(
  215. height: size.width * 0.35,
  216. width: size.width - 20,
  217. padding: EdgeInsets.all(15),
  218. decoration: BoxDecoration(
  219. color: Colors.white,
  220. borderRadius:
  221. BorderRadius.all(
  222. Radius.circular(10))),
  223. child: Column(mainAxisAlignment: MainAxisAlignment.end,
  224. crossAxisAlignment: CrossAxisAlignment.center,
  225. children: <Widget>[
  226. Text("Ginro",
  227. maxLines: 2,
  228. overflow: TextOverflow.ellipsis,
  229. textAlign: TextAlign.center,
  230. style: GoogleFonts.inter(
  231. fontSize: size.width * 0.045,
  232. color: Colors.black,
  233. fontWeight: FontWeight.bold),
  234. ),
  235. Text("General Manager",
  236. textAlign: TextAlign.center,
  237. style: GoogleFonts.inter(
  238. fontSize: size.width * 0.035,
  239. color: Colors.black),
  240. ),
  241. ],
  242. )),
  243. ),
  244. ),
  245. Align(
  246. alignment: Alignment.topCenter,
  247. child: Container(
  248. margin: EdgeInsets.only(left: 15, top: 40),
  249. alignment: Alignment.topLeft,
  250. height: (size.width - 20) * 0.33,
  251. width: (size.width - 20) * 0.33,
  252. decoration: BoxDecoration(
  253. color: Colors.black,
  254. image: DecorationImage(
  255. image: AssetImage('assets/icons/ic_pp_2.png'),
  256. fit: BoxFit.cover,
  257. ),
  258. shape: BoxShape.circle,
  259. ),
  260. ),
  261. ),
  262. ],
  263. ),
  264. ),
  265. GridView.count(
  266. shrinkWrap: true,
  267. physics: NeverScrollableScrollPhysics(),
  268. padding: EdgeInsets.only(top: 25, left: 5, right: 5),
  269. crossAxisSpacing: 15,
  270. mainAxisSpacing: 15,
  271. crossAxisCount: 2,
  272. childAspectRatio: 1.0,
  273. children: <Widget>[
  274. InkWell(
  275. child: Container(
  276. width: size.width,
  277. height: size.height,
  278. decoration: BoxDecoration(
  279. color: Color(0xFFD0D0D0),
  280. borderRadius: BorderRadius.circular(5)),
  281. child: Center(
  282. child: Column(
  283. crossAxisAlignment: CrossAxisAlignment.center,
  284. mainAxisAlignment: MainAxisAlignment.center,
  285. children: <Widget>[
  286. Container(
  287. width: size.width * 0.18,
  288. child: Image.asset(
  289. "assets/icons/menu/ic_canvasing_3.png",
  290. fit: BoxFit.contain)
  291. ),
  292. Container(
  293. margin: EdgeInsets.only(top: 5),
  294. child: Text(
  295. 'Canvasing',
  296. textAlign: TextAlign.center,
  297. style: GoogleFonts.acme(
  298. fontSize: size.width * 0.045,
  299. color: Colors.black),
  300. ),
  301. )
  302. ],
  303. ),
  304. )
  305. ),
  306. onTap: () {
  307. Navigator.push(
  308. context,
  309. MaterialPageRoute(
  310. builder: (context) =>
  311. CanvasingScreen()));
  312. }),
  313. InkWell(
  314. child: Container(
  315. width: size.width,
  316. height: size.height,
  317. decoration: BoxDecoration(
  318. color: Color(0xFFD0D0D0),
  319. borderRadius: BorderRadius.circular(5)),
  320. child: Center(
  321. child: Column(
  322. crossAxisAlignment: CrossAxisAlignment.center,
  323. mainAxisAlignment: MainAxisAlignment.center,
  324. children: <Widget>[
  325. Container(
  326. width: size.width * 0.18,
  327. child: Image.asset(
  328. "assets/icons/menu/ic_dashboardcanvasing_1.png",
  329. fit: BoxFit.contain)
  330. ),
  331. Container(
  332. margin: EdgeInsets.only(top: 5),
  333. child: Text(
  334. 'Dashboard Canvasing',
  335. textAlign: TextAlign.center,
  336. style: GoogleFonts.acme(
  337. fontSize: size.width * 0.045,
  338. color: Colors.black),
  339. ),
  340. )
  341. ],
  342. ),
  343. )
  344. ),
  345. onTap: () {
  346. Navigator.push(
  347. context,
  348. MaterialPageRoute(
  349. builder: (context) =>
  350. DashboardScreen()));
  351. }),
  352. InkWell(
  353. child: Container(
  354. width: size.width,
  355. height: size.height,
  356. decoration: BoxDecoration(
  357. color: Color(0xFFD0D0D0),
  358. borderRadius: BorderRadius.circular(5)),
  359. child: Center(
  360. child: Column(
  361. crossAxisAlignment: CrossAxisAlignment.center,
  362. mainAxisAlignment: MainAxisAlignment.center,
  363. children: <Widget>[
  364. Container(
  365. width: size.width * 0.18,
  366. child: Image.asset(
  367. "assets/icons/menu/ic_history.png",
  368. fit: BoxFit.contain)
  369. ),
  370. Container(
  371. margin: EdgeInsets.only(top: 5),
  372. child: Text(
  373. 'History Canvasing',
  374. textAlign: TextAlign.center,
  375. style: GoogleFonts.acme(
  376. fontSize: size.width * 0.045,
  377. color: Colors.black),
  378. ),
  379. )
  380. ],
  381. ),
  382. )
  383. ),
  384. onTap: () {
  385. Navigator.push(
  386. context,
  387. MaterialPageRoute(
  388. builder: (context) =>
  389. HistoryScreen()));
  390. }),
  391. InkWell(
  392. child: Container(
  393. width: size.width,
  394. height: size.height,
  395. decoration: BoxDecoration(
  396. color: Color(0xFFD0D0D0),
  397. borderRadius: BorderRadius.circular(5)),
  398. child: Column(
  399. crossAxisAlignment: CrossAxisAlignment.center,
  400. mainAxisAlignment: MainAxisAlignment.center,
  401. children: <Widget>[
  402. Container(
  403. width: size.width * 0.18,
  404. child: Image.asset(
  405. "assets/icons/menu/ic_about_9.png",
  406. fit: BoxFit.contain,
  407. ),
  408. ),
  409. Container(
  410. margin: EdgeInsets.only(top: 5),
  411. child: Text(
  412. 'About',
  413. textAlign: TextAlign.center,
  414. style: GoogleFonts.acme(
  415. fontSize: size.width * 0.045,
  416. color: Colors.black),
  417. ),
  418. )
  419. ],
  420. ),
  421. ),
  422. onTap: () {
  423. Navigator.push(
  424. context,
  425. MaterialPageRoute(
  426. builder: (context) => AboutScreen()));
  427. },
  428. ),
  429. ],
  430. )
  431. ],
  432. ),
  433. ),
  434. ),
  435. /*Center(
  436. child: _widgetOptions.elementAt(_selectedIndex),
  437. )*/
  438. ],
  439. ),
  440. )
  441. ),
  442. );
  443. }
  444. }