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

splash_screen.dart 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. import 'dart:async';
  2. import 'dart:convert';
  3. import 'dart:io';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter/services.dart';
  6. import 'package:fluttertoast/fluttertoast.dart';
  7. import 'package:google_fonts/google_fonts.dart';
  8. import 'package:employee_selfservice_mobile/Screens/Login/login_screen.dart';
  9. import 'package:employee_selfservice_mobile/Screens/Splash/loginstatus_post.dart';
  10. import 'package:employee_selfservice_mobile/constants.dart';
  11. import 'package:lottie/lottie.dart';
  12. import 'package:shared_preferences/shared_preferences.dart';
  13. import '../Home/home_screen.dart';
  14. import '../Splash/background.dart';
  15. import 'package:url_launcher/url_launcher.dart';
  16. import 'dart:developer' as logDev;
  17. class Splash extends StatefulWidget {
  18. const Splash({Key? key}) : super(key: key);
  19. @override
  20. _SplashState createState() => _SplashState();
  21. }
  22. class _SplashState extends State<Splash> {
  23. @override
  24. void initState() {
  25. super.initState();
  26. Timer(Duration(seconds: 10), () => loginStatus(context));
  27. }
  28. @override
  29. Widget build(BuildContext context) {
  30. return Scaffold(
  31. resizeToAvoidBottomInset: false,
  32. body: Stack(
  33. children: <Widget>[
  34. Background(),
  35. SplashScreen(),
  36. ],
  37. ));
  38. }
  39. }
  40. class SplashScreen extends StatelessWidget {
  41. const SplashScreen({Key? key}) : super(key: key);
  42. @override
  43. Widget build(BuildContext context) {
  44. return Scaffold(
  45. body: Container(
  46. width: double.infinity,
  47. height: double.infinity,
  48. decoration: BoxDecoration(
  49. gradient: LinearGradient(
  50. begin: Alignment.topRight,
  51. end: Alignment.bottomRight,
  52. colors: [
  53. Color(0xFF4858A7),
  54. Color(0xFF4858A7),
  55. Color(0xFF6474C6),
  56. //Color(0xFF8C99DD),
  57. //Color(0xFFFFFFFF)
  58. ])),
  59. child: Center(
  60. child: Column(
  61. mainAxisAlignment: MainAxisAlignment.center,
  62. crossAxisAlignment: CrossAxisAlignment.center,
  63. children: [
  64. Container(
  65. /*decoration: BoxDecoration(
  66. shape: BoxShape.circle,
  67. color: Colors.white
  68. ),*/
  69. child: SizedBox(
  70. width: 250,
  71. height: 250,
  72. child: LottieBuilder.asset('assets/animation/animation_4.json',
  73. repeat: true),
  74. ),
  75. ),
  76. Text(appName,
  77. style: GoogleFonts.carterOne(fontSize: 25, color: Colors.white))
  78. ],
  79. ),
  80. ),
  81. ));
  82. }
  83. }
  84. Future<void> loginStatus(BuildContext context) async {
  85. final SharedPreferences prefs = await SharedPreferences.getInstance();
  86. String? version = prefs.getString('version');
  87. String? device = prefs.getString('device');
  88. String? session = prefs.getString('session');
  89. String? notif_token = prefs.getString('notif_token');
  90. if (session == null) {
  91. version = "1.0.0";
  92. session = "";
  93. notif_token = "";
  94. if (Platform.isAndroid){
  95. device = "android";
  96. } else if (Platform.isIOS){
  97. device = "ios";
  98. }
  99. }
  100. //logDev.log(session, name: "SESSIONNYA");
  101. LoginStatus_Post.connectToAPI(version!, device!, session, notif_token!).then((valueResult) async {
  102. Map<String, dynamic> object = json.decode(valueResult);
  103. if (object.containsKey("result").toString() == "true") {
  104. String status = object['result']['status'].toString();
  105. if (status == "success") {
  106. Fluttertoast.showToast(
  107. msg: "You are already logged in",
  108. toastLength: Toast.LENGTH_SHORT,
  109. gravity: ToastGravity.CENTER,
  110. timeInSecForIosWeb: 1,
  111. textColor: Colors.white,
  112. fontSize: 16.0);
  113. Navigator.pushReplacement(
  114. context, MaterialPageRoute(builder: (context) => HomeView()));
  115. } else if (status == "failed") {
  116. String message = object['result']['message'].toString();
  117. if (message == "Not Logged In") {
  118. Fluttertoast.showToast(
  119. msg: message,
  120. toastLength: Toast.LENGTH_SHORT,
  121. gravity: ToastGravity.CENTER,
  122. timeInSecForIosWeb: 1,
  123. textColor: Colors.white,
  124. fontSize: 16.0);
  125. Navigator.pushReplacement(
  126. context, MaterialPageRoute(builder: (context) => LoginView()));
  127. } else {
  128. String title = object['result']['title'].toString();
  129. String action = object['result']['action'].toString();
  130. String block = object['result']['block'].toString();
  131. if (block == "false") {
  132. Widget okButton = TextButton(
  133. child: Text(action),
  134. onPressed: () async {
  135. Uri url = Uri.parse(Uri.encodeFull("https://play.google.com/store/apps"));
  136. //final Uri uri = Uri(scheme: "https", host: "play.google.com");
  137. if(!await launchUrl(url, mode: LaunchMode.externalApplication)) {
  138. throw "Can not launch url";
  139. }
  140. },
  141. );
  142. Widget noButton = TextButton(
  143. child: Text("Later"),
  144. onPressed: () {
  145. if (session == ""){
  146. Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => LoginView()));
  147. } else {
  148. Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => HomeView()));
  149. }
  150. },
  151. );
  152. // set up the AlertDialog
  153. AlertDialog alert = AlertDialog(
  154. title: Text(appName),
  155. content: Text(title + "\n" + message),
  156. actions: [noButton, okButton],
  157. );
  158. // show the dialog
  159. showDialog(
  160. context: context,
  161. barrierDismissible: false,
  162. builder: (BuildContext context) {
  163. return alert;
  164. },
  165. );
  166. } else if (block == "true") {
  167. Widget okButton = TextButton(
  168. child: Text(action),
  169. onPressed: () async {
  170. if (action == "update") {
  171. /* _launchURL(Uri.parse("https://play.google.com/store/apps"));
  172. SystemChannels.platform.invokeMethod('SystemNavigator.pop');*/
  173. Uri url = Uri.parse(Uri.encodeFull("https://play.google.com/store/apps"));
  174. //final Uri uri = Uri(scheme: "https", host: "play.google.com");
  175. if(!await launchUrl(url, mode: LaunchMode.externalApplication)) {
  176. throw "Can not launch url";
  177. }
  178. } else if (action == "close") {
  179. SystemChannels.platform.invokeMethod('SystemNavigator.pop');
  180. }
  181. },
  182. );
  183. // set up the AlertDialog
  184. AlertDialog alert = AlertDialog(
  185. title: Text(appName),
  186. content: Text(title + "\n" + message),
  187. actions: [okButton],
  188. );
  189. // show the dialog
  190. showDialog(
  191. context: context,
  192. barrierDismissible: false,
  193. builder: (BuildContext context) {
  194. return alert;
  195. },
  196. );
  197. }
  198. }
  199. }
  200. } else {
  201. alertDialogFailedResponse(context);
  202. /*Fluttertoast.showToast(
  203. msg: "Server Response Error",
  204. toastLength: Toast.LENGTH_SHORT,
  205. gravity: ToastGravity.CENTER,
  206. timeInSecForIosWeb: 1,
  207. textColor: Colors.white,
  208. fontSize: 16.0);*/
  209. }
  210. });
  211. }
  212. _launchURL(Uri url) async {
  213. if (await canLaunchUrl(url)) {
  214. await launchUrl(url);
  215. } else {
  216. throw 'Could not launch $url';
  217. }
  218. }
  219. alertDialogFailedResponse(BuildContext context){
  220. Widget okButton = TextButton(
  221. child: Text("Refresh"),
  222. onPressed: () {
  223. Navigator.of(context, rootNavigator: true).pop();
  224. Navigator.pushReplacement(context, MaterialPageRoute(
  225. builder: (context) => SplashScreen()));
  226. },
  227. );
  228. Widget noButton = TextButton(
  229. child: Text("Back"),
  230. onPressed: () {
  231. Navigator.of(context, rootNavigator: true).pop();
  232. Navigator.pop(context);
  233. },
  234. );
  235. // set up the AlertDialog
  236. AlertDialog alert = AlertDialog(
  237. title: Text(appName),
  238. content: Text("Server Response Error"),
  239. actions: [
  240. noButton,
  241. okButton,
  242. ],
  243. );
  244. // show the dialog
  245. showDialog(
  246. context: context,
  247. barrierDismissible: false,
  248. builder: (BuildContext context) {
  249. return alert;
  250. },
  251. );
  252. }