484 lines
23 KiB
Dart
484 lines
23 KiB
Dart
import 'dart:async';
|
||
|
||
import 'package:aiplot/bean/user_info_bean.dart';
|
||
import 'package:aiplot/tools/me/my_collect_page.dart';
|
||
import 'package:aiplot/tools/me/my_works_page.dart';
|
||
import 'package:cached_network_image/cached_network_image.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||
import 'package:ironsource_mediation/ironsource_mediation.dart';
|
||
|
||
import '../../bean/equity_bean.dart';
|
||
import '../../common/EventBusUtil.dart';
|
||
import '../../common/TabUnderLine.dart';
|
||
import '../../common/func.dart';
|
||
import '../../dialog/invitation_code_dialog.dart';
|
||
import '../../dialog/obtaining_benefits_dialog.dart';
|
||
import '../../generated/l10n.dart';
|
||
import '../../network/NetworkConfig.dart';
|
||
import 'me_info_model.dart';
|
||
|
||
///我的
|
||
class MePage extends StatefulWidget {
|
||
const MePage({Key? key}) : super(key: key);
|
||
|
||
@override
|
||
State<MePage> createState() => _MePageState();
|
||
}
|
||
|
||
class _MePageState extends State<MePage> with SingleTickerProviderStateMixin {
|
||
StreamSubscription? subscription;
|
||
final MeInfoModel _viewModel = MeInfoModel();
|
||
|
||
TabController? _tabController;
|
||
PageController? _pageController;
|
||
List<StatefulWidget>? tabView; //包含内容必须和tab对应
|
||
final ScrollController _scrollController = ScrollController();
|
||
StreamSubscription<RefreshUserdata>? _refreshUserdata;
|
||
|
||
UserInfoBean? userInfoBean;
|
||
EquityBean? equityBean;
|
||
|
||
@override
|
||
void initState() {
|
||
// TODO: implement initState
|
||
super.initState();
|
||
|
||
//我的作品 收藏
|
||
tabView = [const MyWorksPage(), const MyCollectPage()];
|
||
_tabController = TabController(initialIndex: 0, length: 2, vsync: this);
|
||
_pageController = PageController();
|
||
|
||
///eventbus
|
||
_refreshUserdata = EventBusUtil.listen((event) {
|
||
getUserInfo();
|
||
});
|
||
|
||
//网络请求回调
|
||
subscription = _viewModel.streamController.stream.listen((newData) {
|
||
String code = newData['code'];
|
||
if (code.isNotEmpty) {
|
||
EasyLoading.dismiss();
|
||
switch (code) {
|
||
case "getUserData":
|
||
userInfoBean = newData['data'];
|
||
break;
|
||
case "getQuanYi":
|
||
equityBean = newData['data'];
|
||
break;
|
||
}
|
||
}
|
||
setState(() {});
|
||
});
|
||
getUserInfo();
|
||
}
|
||
|
||
//用户信息
|
||
getUserInfo() {
|
||
EasyLoading.show(status: 'loading...', maskType: EasyLoadingMaskType.black);
|
||
_viewModel.getUserData();
|
||
_viewModel.getQuanYi();
|
||
}
|
||
|
||
@override
|
||
void dispose() {
|
||
// TODO: implement dispose
|
||
_tabController?.dispose();
|
||
_pageController?.dispose();
|
||
_refreshUserdata?.cancel();
|
||
subscription?.cancel();
|
||
super.dispose();
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final size = MediaQuery.of(context).size;
|
||
final h270 = size.width / 1.333333333;
|
||
final t70 = size.width / 5.1428571428571;
|
||
final w60 = size.width / 6;
|
||
final l85 = size.width / 4.235294117647;
|
||
final t35 = size.width / 10.285714285714;
|
||
final h340 = size.width / 1.0588235294117;
|
||
final t40 = size.width / 9;
|
||
final w90 = size.width / 4;
|
||
final h45 = size.width / 8;
|
||
final w150 = size.width / 2.4;
|
||
final h140 = size.width / 2.5714285714285;
|
||
final h60 = size.width / 6;
|
||
final h80 = size.width / 4.5;
|
||
|
||
return Scaffold(
|
||
backgroundColor: Colors.white,
|
||
body: NestedScrollView(
|
||
controller: _scrollController,
|
||
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
|
||
return [
|
||
SliverOverlapAbsorber(
|
||
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
|
||
sliver: SliverAppBar(
|
||
backgroundColor: Colors.white,
|
||
elevation: 0,
|
||
centerTitle: true,
|
||
actions: [
|
||
///邀请码
|
||
Container(
|
||
alignment: Alignment.center,
|
||
child: GestureDetector(
|
||
onTap: () {
|
||
FunctionUtil.popDialog(context, InvitationCodeDialog());
|
||
},
|
||
child: Container(
|
||
padding: const EdgeInsets.all(6),
|
||
decoration: const BoxDecoration(
|
||
gradient: LinearGradient(
|
||
begin: Alignment.centerLeft, //渐变开始于上面的中间开始
|
||
end: Alignment.centerRight, //渐变结束于下面的中间
|
||
colors: [Color(0xFF808EEF), Color(0xFFBE6FDF)]),
|
||
borderRadius: BorderRadius.all(Radius.circular(20))),
|
||
child: Text(
|
||
S.of(context).Invitation_code,
|
||
style: TextStyle(color: Colors.white, fontSize: 10),
|
||
)),
|
||
),
|
||
),
|
||
|
||
///设置
|
||
Container(
|
||
padding: EdgeInsets.zero,
|
||
child: IconButton(
|
||
icon: const Image(
|
||
width: 20,
|
||
height: 20,
|
||
image: AssetImage('assets/images/ic_setting.png'),
|
||
),
|
||
onPressed: () {
|
||
Navigator.pushNamed(context, "/SettingPage");
|
||
}),
|
||
),
|
||
],
|
||
expandedHeight: NetworkConfig.appConfigBean != null && !NetworkConfig.appConfigBean!.IsCheckRemark! ? h340 : h140,
|
||
flexibleSpace: FlexibleSpaceBar(
|
||
background: Column(
|
||
children: [
|
||
///用户信息
|
||
Container(
|
||
margin: EdgeInsets.only(top: w60),
|
||
width: double.infinity,
|
||
height: t70,
|
||
child: Stack(
|
||
children: [
|
||
//头像
|
||
Positioned(
|
||
left: 15,
|
||
child: userInfoBean != null && userInfoBean!.UserIconUrl != null
|
||
? CachedNetworkImage(
|
||
fit: BoxFit.fitHeight,
|
||
width: w60,
|
||
height: w60,
|
||
imageUrl: userInfoBean!.UserIconUrl!,
|
||
errorWidget: (context, url, error) => Image(
|
||
fit: BoxFit.fitWidth,
|
||
width: w60,
|
||
height: w60,
|
||
image: const AssetImage('assets/images/head.png'),
|
||
),
|
||
)
|
||
: Container(),
|
||
),
|
||
//昵称
|
||
userInfoBean != null
|
||
? Positioned(
|
||
left: l85,
|
||
top: 5,
|
||
child: SizedBox(
|
||
width: w150,
|
||
child: Text(
|
||
userInfoBean!.NickName!,
|
||
overflow: TextOverflow.ellipsis,
|
||
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w500),
|
||
),
|
||
),
|
||
)
|
||
: Container(height: 1),
|
||
|
||
///点数
|
||
Positioned(
|
||
left: l85,
|
||
top: t35,
|
||
child: Row(
|
||
children: [
|
||
Text(
|
||
S.of(context).Painting_point,
|
||
style: const TextStyle(color: Color(0xFF999999), fontSize: 12),
|
||
),
|
||
Container(
|
||
margin: const EdgeInsets.only(left: 5),
|
||
child: const Image(
|
||
width: 16,
|
||
height: 16,
|
||
image: AssetImage('assets/images/ic_count.png'),
|
||
),
|
||
),
|
||
Container(
|
||
margin: const EdgeInsets.only(left: 5),
|
||
child: Text(
|
||
NetworkConfig.allCurrency,
|
||
style: const TextStyle(color: Color(0xFF8841FF)),
|
||
),
|
||
),
|
||
Container(
|
||
margin: const EdgeInsets.only(left: 17),
|
||
child: Text(
|
||
S.of(context).Collected,
|
||
style: const TextStyle(color: Color(0xFF999999), fontSize: 12),
|
||
),
|
||
),
|
||
userInfoBean != null && userInfoBean!.CollectNumber != null
|
||
? Container(
|
||
margin: const EdgeInsets.only(left: 10),
|
||
child: Text(
|
||
userInfoBean!.CollectNumber.toString(),
|
||
style: const TextStyle(color: Color(0xFF999999), fontSize: 12),
|
||
),
|
||
)
|
||
: Container(),
|
||
],
|
||
),
|
||
),
|
||
|
||
///审核 获取权益
|
||
NetworkConfig.appConfigBean?.IsShowUserPageEquityBtn != null && NetworkConfig.appConfigBean!.IsShowUserPageEquityBtn!
|
||
? Positioned(
|
||
top: 10,
|
||
right: 16,
|
||
child: GestureDetector(
|
||
onTap: () {
|
||
FunctionUtil.popDialog(
|
||
context,
|
||
ObtainingBenefitsDialog(
|
||
onTap: (index) {
|
||
switch (index) {
|
||
case 0: //看广告
|
||
if (NetworkConfig.isAdAvailable) {
|
||
IronSource.showRewardedVideo();
|
||
} else {
|
||
EasyLoading.showToast(S.of(context).no_advertisements);
|
||
}
|
||
break;
|
||
|
||
case 1: //购买
|
||
break;
|
||
}
|
||
},
|
||
equityBean: equityBean,
|
||
));
|
||
},
|
||
child: Container(
|
||
width: w90,
|
||
height: t40,
|
||
alignment: Alignment.center,
|
||
decoration: const BoxDecoration(
|
||
borderRadius: BorderRadius.all(Radius.circular(20)),
|
||
gradient: LinearGradient(
|
||
begin: Alignment.centerLeft, //渐变开始于上面的中间开始
|
||
end: Alignment.centerRight, //渐变结束于下面的中间
|
||
colors: [Color(0xFF843FFF), Color(0xFFEB76FF)])),
|
||
child: Text(
|
||
S.of(context).obtaining_benefits,
|
||
style: TextStyle(color: Colors.white, fontSize: 14),
|
||
),
|
||
),
|
||
))
|
||
: Container()
|
||
],
|
||
),
|
||
),
|
||
|
||
///商城
|
||
NetworkConfig.appConfigBean != null &&
|
||
!NetworkConfig.appConfigBean!.IsCheckRemark! &&
|
||
NetworkConfig.appConfigBean?.MallInletImage != null
|
||
? Align(
|
||
child: GestureDetector(
|
||
onTap: () {
|
||
Navigator.pushNamed(context, "/ShopPage");
|
||
},
|
||
child: Container(
|
||
margin: const EdgeInsets.only(left: 15, right: 15),
|
||
child: CachedNetworkImage(height: h80, imageUrl: NetworkConfig.appConfigBean!.MallInletImage!),
|
||
),
|
||
),
|
||
)
|
||
: Container(),
|
||
|
||
NetworkConfig.appConfigBean != null &&
|
||
!NetworkConfig.appConfigBean!.IsCheckRemark! &&
|
||
userInfoBean != null &&
|
||
userInfoBean!.UserAdLog != null &&
|
||
userInfoBean!.UserAdLog!.UsedRewardCount != null &&
|
||
userInfoBean!.UserAdLog!.TotalRewardCount != null
|
||
? Container(
|
||
height: h140,
|
||
decoration: const BoxDecoration(
|
||
color: Color(0xFFF8F8FF),
|
||
borderRadius: BorderRadius.all(Radius.circular(7)),
|
||
),
|
||
margin: const EdgeInsets.only(left: 15, right: 15, top: 5),
|
||
child: Column(
|
||
children: [
|
||
///看广告
|
||
GestureDetector(
|
||
onTap: () {
|
||
if (userInfoBean!.UserAdLog!.UsedRewardCount != userInfoBean!.UserAdLog!.TotalRewardCount) {
|
||
if (NetworkConfig.isAdAvailable) {
|
||
IronSource.showRewardedVideo();
|
||
} else {
|
||
EasyLoading.showToast(S.of(context).no_advertisements);
|
||
}
|
||
} else {
|
||
EasyLoading.showToast(S.of(context).received_all);
|
||
}
|
||
},
|
||
child: Container(
|
||
height: h60,
|
||
child: Stack(
|
||
children: [
|
||
Positioned(
|
||
top: 20,
|
||
left: 10,
|
||
child: Text(
|
||
"${S.of(context).Watch_the} (${userInfoBean!.UserAdLog!.UsedRewardCount}/${userInfoBean!.UserAdLog!.TotalRewardCount})",
|
||
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
|
||
),
|
||
),
|
||
Positioned(
|
||
top: t40,
|
||
left: 10,
|
||
child: Text(
|
||
S.of(context).Earn_paint,
|
||
style: TextStyle(fontSize: 12, color: Color(0xFF999999)),
|
||
),
|
||
),
|
||
Positioned(
|
||
right: 7,
|
||
top: 18,
|
||
child: Stack(
|
||
alignment: Alignment.center,
|
||
children: [
|
||
Image(width: w90, height: h45, image: AssetImage('assets/images/view_ad.png')),
|
||
Positioned(
|
||
top: 10,
|
||
child: Text(
|
||
S.of(context).Watch,
|
||
style: TextStyle(fontSize: 14, color: Colors.white),
|
||
))
|
||
],
|
||
))
|
||
],
|
||
),
|
||
),
|
||
),
|
||
|
||
Container(
|
||
height: 1,
|
||
width: size.width,
|
||
color: Color(0xFFEAEAEA),
|
||
margin: EdgeInsets.only(top: 10, left: 15, right: 15),
|
||
),
|
||
|
||
///去创作
|
||
GestureDetector(
|
||
onTap: () {
|
||
EventBusUtil.fire(TabBarJumpEvent(1));
|
||
},
|
||
child: SizedBox(
|
||
height: h60,
|
||
child: Stack(
|
||
children: [
|
||
Positioned(
|
||
top: 20,
|
||
left: 10,
|
||
child: Text(
|
||
S.of(context).Upload_artwork_gallery,
|
||
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
|
||
),
|
||
),
|
||
Positioned(
|
||
top: t40,
|
||
left: 10,
|
||
child: Text(
|
||
"${S.of(context).Obtained_after_review} ${NetworkConfig.appConfigBean!.SharingRewards} ${S.of(context).Painting_points}",
|
||
style: const TextStyle(fontSize: 12, color: Color(0xFF999999)),
|
||
),
|
||
),
|
||
Positioned(
|
||
right: 7,
|
||
top: 18,
|
||
child: Stack(
|
||
alignment: Alignment.center,
|
||
children: [
|
||
Image(width: w90, height: h45, image: const AssetImage('assets/images/view_ad.png')),
|
||
Positioned(
|
||
top: 10,
|
||
child: Text(
|
||
S.of(context).To_create,
|
||
style: const TextStyle(fontSize: 14, color: Colors.white),
|
||
))
|
||
],
|
||
))
|
||
],
|
||
),
|
||
),
|
||
)
|
||
],
|
||
),
|
||
)
|
||
: Container(),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
)
|
||
];
|
||
},
|
||
body: Column(
|
||
children: [
|
||
///作品/收藏
|
||
Container(
|
||
height: 30,
|
||
width: size.width,
|
||
margin: EdgeInsets.only(top: NetworkConfig.statusHeight + 0.1),
|
||
child: TabBar(
|
||
tabs: <Widget>[
|
||
Text(S.of(context).My_Works),
|
||
Text(S.of(context).Collection),
|
||
],
|
||
controller: _tabController,
|
||
indicator: const RoundUnderlineTabIndicator(borderSide: BorderSide(width: 2, color: Color(0xFF8841FF))),
|
||
labelColor: const Color(0xFF8841FF),
|
||
//设置选中时的字体颜色,tabs里面的字体样式优先级最高
|
||
labelStyle: const TextStyle(fontSize: 16, fontWeight: FontWeight.w700),
|
||
unselectedLabelColor: const Color(0xFF666666),
|
||
//设置未选中时的字体颜色,tabs里面的字体样式优先级最高
|
||
unselectedLabelStyle: const TextStyle(fontSize: 16, fontWeight: FontWeight.w700),
|
||
onTap: (int index) {
|
||
_pageController!.jumpToPage(index);
|
||
},
|
||
),
|
||
),
|
||
Expanded(
|
||
child: PageView(
|
||
controller: _pageController,
|
||
children: tabView!,
|
||
onPageChanged: (index) {
|
||
_tabController!.animateTo(index);
|
||
},
|
||
),
|
||
)
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|