import 'dart:convert'; import 'package:bbyyy/beans/my_shop_bean_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/https/url.dart'; import 'package:bbyyy/my_tools/dims.dart'; import 'package:bbyyy/my_tools/event_bus.dart'; import 'package:bbyyy/my_tools/my_colors.dart'; import 'package:bbyyy/my_tools/my_cookie.dart'; import 'package:bbyyy/my_tools/my_tools.dart'; import 'package:bbyyy/my_tools/my_views.dart'; import 'package:bbyyy/paegs/chat_page/chat_page.dart'; import 'package:bbyyy/paegs/mine_page/my_goods_page/my_goods_page.dart'; import 'package:bbyyy/paegs/mine_page/my_information_page/my_information_page.dart'; import 'package:bbyyy/paegs/mine_page/order_page/order_page.dart'; import 'package:bbyyy/paegs/mine_page/promotion_download_page/promotion_download_page.dart'; import 'package:bbyyy/paegs/mine_page/punish_page/punish_page.dart'; import 'package:bbyyy/paegs/mine_page/referrer_page/referrer_page.dart'; import 'package:bbyyy/paegs/mine_page/set_page/set_page.dart'; import 'package:bbyyy/paegs/mine_page/wallet_page/wallet_page.dart'; import 'package:bbyyy/paegs/mine_page/wallet_page/withdraw_page/withdraw_page.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'advertising_page/advertising_page.dart'; import 'bind_alipay_page/bind_alipay_page.dart'; import 'coupon_page/coupon_page.dart'; import 'my_information_page/my_qr_page.dart'; class MinePage extends StatefulWidget { @override _MinePageState createState() => _MinePageState(); } class _MinePageState extends State { @override void initState() { // TODO: implement initState super.initState(); EventBus().on('userChange', (arg) { setState(() {}); }); EventBus().on('appStoreReview', (arg) { setState(() {}); }); checkIfThereIsAShop(); } @override void dispose() { // TODO: implement dispose super.dispose(); EventBus().off('userChange'); EventBus().off('appStoreReview'); } RefreshController controller = RefreshController(); @override Widget build(BuildContext context) { return Scaffold( body: SmartRefresher( controller: controller, onRefresh: onRefresh, child: SingleChildScrollView( child: Stack( children: [ Image.asset( 'images/mine_bg.png', width: MediaQuery.of(context).size.width, height: MediaQuery.of(context).size.width / 750 * 462, ), Column( children: [ SafeArea( bottom: false, child: Container( margin: EdgeInsets.only( top: 40, left: 20, right: 20, ), child: Row( children: [ GestureDetector( onTap: () { MyTools().toPage(context, MyInformationPage(), (then) { queryPersonalInformation(); }); }, behavior: HitTestBehavior.translucent, child: Container( margin: EdgeInsets.only(right: 10), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.all( Radius.circular(30), ), ), height: 60, width: 60, child: ClipRRect( borderRadius: BorderRadius.all( Radius.circular(26), ), child: MyViews().netImg( imgURL(MyCookie() .loginInformation .data .extra .picture), 52, 52), ), alignment: Alignment.center, ), ), Expanded( child: Container( height: 60, child: Column( children: [ Row( children: [ Expanded( child: GestureDetector( onTap: () { MyTools().toPage( context, MyInformationPage(), (then) { queryPersonalInformation(); }); }, child: Container( margin: EdgeInsets.only(right: 10), child: Text( MyCookie() .loginInformation .data .extra .name, style: TextStyle( color: Colors.white, fontSize: 18), maxLines: 1, overflow: TextOverflow.ellipsis, softWrap: true, ), ), ), ), Container( margin: EdgeInsets.only(left: 20), child: MyViews().myText( '¥${MyCookie().userBean.balance}', Colors.white, 24), ), ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ), Row( children: [ GestureDetector( onTap: (){ showToast('已复制到剪切板'); Clipboard.setData(ClipboardData(text: '${MyCookie().getUID()}')); }, behavior: HitTestBehavior.translucent, child: Row( children: [ Text( 'ID:${MyCookie().getUID()}', style: TextStyle( color: Colors.white, fontSize: 14, ), maxLines: 1, overflow: TextOverflow.ellipsis, softWrap: true, ), Container(margin: EdgeInsets.only(left: 10),child: Icon(Icons.copy,color: Colors.white,size: 14,)) ], ), ), GestureDetector( onTap: () { MyTools().toPage( context, MyQRPage(), (then) {}); }, behavior: HitTestBehavior.translucent, child: Container( child: Row( children: [ SvgPicture.asset( 'images/svg/二维码.svg', color: Colors.white, ), Container( width: 20, ), SvgPicture.asset( 'images/svg/箭头.svg', color: Colors.white, height: 12, width: 8, ) ], ), ), ) ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ), ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ), ), ), ], ), ), ), Card( margin: EdgeInsets.only( top: MediaQuery.of(context).size.width / 750 * 462 - 200, left: 20, right: 20), child: Padding( padding: EdgeInsets.only(top: 15, bottom: 13), child: Row( children: [ GestureDetector( onTap: () { MyTools().toPage(context, WalletPage(), (then) { queryPersonalInformation(); }); }, behavior: HitTestBehavior.translucent, child: Column( children: [ SvgPicture.asset('images/svg/钱包.svg'), Container( margin: EdgeInsets.only(top: 11), child: Text( '流水', style: TextStyle( color: MyColors.c333333, fontSize: 14), ), ) ], ), ), if (!MyCookie().underReview) GestureDetector( onTap: () { MyTools().toPage(context, CouponPage(), (then) { queryPersonalInformation(); }); }, behavior: HitTestBehavior.translucent, child: Column( children: [ SvgPicture.asset('images/svg/优惠券.svg'), Container( margin: EdgeInsets.only(top: 11), child: Text( '优惠券', style: TextStyle( color: MyColors.c333333, fontSize: 14), )) ], ), ), GestureDetector( onTap: () { MyTools().toPage(context, MyGoodsPage(), (then) { queryPersonalInformation(); }); }, behavior: HitTestBehavior.translucent, child: Column( children: [ SvgPicture.asset('images/svg/商品.svg'), Container( margin: EdgeInsets.only(top: 11), child: Text( '商品', style: TextStyle( color: MyColors.c333333, fontSize: 14), )) ], ), ), GestureDetector( 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(); }); } }, behavior: HitTestBehavior.translucent, child: Column( children: [ SvgPicture.asset('images/svg/提现.svg'), Container( margin: EdgeInsets.only(top: 11), child: Text( '提现', style: TextStyle( color: MyColors.c333333, fontSize: 14), )) ], ), ) ], mainAxisAlignment: MainAxisAlignment.spaceAround, ), ), elevation: 2, shadowColor: MyColors.c21333333, ), functionItem('images/svg/订单.svg', '订单', () { MyTools().toPage(context, OrderPage(), (then) { queryPersonalInformation(); }); }), if (showRe) functionItem('images/svg/推荐人.svg', '推荐人', () { MyTools().toPage(context, ReferrerPage(), (then) {}); }), functionItem('images/svg/绑定.svg', '提现账号', () { MyTools().toPage(context, BindAlipayPage(), (then) { queryPersonalInformation(); }); }), if (!MyCookie().underReview) functionItem('images/svg/广告.svg', '广告', () { MyTools().toPage(context, AdvertisingPage(), (then) {}); }), functionItem('images/svg/处罚.svg', '投诉', () { MyTools().toPage(context, PunishPage(), (then) { queryPersonalInformation(); }); }), functionItem('images/svg/客服.svg', '客服', () { MyShopBeanDataData chatWith = MyShopBeanDataData(); chatWith.userName = '客服'; chatWith.userUid = 0; chatWith.userPic = ''; MyTools().toPage(context, ChatPage(chatWith, null), (then) { queryPersonalInformation(); }); }), functionItem('images/svg/推广下载.svg', '推广下载', () { MyTools() .toPage(context, PromotionDownloadPage(), (then) {}); }), GestureDetector( onTap: () { checkForUpdates(context, showT: true); }, behavior: HitTestBehavior.translucent, child: Container( padding: EdgeInsets.only(left: 20, right: 20), child: Column( children: [ Row( children: [ Container( child: SvgPicture.asset( 'images/svg/更新.svg', color: MyColors.c333333, ), margin: EdgeInsets.only( right: 12, top: 15, bottom: 15), ), Expanded( child: Text( '更新', style: TextStyle( color: MyColors.c333333, fontSize: 15), )), Container( child: Text( MyCookie().packageInfo.version, style: TextStyle( color: MyColors.c333333, fontSize: 15), ), margin: EdgeInsets.only(right: 10), ), SvgPicture.asset('images/svg/箭头.svg') ], ), Container( height: 1, color: MyColors.cEFEFEF, ) ], ), ), ), functionItem('images/svg/设置.svg', '设置', () { MyTools().toPage(context, SetPage(), (then) { queryPersonalInformation(); }); }), ], ) ], ), ), ), ); } functionItem(String svg, String title, onTap) { return GestureDetector( onTap: onTap, behavior: HitTestBehavior.translucent, child: Container( padding: EdgeInsets.only(left: 20, right: 20), child: Column( children: [ Row( children: [ Container( child: SvgPicture.asset( svg, color: MyColors.c333333, ), margin: EdgeInsets.only(right: 12, top: 15, bottom: 15), ), Expanded( child: Text( title, style: TextStyle(color: MyColors.c333333, fontSize: 15), )), SvgPicture.asset('images/svg/箭头.svg') ], ), Container( height: 1, color: MyColors.cEFEFEF, ) ], ), ), ); } 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'); } endRe(controller); }, (error) {}); } void onRefresh() { queryPersonalInformation(); } bool showRe = false; void checkIfThereIsAShop() { MyDio().query({ "key": "shop_user", "filters": { "conditions": [ "review_state==1", "owner_uid==${MyCookie().getUID()}", "private_shop==true", "recommender_uid!=0" ] }, "dims": shopUserDims, "paging": [1, 2000] }, (response, hasError) { if (!hasError) { MyShopBeanEntity entity = MyShopBeanEntity().fromJson(json.decode(response.data.toString())); if (entity.data.data == null || entity.data.data.isEmpty || entity.data.data.length == 0) { showRe = false; } else { showRe = true; } setState(() {}); } }, (error) {}); } }