import 'dart:convert'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/main.dart'; import 'package:huixiang/mine/mine_view/mine_order.dart'; import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/rank.dart'; import 'package:huixiang/retrofit/data/social_info.dart'; import 'package:huixiang/retrofit/data/user_info.dart'; import 'package:huixiang/retrofit/retrofit_api.dart'; import 'package:huixiang/utils/event_type.dart'; import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/view_widget/classic_header.dart'; import 'package:huixiang/view_widget/login_tips_dialog.dart'; import 'package:huixiang/view_widget/mine_vip_view.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:dio/dio.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'mine_view/mine_item.dart'; import 'mine_view/mine_view.dart'; import 'mine_view/wallet_coupon_view.dart'; class MinePage extends StatefulWidget { @override State createState() { return _MinePage(); } } class _MinePage extends State with AutomaticKeepAliveClientMixin { ApiService apiService; UserInfo userInfo; List ranks = []; SocialInfo infoNumber; final RefreshController _refreshController = RefreshController(); _toUserInfo() async { SharedPreferences shared = await SharedPreferences.getInstance(); if (shared.getString("token") == null || shared.getString("token") == "") { Navigator.of(context) .pushNamed('/router/login_page', arguments: {"login": "login"}); return; } // await Navigator.of(context).pushNamed('/router/user_info_page'); await Navigator.of(context).pushNamed('/router/personal_page',arguments:{"memberId":"0",}); setState(() {}); } @override void dispose() { super.dispose(); if (_refreshController != null) _refreshController.dispose(); } @override void initState() { super.initState(); querySocialInfo(); eventBus.on().listen((event) { print("EventType: ${event.type}"); if (event.type < 3) { if (mounted) setState(() {}); } if (event.type == 3) { if (mounted) setState(() {}); } }); } queryUserInfo() async { // EasyLoading.show(status: S.of(context).zhengzaijiazai); final SharedPreferences value = await SharedPreferences.getInstance(); if (value.containsKey('user') && value.getString('user') != null && value.getString('user') != "") { userInfo = UserInfo.fromJson(jsonDecode(value.getString('user'))); } apiService = ApiService( Dio(), context: context, token: value.getString('token'), showLoading: false, ); BaseData> rankData = await apiService.rankList().catchError((onError) { _refreshController.refreshFailed(); }); if (rankData != null && rankData.isSuccess) { ranks.clear(); ranks.addAll(rankData.data); } BaseData baseDate = await apiService.queryInfo().catchError((onError) { _refreshController.refreshFailed(); }); if (baseDate != null && baseDate.isSuccess) { userInfo = baseDate.data; SharedPreferences.getInstance().then( (value) => { value.setString('user', jsonEncode(baseDate.data)), }, ); _refreshController.refreshCompleted(); } else { _refreshController.refreshFailed(); } // EasyLoading.dismiss(); } _onRefresh() { // queryUserInfo(); querySocialInfo(); } ///个人社交信息(粉丝/关注数量/成就数量) querySocialInfo() async { SharedPreferences value = await SharedPreferences.getInstance(); apiService = ApiService( Dio(), context: context, token: value.getString("token"), showLoading: false, ); BaseData baseData = await apiService.socialInfo().catchError((onError) { _refreshController.refreshFailed(); }); if (baseData != null && baseData.isSuccess) { infoNumber = baseData.data; _refreshController.refreshCompleted(); } EasyLoading.dismiss(); } @override Widget build(BuildContext context) { super.build(context); return Scaffold( backgroundColor: Color(0xFFF7F7F7), body: Container( padding: EdgeInsets.only(bottom: 76.h), // margin: EdgeInsets.only(top: 40.h), child: SmartRefresher( controller: _refreshController, enablePullDown: true, enablePullUp: false, header: MyHeader(), physics: BouncingScrollPhysics(), onRefresh: () { setState(() { _onRefresh(); }); }, child: SingleChildScrollView( child: Container( child: Stack( alignment: Alignment.centerRight, children: [ FutureBuilder( future: queryUserInfo(), builder: (context, snapshot) { return Column( children: [ Container( decoration: BoxDecoration( gradient: LinearGradient( begin: Alignment.bottomLeft, end: Alignment.topRight, colors: [ Color(0xFFE5F7FF), Color(0xFFE8F5E9), ], stops: [0.1, 0.8], ), ), child: Column( children: [ ///我的 用户信息 MineView( userInfo, () { _toUserInfo(); }, () { toIntegralPage(); }, ), ///我的 VIP等级信息 MineVipView( tag: "vip", ranks: ranks, userInfo: userInfo, rank: double.tryParse( userInfo?.expendAmount ?? "0") .toInt(), rankMax: userInfo?.memberRankVo?.nextOrigin ?? 0, createTime: userInfo?.createTime ?? "", ), ], ), ), ///关注度/粉丝/发布 attention(), /// 钱包或领券中心 WalletCoupon(), MineOrderView(), ///我的 下面item MineItem(), ], ); }, ), // buildNotice(), ], ), ), ), ), ), ); } ///横向的提示 Widget buildNotice() { return Container( margin: EdgeInsets.only(top: 130.h), child: Stack( children: [ Container( height: 33.h, margin: EdgeInsets.only(left: 12.w), padding: EdgeInsets.only(left: 16.w), decoration: BoxDecoration( color: Colors.white, boxShadow: [ BoxShadow( color: Colors.black.withAlpha(25), offset: Offset(0, 1), blurRadius: 12, spreadRadius: 0, ) ], borderRadius: BorderRadius.only( topLeft: Radius.circular(2), bottomLeft: Radius.circular(2), ), ), child: Row( mainAxisAlignment: MainAxisAlignment.spaceAround, crossAxisAlignment: CrossAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: [ Text( S.of(context).ninyouyigedingdanyaolingqu, style: TextStyle( fontWeight: MyFontWeight.bold, fontSize: 12.sp, color: Colors.black, ), ), Icon( Icons.keyboard_arrow_right, color: Colors.black, size: 16, ) ], ), ), Container( margin: EdgeInsets.only(top: 5.h, bottom: 4.h), padding: EdgeInsets.all(2), decoration: BoxDecoration( color: Colors.white, boxShadow: [ BoxShadow( color: Colors.black.withAlpha(25), offset: Offset(0, 1), blurRadius: 12, spreadRadius: 0, ) ], shape: BoxShape.circle, ), child: Image.asset( "assets/image/icon_mine_motorcycle.png", width: 20.w, height: 20.h, fit: BoxFit.contain, ), ), ], ), ); } ///关注度/粉丝/成就数量 Widget attention() { return Container( margin: EdgeInsets.only(left: 16, top: 10, right: 16), // padding: EdgeInsets.only(top: 16,bottom: 16), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(8), boxShadow: [ BoxShadow( color: Colors.black.withAlpha(12), offset: Offset(0, 3), blurRadius: 14, spreadRadius: 0, ), ], ), child: Row( mainAxisAlignment: MainAxisAlignment.spaceAround, crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded( child: GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { Navigator.of(context).pushNamed( '/router/communityFollow', arguments: {}, ); }, child: Container( color: Colors.transparent, padding: EdgeInsets.all(16), child: Column( children: [ Text( infoNumber != null ? infoNumber.follow.toString() : "0", style: TextStyle( color: Color(0xFF000000), fontSize: 15.sp, fontWeight: MyFontWeight.medium, ), ), SizedBox( height: 4, ), Text( S.of(context).guanzhu, style: TextStyle( color: Color(0xFF000000), fontSize: 14.sp, fontWeight: MyFontWeight.regular, ), ), ], )), ), ), Expanded( child: GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { Navigator.of(context).pushNamed( '/router/communityFollow', arguments: {}, ); }, child: Container( color: Colors.transparent, padding: EdgeInsets.all(16), child: Column( children: [ Text( infoNumber != null ? infoNumber.fans.toString() : "0", style: TextStyle( color: Color(0xFF000000), fontSize: 15.sp, fontWeight: MyFontWeight.medium, ), ), SizedBox( height: 4, ), Text( S.of(context).fensi, style: TextStyle( color: Color(0xFF000000), fontSize: 14.sp, fontWeight: MyFontWeight.regular, ), ), ], )), ), ), Expanded( child: GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { Navigator.of(context).pushNamed( '/router/mine_attainment_page', arguments: {"userInfo": userInfo}, ); }, child: Container( color: Colors.transparent, padding: EdgeInsets.all(16), child: Column( children: [ Text( infoNumber != null ? infoNumber.achievementNumber.toString() : "0", style: TextStyle( color: Color(0xFF000000), fontSize: 15.sp, fontWeight: MyFontWeight.medium, ), ), SizedBox( height: 4, ), Text( "成就", style: TextStyle( color: Color(0xFF000000), fontSize: 14.sp, fontWeight: MyFontWeight.regular, ), ), ], ), )), ) ], ), ); } toIntegralPage() async { SharedPreferences shared = await SharedPreferences.getInstance(); if (shared.getString("token") == null || shared.getString("token") == "") { LoginTipsDialog().show(context); return; } await Navigator.of(context).pushNamed('/router/integral_page'); setState(() {}); } @override bool get wantKeepAlive => true; }