| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563 |
- import 'dart:async';
- import 'dart:convert';
- import 'package:bbyyy/beans/coupon_bean_entity.dart';
- import 'package:bbyyy/beans/grab_a_red_envelope_bean_entity.dart';
- import 'package:bbyyy/beans/user_balance_entity.dart';
- import 'package:bbyyy/beans/user_bean_entity.dart';
- import 'package:bbyyy/https/MyDio.dart';
- import 'package:bbyyy/https/my_request.dart';
- import 'package:bbyyy/my_tools/daily_red_packet/daily_red_packet.dart';
- import 'package:bbyyy/my_tools/dims.dart';
- import 'package:bbyyy/my_tools/easy_loading/easy_loading.dart';
- import 'package:bbyyy/my_tools/event_bus.dart';
- import 'package:bbyyy/my_tools/loacion_util.dart';
- import 'package:bbyyy/my_tools/my_colors.dart';
- import 'package:bbyyy/my_tools/my_cookie.dart';
- import 'package:bbyyy/my_tools/my_datas.dart';
- import 'package:bbyyy/my_tools/my_tools.dart';
- import 'package:bbyyy/my_tools/pop_up_queue.dart';
- import 'package:bbyyy/my_tools/s.dart';
- import 'package:bbyyy/nsq/nsq.dart' as Nsq;
- import 'package:bbyyy/paegs/gang_page/gang_page.dart';
- import 'package:bbyyy/paegs/home_page/home_page.dart';
- import 'package:bbyyy/paegs/mine_page/bind_alipay_page/bind_alipay_page.dart';
- import 'package:bbyyy/paegs/mine_page/mine_page.dart';
- import 'package:bbyyy/paegs/mine_page/order_page/order_page.dart';
- import 'package:bbyyy/paegs/mine_page/wallet_page/withdraw_page/withdraw_page.dart';
- import 'package:bbyyy/paegs/msg_page/msg_page.dart';
- import 'package:bbyyy/paegs/root_page/root_page_view.dart';
- import 'package:bbyyy/pay/pay_tools.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/gestures.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:flutter_svg/flutter_svg.dart';
- class RootPage extends StatefulWidget {
- @override
- _RootPageState createState() => _RootPageState();
- }
- class _RootPageState extends State<RootPage> {
- PageController pageController = PageController(initialPage: 0);
- DateTime lastPopTime;
- double ppx;
- @override
- void initState() {
- super.initState();
- // s().encryption();
- LocationUtil().initLocation(context);
- LocationUtil().getLocation();
- Nsq.ConnectServer(
- Nsq.handlerMessage, // 接收消息处理逻辑
- // serverIp: '172.16.104.14',
- serverIp: MyCookie().server,
- // 服务端返回
- serverPort: 4150,
- // 服务端返回
- topic: '${MyCookie().getUID()}',
- // 主题订阅,服务端返回
- channel: '${MyCookie().getUID()}',
- // 服务端返回uid
- clientId: '客户uid',
- // 服务端返回uid
- hostname: '主机名', // 服务端返回
- );
- EventBus().emit('检查粘贴板');
- EventBus().on('ChangePage', (arg) {
- if (RootPageView().bNIndex == 3) {
- queryPersonalInformation();
- }
- pageController.jumpToPage(RootPageView().bNIndex);
- setState(() {});
- });
- EventBus().on('hasNoPay', (arg) {
- setState(() {});
- });
- EventBus().on('showRP', (arg) {
- signInRedEnvelope();
- });
- MyData().init(context);
- queryPersonalInformation();
- checkForUpdates(context);
- Future.delayed(Duration(seconds: 1), () {
- // checkCouponEvent();
- DailyRedPacketTool().queryRedEnvelopeInformation();
- getUserWalletBalance((re, hE) {
- if (!hE) {
- UserBalanceEntity balance =
- UserBalanceEntity().fromJson(json.decode(re.data.toString()));
- MyCookie().balance = balance.data;
- }
- }, (e) {}, context);
- });
- }
- @override
- void dispose() {
- // TODO: implement dispose
- EventBus().off('ChangePage');
- EventBus().off('hasNoPay');
- EventBus().off('showRP');
- LocationUtil().stopLocation();
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- ppx = MediaQuery.of(context).size.width / 375;
- return WillPopScope(
- onWillPop: () async {
- if (lastPopTime == null ||
- DateTime.now().difference(lastPopTime) > Duration(seconds: 2)) {
- lastPopTime = DateTime.now();
- EasyLoading.showToast('再按一次退出');
- } else {
- lastPopTime = DateTime.now();
- await SystemChannels.platform.invokeMethod('SystemNavigator.pop');
- }
- return false;
- },
- child: Scaffold(
- resizeToAvoidBottomInset: false,
- backgroundColor: Colors.transparent,
- body: Stack(
- children: [
- Column(
- children: [
- Expanded(
- child: PageView(
- controller: pageController,
- children: [HomePage(), GangPage(), MsgPage(), MinePage()],
- physics: NeverScrollableScrollPhysics(),
- ),
- ),
- RootPageView().bottomNavigationBar(),
- ],
- ),
- if (MyCookie().haveNoPay)
- Positioned(
- bottom: 60,
- right: 0,
- child: SafeArea(
- top: false,
- child: GestureDetector(
- onTap: () {
- MyTools().toPage(
- context,
- OrderPage(
- index: 2,
- ), (then) {
- queryPersonalInformation();
- });
- },
- behavior: HitTestBehavior.translucent,
- child: Container(
- height: 44,
- width: 100,
- padding: EdgeInsets.symmetric(horizontal: 10),
- child: Row(
- children: [
- SvgPicture.asset(
- 'images/svg/订单.svg',
- color: Colors.white,
- height: 15,
- width: 15,
- ),
- Text(
- '未付订单',
- style: TextStyle(color: Colors.white, fontSize: 14),
- )
- ],
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- ),
- decoration: BoxDecoration(
- color: Colors.amber,
- borderRadius: BorderRadius.only(
- topLeft: Radius.circular(22),
- bottomLeft: Radius.circular(22),
- ),
- ),
- ),
- ),
- ),
- ),
- ],
- ),
- ),
- );
- }
- void queryPersonalInformation() {
- MyDio().query({
- "key": "user",
- "filters": {
- "conditions": ["uid == ${MyCookie().getUID()}"]
- },
- "dims": userDims,
- "paging": [1, 20]
- }, (response, hasError) {
- if (!hasError) {
- UserBeanEntity entity =
- UserBeanEntity().fromJson(json.decode(response.data.toString()));
- MyCookie().userBean = entity.data.data[0];
- EventBus().emit('userChange');
- }
- }, (error) {});
- }
- //查询优惠券活动
- // checkCouponEvent() {
- // MyDio().query({
- // "key": "coupon_distribute",
- // "filters": {
- // "conditions": ["valid==true"],
- // },
- // "dims": couponDistributeDims,
- // "paging": [1, 100]
- // }, (response, hasError) {
- // if (!hasError) {
- // CouponBeanEntity entity =
- // CouponBeanEntity().fromJson(json.decode(response.data.toString()));
- // PopUpQueue().coupon.addAll(entity.data.data);
- // }
- // }, (error) {});
- // }
- int showWitch = 0;
- //登录红包
- signInRedEnvelope() {
- showDialog<void>(
- context: context,
- barrierDismissible: false,
- // false = user must tap button, true = tap outside dialog
- builder: (BuildContext dialogContext) {
- return StatefulBuilder(
- builder:
- (BuildContext context, void Function(void Function()) setState) {
- return Container(
- child: Column(
- children: [
- showRedEnvelope(setState),
- GestureDetector(
- onTap: () {
- showWitch = 0;
- Navigator.pop(context);
- },
- child: Container(
- margin: EdgeInsets.only(top: 24 * ppx),
- child: Icon(
- Icons.clear,
- color: Colors.white,
- ),
- height: 28 * ppx,
- width: 28 * ppx,
- alignment: Alignment.center,
- decoration: BoxDecoration(
- color: MyColors.c25E7E7E7,
- borderRadius: BorderRadius.circular(14 * ppx)),
- ),
- )
- ],
- mainAxisAlignment: MainAxisAlignment.center,
- ),
- alignment: Alignment.center,
- );
- },
- );
- },
- );
- }
- Stack showRedEnvelope(void Function(void Function() p1) setState) {
- switch (showWitch) {
- case 0:
- return redEnvelopeP1(setState);
- case 1:
- return redEnvelopeP2(setState);
- case 2:
- return redEnvelopeP3(setState);
- default:
- return redEnvelopeP1(setState);
- }
- }
- bool grab = false;
- Stack redEnvelopeP1(void Function(void Function() p1) setState) {
- return Stack(
- children: [
- Positioned(
- child: Container(
- height: 396 * ppx,
- width: double.infinity,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(16),
- color: MyColors.cF25D4B),
- margin: EdgeInsets.symmetric(horizontal: 45 * ppx),
- alignment: Alignment.bottomCenter,
- child: CustomPaint(
- painter: RedEnvelopePath(),
- size: Size(double.infinity - (90 * ppx), 120 * ppx)),
- ),
- ),
- Positioned(
- bottom: 40 * ppx,
- left: ((375 / 2 - 45) * ppx),
- child: GestureDetector(
- onTap: () {
- setState(() {
- grab = true;
- });
- if (DailyRedPacketTool().dailyRedPacket.valid) {
- EventBus().on('grabARedEnvelope', (arg) {
- if (arg is GrabARedEnvelopeBeanData) {
- if (arg.success) {
- setState(() {
- showWitch = 1;
- });
- } else {
- setState(() {
- showWitch = 2;
- });
- }
- }
- EventBus().off('grabARedEnvelope');
- });
- DailyRedPacketTool().grabARedEnvelope();
- } else {
- setState(() {
- showWitch = 2;
- });
- }
- },
- behavior: HitTestBehavior.translucent,
- child: Container(
- decoration: BoxDecoration(
- color: MyColors.cF1D19B,
- borderRadius: BorderRadius.circular(45 * ppx)),
- height: 90 * ppx,
- width: 90 * ppx,
- child: grab
- ? Container(
- height: 40,
- width: 40,
- padding: const EdgeInsets.all(2.0),
- child: CircularProgressIndicator(
- backgroundColor: Colors.transparent,
- valueColor: AlwaysStoppedAnimation(Colors.white),
- strokeWidth: 2,
- ),
- )
- : Text(
- '抢',
- style: TextStyle(
- color: MyColors.c333333,
- fontSize: 40 * ppx,
- decoration: TextDecoration.none,
- fontWeight: FontWeight.normal),
- ),
- alignment: Alignment.center,
- ),
- ),
- ),
- Positioned(
- child: Column(
- children: [
- SvgPicture.asset('images/svg/logo.svg'),
- Container(
- margin: EdgeInsets.only(top: 28 * ppx),
- child: Text(
- '登录红包',
- style: TextStyle(
- color: Colors.white,
- fontSize: 32 * ppx,
- fontWeight: FontWeight.normal,
- decoration: TextDecoration.none),
- ),
- ),
- Container(
- margin: EdgeInsets.only(top: 4 * ppx),
- child: Text(
- '每人仅限1份',
- style: TextStyle(
- color: MyColors.cF1D19B,
- fontSize: 14 * ppx,
- fontWeight: FontWeight.normal,
- decoration: TextDecoration.none),
- ),
- )
- ],
- ),
- top: 37 * ppx,
- )
- ],
- alignment: Alignment.topCenter,
- );
- }
- Stack redEnvelopeP2(void Function(void Function() p1) setState) {
- return Stack(
- children: [
- Positioned(
- child: Container(
- height: 396 * ppx,
- width: double.infinity,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(16),
- color: MyColors.cEB4935),
- margin: EdgeInsets.symmetric(horizontal: 45 * ppx),
- alignment: Alignment.bottomCenter,
- ),
- ),
- Positioned(
- child: Column(
- children: [
- SvgPicture.asset('images/svg/logo.svg'),
- Container(
- margin: EdgeInsets.only(top: 67 * ppx),
- child: Text(
- '${DailyRedPacketTool().grabARedEnvelopeBeanData.amount}元',
- style: TextStyle(
- color: MyColors.cF1D19B,
- fontSize: 38 * ppx,
- fontWeight: FontWeight.bold,
- decoration: TextDecoration.none),
- ),
- ),
- ],
- ),
- top: 37 * ppx,
- ),
- Positioned(
- child: RichText(
- text: TextSpan(
- text: '自动划入钱包,去',
- style: TextStyle(
- color: Colors.white,
- decoration: TextDecoration.none,
- fontSize: 13 * ppx),
- children: [
- TextSpan(
- text: '提现',
- style: TextStyle(
- color: Colors.white,
- decoration: TextDecoration.underline,
- fontSize: 13 * ppx),
- recognizer: TapGestureRecognizer()
- ..onTap = () {
- if (MyCookie().userBean.aliPayAccount.isEmpty ||
- MyCookie().userBean.aliPayName.isEmpty) {
- MyTools().toPage(context, BindAlipayPage(),
- (then) {
- if (MyCookie()
- .userBean
- .aliPayAccount
- .isNotEmpty &&
- MyCookie()
- .userBean
- .aliPayName
- .isNotEmpty) {
- MyTools().toPage(context, WithdrawPage(),
- (then) {
- queryPersonalInformation();
- });
- }
- });
- } else {
- MyTools().toPage(context, WithdrawPage(),
- (then) {
- queryPersonalInformation();
- });
- }
- }),
- ]),
- ),
- bottom: 20 * ppx,
- )
- ],
- alignment: Alignment.topCenter,
- );
- }
- Stack redEnvelopeP3(void Function(void Function() p1) setState) {
- return Stack(
- children: [
- Positioned(
- child: Container(
- height: 396 * ppx,
- width: double.infinity,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(16),
- color: MyColors.cEB4935),
- margin: EdgeInsets.symmetric(horizontal: 45 * ppx),
- ),
- ),
- Positioned(
- child: Column(
- children: [
- SvgPicture.asset('images/svg/logo.svg'),
- Container(
- margin: EdgeInsets.only(top: 64 * ppx),
- padding: EdgeInsets.symmetric(horizontal: 12*ppx),
- width: ppx*285,
- child: Text(
- '${DailyRedPacketTool().grabARedEnvelopeBeanData.msg}',
- textAlign: TextAlign.center,
- style: TextStyle(
- color: MyColors.cF1D19B,
- fontSize: 18 * ppx,
- fontWeight: FontWeight.normal,
- decoration: TextDecoration.none,),
- maxLines: 5,
- ),
- )
- ],
- ),
- top: 37 * ppx,
- ),
- Positioned(
- child: Text(
- '谢谢支持,欢迎参与后续活动!',
- style: TextStyle(
- color: Colors.white,
- fontSize: 13 * ppx,
- fontWeight: FontWeight.normal,
- decoration: TextDecoration.none),
- ),
- bottom: 20 * ppx,
- )
- ],
- alignment: Alignment.topCenter,
- );
- }
- }
- class RedEnvelopePath extends CustomPainter {
- Paint _paint = Paint()
- ..color = MyColors.cF55544 //画笔颜色
- ..strokeCap = StrokeCap.round //画笔笔触类型
- ..isAntiAlias = true //是否启动抗锯齿
- ..strokeWidth = 15.0; //画笔的宽度
- @override
- void paint(Canvas canvas, Size size) {
- var path = Path()
- ..moveTo(0, 0)
- ..quadraticBezierTo(size.width / 2, 80, size.width, 0)
- ..lineTo(size.width, size.height - 16)
- ..quadraticBezierTo(size.width, size.height, size.width - 16, size.height)
- ..lineTo(16, size.height)
- ..quadraticBezierTo(0, size.height, 0, size.height - 16)
- ..close();
- canvas.drawPath(path, _paint);
- }
- @override
- bool shouldRepaint(covariant CustomPainter oldDelegate) {
- return false;
- }
- }
|