root_page.dart 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. import 'dart:async';
  2. import 'dart:convert';
  3. import 'package:bbyyy/beans/coupon_bean_entity.dart';
  4. import 'package:bbyyy/beans/user_bean_entity.dart';
  5. import 'package:bbyyy/https/MyDio.dart';
  6. import 'package:bbyyy/https/my_request.dart';
  7. import 'package:bbyyy/my_tools/dims.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/loacion_util.dart';
  11. import 'package:bbyyy/my_tools/my_colors.dart';
  12. import 'package:bbyyy/my_tools/my_cookie.dart';
  13. import 'package:bbyyy/my_tools/my_datas.dart';
  14. import 'package:bbyyy/my_tools/my_tools.dart';
  15. import 'package:bbyyy/my_tools/pop_up_queue.dart';
  16. import 'package:bbyyy/nsq/nsq.dart' as Nsq;
  17. import 'package:bbyyy/paegs/gang_page/gang_page.dart';
  18. import 'package:bbyyy/paegs/home_page/home_page.dart';
  19. import 'package:bbyyy/paegs/mine_page/mine_page.dart';
  20. import 'package:bbyyy/paegs/mine_page/order_page/order_page.dart';
  21. import 'package:bbyyy/paegs/msg_page/msg_page.dart';
  22. import 'package:bbyyy/paegs/root_page/root_page_view.dart';
  23. import 'package:flutter/cupertino.dart';
  24. import 'package:flutter/gestures.dart';
  25. import 'package:flutter/material.dart';
  26. import 'package:flutter/services.dart';
  27. import 'package:flutter_svg/flutter_svg.dart';
  28. class RootPage extends StatefulWidget {
  29. @override
  30. _RootPageState createState() => _RootPageState();
  31. }
  32. class _RootPageState extends State<RootPage> {
  33. PageController pageController = PageController(initialPage: 0);
  34. DateTime lastPopTime;
  35. double ppx;
  36. @override
  37. void initState() {
  38. super.initState();
  39. MyCookie().initP();
  40. LocationUtil().initLocation(context);
  41. LocationUtil().getLocation();
  42. Nsq.ConnectServer(
  43. Nsq.handlerMessage, // 接收消息处理逻辑
  44. // serverIp: '172.16.104.14',
  45. serverIp: MyCookie().server,
  46. // 服务端返回
  47. serverPort: 4150,
  48. // 服务端返回
  49. topic: '${MyCookie().getUID()}',
  50. // 主题订阅,服务端返回
  51. channel: '${MyCookie().getUID()}',
  52. // 服务端返回uid
  53. clientId: '客户uid',
  54. // 服务端返回uid
  55. hostname: '主机名', // 服务端返回
  56. );
  57. EventBus().emit('检查粘贴板');
  58. EventBus().on('ChangePage', (arg) {
  59. if (RootPageView().bNIndex == 3) {
  60. queryPersonalInformation();
  61. }
  62. pageController.jumpToPage(RootPageView().bNIndex);
  63. setState(() {});
  64. });
  65. EventBus().on('hasNoPay', (arg) {
  66. setState(() {});
  67. });
  68. EventBus().on('showRP', (arg) {
  69. signInRedEnvelope();
  70. });
  71. MyData().init(context);
  72. queryPersonalInformation();
  73. checkForUpdates(context);
  74. Future.delayed(Duration(seconds: 1), () {
  75. checkCouponEvent();
  76. });
  77. }
  78. @override
  79. void dispose() {
  80. // TODO: implement dispose
  81. EventBus().off('ChangePage');
  82. EventBus().off('hasNoPay');
  83. EventBus().off('showRP');
  84. LocationUtil().stopLocation();
  85. super.dispose();
  86. }
  87. @override
  88. Widget build(BuildContext context) {
  89. ppx = MediaQuery.of(context).size.width / 375;
  90. return WillPopScope(
  91. onWillPop: () async {
  92. if (lastPopTime == null ||
  93. DateTime.now().difference(lastPopTime) > Duration(seconds: 2)) {
  94. lastPopTime = DateTime.now();
  95. EasyLoading.showToast('再按一次退出');
  96. } else {
  97. lastPopTime = DateTime.now();
  98. await SystemChannels.platform.invokeMethod('SystemNavigator.pop');
  99. }
  100. return false;
  101. },
  102. child: Scaffold(
  103. resizeToAvoidBottomInset: false,
  104. backgroundColor: Colors.transparent,
  105. body: Stack(
  106. children: [
  107. Column(
  108. children: [
  109. Expanded(
  110. child: PageView(
  111. controller: pageController,
  112. children: [HomePage(), GangPage(), MsgPage(), MinePage()],
  113. physics: NeverScrollableScrollPhysics(),
  114. ),
  115. ),
  116. RootPageView().bottomNavigationBar(),
  117. ],
  118. ),
  119. if (MyCookie().haveNoPay)
  120. Positioned(
  121. bottom: 60,
  122. right: 0,
  123. child: SafeArea(
  124. top: false,
  125. child: GestureDetector(
  126. onTap: () {
  127. MyTools().toPage(
  128. context,
  129. OrderPage(
  130. index: 2,
  131. ), (then) {
  132. queryPersonalInformation();
  133. });
  134. },
  135. behavior: HitTestBehavior.translucent,
  136. child: Container(
  137. height: 44,
  138. width: 100,
  139. padding: EdgeInsets.symmetric(horizontal: 10),
  140. child: Row(
  141. children: [
  142. SvgPicture.asset(
  143. 'images/svg/订单.svg',
  144. color: Colors.white,
  145. height: 15,
  146. width: 15,
  147. ),
  148. Text(
  149. '未付订单',
  150. style: TextStyle(color: Colors.white, fontSize: 14),
  151. )
  152. ],
  153. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  154. ),
  155. decoration: BoxDecoration(
  156. color: Colors.amber,
  157. borderRadius: BorderRadius.only(
  158. topLeft: Radius.circular(22),
  159. bottomLeft: Radius.circular(22),
  160. ),
  161. ),
  162. ),
  163. ),
  164. ),
  165. ),
  166. ],
  167. ),
  168. ),
  169. );
  170. }
  171. void queryPersonalInformation() {
  172. MyDio().query({
  173. "key": "user",
  174. "filters": {
  175. "conditions": ["uid == ${MyCookie().getUID()}"]
  176. },
  177. "dims": userDims,
  178. "paging": [1, 20]
  179. }, (response, hasError) {
  180. if (!hasError) {
  181. UserBeanEntity entity =
  182. UserBeanEntity().fromJson(json.decode(response.data.toString()));
  183. MyCookie().userBean = entity.data.data[0];
  184. EventBus().emit('userChange');
  185. }
  186. }, (error) {});
  187. }
  188. //查询优惠券活动
  189. checkCouponEvent() {
  190. MyDio().query({
  191. "key": "coupon_distribute",
  192. "filters": {
  193. "conditions": ["valid==true"],
  194. },
  195. "dims": couponDistributeDims,
  196. "paging": [1, 100]
  197. }, (response, hasError) {
  198. if (!hasError) {
  199. CouponBeanEntity entity =
  200. CouponBeanEntity().fromJson(json.decode(response.data.toString()));
  201. PopUpQueue().coupon.addAll(entity.data.data);
  202. }
  203. }, (error) {});
  204. }
  205. int showWitch = 0;
  206. //登录红包
  207. signInRedEnvelope() {
  208. showDialog<void>(
  209. context: context,
  210. barrierDismissible: false,
  211. // false = user must tap button, true = tap outside dialog
  212. builder: (BuildContext dialogContext) {
  213. return StatefulBuilder(builder: (BuildContext context, void Function(void Function()) setState) {
  214. return Container(
  215. child: Column(
  216. children: [
  217. showRedEnvelope(setState),
  218. GestureDetector(
  219. onTap: () {
  220. showWitch = 0;
  221. Navigator.pop(context);
  222. },
  223. child: Container(
  224. margin: EdgeInsets.only(top: 24 * ppx),
  225. child: Icon(
  226. Icons.clear,
  227. color: Colors.white,
  228. ),
  229. height: 28 * ppx,
  230. width: 28 * ppx,
  231. alignment: Alignment.center,
  232. decoration: BoxDecoration(
  233. color: MyColors.c25E7E7E7,
  234. borderRadius: BorderRadius.circular(14 * ppx)),
  235. ),
  236. )
  237. ],
  238. mainAxisAlignment: MainAxisAlignment.center,
  239. ),
  240. alignment: Alignment.center,
  241. );
  242. },);
  243. },
  244. );
  245. }
  246. Stack showRedEnvelope(void Function(void Function() p1) setState) {
  247. switch (showWitch) {
  248. case 0:
  249. return redEnvelopeP1(setState);
  250. case 1:
  251. return redEnvelopeP2(setState);
  252. case 2:
  253. return redEnvelopeP3(setState);
  254. default:
  255. return redEnvelopeP1(setState);
  256. }
  257. }
  258. Stack redEnvelopeP1(void Function(void Function() p1) setState) {
  259. return Stack(
  260. children: [
  261. Positioned(
  262. child: Container(
  263. height: 396 * ppx,
  264. width: double.infinity,
  265. decoration: BoxDecoration(
  266. borderRadius: BorderRadius.circular(16),
  267. color: MyColors.cF25D4B),
  268. margin: EdgeInsets.symmetric(horizontal: 45 * ppx),
  269. alignment: Alignment.bottomCenter,
  270. child: CustomPaint(
  271. painter: RedEnvelopePath(),
  272. size: Size(double.infinity - (90 * ppx), 120 * ppx)),
  273. ),
  274. ),
  275. Positioned(
  276. bottom: 40 * ppx,
  277. left: ((375 / 2 - 45) * ppx),
  278. child: GestureDetector(
  279. onTap: () {
  280. setState((){
  281. showWitch = 1;
  282. });
  283. },
  284. behavior: HitTestBehavior.translucent,
  285. child: Container(
  286. decoration: BoxDecoration(
  287. color: MyColors.cF1D19B,
  288. borderRadius: BorderRadius.circular(45 * ppx)),
  289. height: 90 * ppx,
  290. width: 90 * ppx,
  291. child: Text(
  292. '抢',
  293. style: TextStyle(
  294. color: MyColors.c333333,
  295. fontSize: 40 * ppx,
  296. decoration: TextDecoration.none,
  297. fontWeight: FontWeight.normal),
  298. ),
  299. alignment: Alignment.center,
  300. ),
  301. ),
  302. ),
  303. Positioned(
  304. child: Column(
  305. children: [
  306. SvgPicture.asset('images/svg/logo.svg'),
  307. Container(
  308. margin: EdgeInsets.only(top: 28 * ppx),
  309. child: Text(
  310. '登陆红包',
  311. style: TextStyle(
  312. color: Colors.white,
  313. fontSize: 32 * ppx,
  314. fontWeight: FontWeight.normal,
  315. decoration: TextDecoration.none),
  316. ),
  317. ),
  318. Container(
  319. margin: EdgeInsets.only(top: 4 * ppx),
  320. child: Text(
  321. '每人仅限1份',
  322. style: TextStyle(
  323. color: MyColors.cF1D19B,
  324. fontSize: 14 * ppx,
  325. fontWeight: FontWeight.normal,
  326. decoration: TextDecoration.none),
  327. ),
  328. )
  329. ],
  330. ),
  331. top: 37 * ppx,
  332. )
  333. ],
  334. alignment: Alignment.topCenter,
  335. );
  336. }
  337. Stack redEnvelopeP2(void Function(void Function() p1) setState) {
  338. return Stack(
  339. children: [
  340. Positioned(
  341. child: Container(
  342. height: 396 * ppx,
  343. width: double.infinity,
  344. decoration: BoxDecoration(
  345. borderRadius: BorderRadius.circular(16),
  346. color: MyColors.cF55544),
  347. margin: EdgeInsets.symmetric(horizontal: 45 * ppx),
  348. alignment: Alignment.bottomCenter,
  349. ),
  350. ),
  351. Positioned(
  352. child: Column(
  353. children: [
  354. SvgPicture.asset('images/svg/logo.svg'),
  355. Container(
  356. margin: EdgeInsets.only(top: 48 * ppx),
  357. child: Text(
  358. '0.30元',
  359. style: TextStyle(
  360. color: MyColors.cF1D19B,
  361. fontSize: 30 * ppx,
  362. fontWeight: FontWeight.normal,
  363. decoration: TextDecoration.none),
  364. ),
  365. ),
  366. Container(
  367. margin: EdgeInsets.only(top: 10 * ppx),
  368. child: RichText(
  369. text: TextSpan(
  370. text: '自动划入钱包,去',
  371. style: TextStyle(
  372. color: MyColors.c333333,
  373. decoration: TextDecoration.none,
  374. fontSize: 13 * ppx),
  375. children: [
  376. TextSpan(
  377. text: '提现',
  378. style: TextStyle(
  379. color: MyColors.c44D7B6,
  380. decoration: TextDecoration.underline,
  381. fontSize: 13 * ppx),
  382. recognizer: TapGestureRecognizer()
  383. ..onTap = () {
  384. setState((){
  385. showWitch = 2;
  386. });
  387. }),
  388. ]),
  389. ),
  390. )
  391. ],
  392. ),
  393. top: 37 * ppx,
  394. ),
  395. Positioned(
  396. child: Column(
  397. children: [
  398. Text(
  399. '详细规则',
  400. style: TextStyle(
  401. color: Colors.white,
  402. fontSize: 12 * ppx,
  403. fontWeight: FontWeight.normal,
  404. decoration: TextDecoration.none),
  405. ),
  406. Container(
  407. margin: EdgeInsets.only(top: 4 * ppx),
  408. child: Text(
  409. '每人每天限领一份,每天八点官方准时派发登陆活动,',
  410. style: TextStyle(
  411. color: Colors.white,
  412. fontSize: 9 * ppx,
  413. fontWeight: FontWeight.normal,
  414. decoration: TextDecoration.none),
  415. ),
  416. ),
  417. Text(
  418. '每天10000元,最高可直接领取100元!!!',
  419. style: TextStyle(
  420. color: Colors.white,
  421. fontSize: 9 * ppx,
  422. fontWeight: FontWeight.normal,
  423. decoration: TextDecoration.none),
  424. ),
  425. ],
  426. ),
  427. bottom: 20 * ppx,
  428. )
  429. ],
  430. alignment: Alignment.topCenter,
  431. );
  432. }
  433. Stack redEnvelopeP3(void Function(void Function() p1) setState) {
  434. return Stack(
  435. children: [
  436. Positioned(
  437. child: Container(
  438. height: 396 * ppx,
  439. width: double.infinity,
  440. decoration: BoxDecoration(
  441. borderRadius: BorderRadius.circular(16),
  442. color: MyColors.cF55544),
  443. margin: EdgeInsets.symmetric(horizontal: 45 * ppx),
  444. ),
  445. ),
  446. Positioned(
  447. child: Column(
  448. children: [
  449. SvgPicture.asset('images/svg/logo.svg'),
  450. Container(
  451. margin: EdgeInsets.only(top: 64 * ppx),
  452. child: Text(
  453. '呀!来晚了,明天我一定准时!',
  454. style: TextStyle(
  455. color: MyColors.cF1D19B,
  456. fontSize: 15 * ppx,
  457. fontWeight: FontWeight.normal,
  458. decoration: TextDecoration.none),
  459. ),
  460. )
  461. ],
  462. ),
  463. top: 37 * ppx,
  464. ),
  465. Positioned(
  466. child: Column(
  467. children: [
  468. Text(
  469. '详细规则',
  470. style: TextStyle(
  471. color: Colors.white,
  472. fontSize: 12 * ppx,
  473. fontWeight: FontWeight.normal,
  474. decoration: TextDecoration.none),
  475. ),
  476. Container(
  477. margin: EdgeInsets.only(top: 4 * ppx),
  478. child: Text(
  479. '每人每天限领一份,每天八点官方准时派发登陆活动,',
  480. style: TextStyle(
  481. color: Colors.white,
  482. fontSize: 9 * ppx,
  483. fontWeight: FontWeight.normal,
  484. decoration: TextDecoration.none),
  485. ),
  486. ),
  487. Text(
  488. '每天10000元,最高可直接领取100元!!!',
  489. style: TextStyle(
  490. color: Colors.white,
  491. fontSize: 9 * ppx,
  492. fontWeight: FontWeight.normal,
  493. decoration: TextDecoration.none),
  494. ),
  495. ],
  496. ),
  497. bottom: 20 * ppx,
  498. )
  499. ],
  500. alignment: Alignment.topCenter,
  501. );
  502. }
  503. }
  504. class RedEnvelopePath extends CustomPainter {
  505. Paint _paint = Paint()
  506. ..color = MyColors.cF55544 //画笔颜色
  507. ..strokeCap = StrokeCap.round //画笔笔触类型
  508. ..isAntiAlias = true //是否启动抗锯齿
  509. ..strokeWidth = 15.0; //画笔的宽度
  510. @override
  511. void paint(Canvas canvas, Size size) {
  512. print(size);
  513. var path = Path()
  514. ..moveTo(0, 0)
  515. ..quadraticBezierTo(size.width / 2, 80, size.width, 0)
  516. ..lineTo(size.width, size.height - 16)
  517. ..quadraticBezierTo(size.width, size.height, size.width - 16, size.height)
  518. ..lineTo(16, size.height)
  519. ..quadraticBezierTo(0, size.height, 0, size.height - 16)
  520. ..close();
  521. canvas.drawPath(path, _paint);
  522. }
  523. @override
  524. bool shouldRepaint(covariant CustomPainter oldDelegate) {
  525. return null;
  526. }
  527. }