welcome_page.dart 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import 'dart:async';
  2. import 'dart:convert';
  3. import 'dart:io';
  4. import 'package:bbyyy/beans/app_store_review_bean_entity.dart';
  5. import 'package:bbyyy/beans/login_information_bean_entity.dart';
  6. import 'package:bbyyy/https/MyDio.dart';
  7. import 'package:bbyyy/https/my_request.dart';
  8. import 'package:bbyyy/my_tools/easy_loading/easy_loading.dart';
  9. import 'package:bbyyy/my_tools/event_bus.dart';
  10. import 'package:bbyyy/my_tools/my_colors.dart';
  11. import 'package:bbyyy/my_tools/my_cookie.dart';
  12. import 'package:bbyyy/my_tools/my_tools.dart';
  13. import 'package:bbyyy/my_tools/my_views.dart';
  14. import 'package:bbyyy/my_tools/s.dart';
  15. import 'package:bbyyy/paegs/login_page/login_page.dart';
  16. import 'package:bbyyy/paegs/root_page/root_page.dart';
  17. import 'package:flutter/material.dart';
  18. import 'package:flutter/services.dart';
  19. class WelcomePage extends StatefulWidget {
  20. @override
  21. _WelcomePageState createState() => _WelcomePageState();
  22. }
  23. class _WelcomePageState extends State<WelcomePage> {
  24. @override
  25. void initState() {
  26. super.initState();
  27. EasyLoading.instance
  28. ..displayDuration = const Duration(milliseconds: 1500)
  29. ..indicatorType = EasyLoadingIndicatorType.ring
  30. ..loadingStyle = EasyLoadingStyle.light
  31. ..maskType = EasyLoadingMaskType.black
  32. ..indicatorSize = 45.0
  33. ..radius = 10.0
  34. ..textPadding = EdgeInsets.all(0)
  35. ..contentPadding = EdgeInsets.fromLTRB(20, 12, 20, 12)
  36. ..userInteractions = false;
  37. EventBus().on('服务器异常,请稍后再试', (arg) {
  38. qAPP();
  39. });
  40. EventBus().on('packageInfo', (arg) {
  41. try{
  42. if(MyCookie().prefs.getString('timestamp')!=null&&MyCookie().prefs.getString('timestamp')!=''&&
  43. MyCookie().prefs.getString('uid')!=null&&MyCookie().prefs.getString('uid')!=''&&
  44. MyCookie().prefs.getString('using')!=null&&MyCookie().prefs.getString('using')!=''){
  45. s().encryption();
  46. }
  47. }catch(e){}
  48. isItUnderReview();
  49. });
  50. MyCookie().initP();
  51. }
  52. void isItUnderReview() {
  53. EasyLoading.show();
  54. MyDio().post(
  55. '/model/appStoreReview', {'version': MyCookie().packageInfo.version},
  56. (response, hasError) {
  57. if (!hasError) {
  58. EasyLoading.dismiss();
  59. AppStoreReviewBeanEntity e = AppStoreReviewBeanEntity()
  60. .fromJson(json.decode(response.data.toString()));
  61. print(e.data);
  62. if (e.data && Platform.isIOS) {
  63. MyCookie().underReview = true;
  64. } else {
  65. MyCookie().underReview = false;
  66. }
  67. EventBus().emit('appStoreReview');
  68. Timer(Duration(seconds: 1), () {
  69. if (MyCookie().getLoginInformation() == null ||
  70. MyCookie().getLoginInformation().data == null ||
  71. MyCookie().getLoginInformation().data.token.isEmpty ||
  72. MyCookie().getLoginInformation().data.token == '') {
  73. MyTools().toPage(context, LoginPage(), (then) {}, noBack: true);
  74. } else {
  75. MyDio().initDio();
  76. checkLogin((r, hE) {
  77. if (!hE) {
  78. String token = MyCookie().getToken();
  79. LoginInformationBeanEntity loginInformation =
  80. LoginInformationBeanEntity()
  81. .fromJson(json.decode(r.data.toString()));
  82. loginInformation.data.token = token;
  83. MyCookie().saveLoginInformationBeanEntity(loginInformation);
  84. MyTools().toPage(context, RootPage(), (then) {}, noBack: true);
  85. } else {
  86. MyTools().toPage(context, LoginPage(), (then) {}, noBack: true);
  87. }
  88. }, (e) {});
  89. }
  90. });
  91. }
  92. }, (error) {});
  93. }
  94. @override
  95. Widget build(BuildContext context) {
  96. return Scaffold(
  97. body: Stack(
  98. children: [
  99. Image.asset(
  100. 'images/we_bg.png',
  101. fit: BoxFit.cover,
  102. height: MediaQuery.of(context).size.height,
  103. width: MediaQuery.of(context).size.width,
  104. ),
  105. Image.asset(
  106. 'images/we_logo.png',
  107. height: 118,
  108. width: 118,
  109. )
  110. ],
  111. alignment: Alignment.center,
  112. ),
  113. );
  114. }
  115. void qAPP() {
  116. showDialog(
  117. context: context,
  118. builder: (BuildContext context) {
  119. return Material(
  120. color: Colors.black12,
  121. child: Center(
  122. child: Container(
  123. decoration: BoxDecoration(
  124. borderRadius: BorderRadius.circular(16),
  125. color: Colors.white,
  126. ),
  127. height: 180,
  128. margin: EdgeInsets.symmetric(horizontal: 18),
  129. padding: EdgeInsets.symmetric(horizontal: 8, vertical: 12),
  130. child: Column(
  131. children: [
  132. Expanded(
  133. child: Center(
  134. child: Container(
  135. child: MyViews()
  136. .myText('服务器出现异常,请稍后再试。', MyColors.c333333, 14),
  137. margin: EdgeInsets.symmetric(horizontal: 20),
  138. ),
  139. ),
  140. ),
  141. Container(
  142. height: 0.5,
  143. color: MyColors.cE7E7E7,
  144. margin: EdgeInsets.only(bottom: 12),
  145. ),
  146. Container(
  147. margin: EdgeInsets.symmetric(horizontal: 10),
  148. child: Expanded(
  149. child: GestureDetector(
  150. behavior: HitTestBehavior.translucent,
  151. onTap: () async {
  152. await SystemChannels.platform
  153. .invokeMethod('SystemNavigator.pop');
  154. },
  155. child: Container(
  156. decoration: BoxDecoration(
  157. borderRadius: BorderRadius.circular(20),
  158. color: MyColors.cFF4233),
  159. height: 40,
  160. child: MyViews().myText('退 出', Colors.white, 14),
  161. alignment: Alignment.center,
  162. ),
  163. ),
  164. ),
  165. )
  166. ],
  167. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  168. ),
  169. ),
  170. ),
  171. );
  172. },
  173. );
  174. }
  175. }