暫無描述
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 19KB

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