409 lines
14 KiB
Dart
409 lines
14 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
|
|
import '../../bean/works_info_bean.dart';
|
|
import '../../common/EventBusUtil.dart';
|
|
import '../../common/app_util.dart';
|
|
import '../../common/func.dart';
|
|
import '../../dialog/influential_prompt_dialog.dart';
|
|
import '../../dialog/share_dialog.dart';
|
|
import '../../generated/l10n.dart';
|
|
import '../../network/NetworkConfig.dart';
|
|
import 'draw_details_model.dart';
|
|
import 'expert_user_details_page.dart';
|
|
|
|
///达人详情
|
|
class InfluentialDetailsPage2 extends StatefulWidget {
|
|
String drawId;
|
|
|
|
InfluentialDetailsPage2(this.drawId, {super.key});
|
|
|
|
@override
|
|
State<InfluentialDetailsPage2> createState() => _InfluentialDetailsPage2State();
|
|
}
|
|
|
|
class _InfluentialDetailsPage2State extends State<InfluentialDetailsPage2> {
|
|
StreamSubscription? subscription;
|
|
final DrawDetailsModel _viewModel = DrawDetailsModel();
|
|
|
|
/// 初始化控制器
|
|
late PageController pageController;
|
|
|
|
// List<WorksDetailBean> DetailList = [];
|
|
int currentPage = 0;
|
|
int initialPage = 0;
|
|
|
|
@override
|
|
void initState() {
|
|
// TODO: implement initState
|
|
super.initState();
|
|
subscription = _viewModel.streamController.stream.listen((newData) {
|
|
String code = newData['code'];
|
|
if (code.isNotEmpty) {
|
|
switch (code) {
|
|
case "getWorksDetailList":
|
|
// DetailList = newData['data'];
|
|
break;
|
|
case "userFollow":
|
|
EasyLoading.showToast(newData['message']);
|
|
break;
|
|
default:
|
|
// EasyLoading.showToast(newData['data']);
|
|
break;
|
|
}
|
|
setState(() {});
|
|
}
|
|
});
|
|
|
|
for (int i = 0; i < NetworkConfig.workList.length; i++) {
|
|
if ("${NetworkConfig.workList[i].Id}" == widget.drawId) {
|
|
initialPage = i;
|
|
}
|
|
}
|
|
|
|
//创建控制器的实例
|
|
pageController = PageController(
|
|
//用来配置PageView中默认显示的页面 从0开始
|
|
initialPage: initialPage,
|
|
//为true是保持加载的每个页面的状态
|
|
keepPage: true,
|
|
);
|
|
|
|
///PageView设置滑动监听
|
|
pageController.addListener(() {
|
|
//PageView滑动的距离
|
|
double offset = pageController.offset;
|
|
//当前显示的页面的索引
|
|
double? page = pageController.page;
|
|
print("pageView 滑动的距离 $offset 索引 $page");
|
|
|
|
if (pageController.position.pixels >= pageController.position.maxScrollExtent - 100) {
|
|
// 滑动到底部
|
|
// 执行相应的操作
|
|
|
|
}
|
|
});
|
|
|
|
// _viewModel.getWorksDetailList(widget.drawId);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
// TODO: implement dispose
|
|
subscription?.cancel();
|
|
pageController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final size = MediaQuery.of(context).size;
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
backgroundColor: Colors.black,
|
|
title: Text(S.of(context).details),
|
|
leading: IconButton(
|
|
icon: const Icon(Icons.arrow_back_ios_new),
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
centerTitle: true,
|
|
),
|
|
body: Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
Container(
|
|
color: Colors.black,
|
|
width: size.width,
|
|
height: size.height,
|
|
child: PageView.builder(
|
|
onPageChanged: (int index) {
|
|
currentPage = index;
|
|
},
|
|
itemCount: NetworkConfig.workList.length,
|
|
itemBuilder: (BuildContext context, int index) {
|
|
return _pageViewItem(context, NetworkConfig.workList[index]);
|
|
},
|
|
//页面控制器
|
|
controller: pageController,
|
|
scrollDirection: Axis.vertical,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
_pageViewItem(BuildContext context, WorksInfoBean data) {
|
|
final size = MediaQuery.of(context).size;
|
|
return Stack(
|
|
children: [
|
|
CachedNetworkImage(
|
|
width: size.width,
|
|
height: size.height,
|
|
imageUrl: data.TaskResult,
|
|
errorWidget: (context, url, error) => const Icon(Icons.error),
|
|
),
|
|
Positioned(
|
|
right: 10,
|
|
bottom: 31,
|
|
child: SizedBox(
|
|
width: 50,
|
|
child: Column(
|
|
children: [
|
|
Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
///头像
|
|
GestureDetector(
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => ExpertUserDetailsPage(
|
|
workUserId: "${data.UserId}",
|
|
worksID: '${data.Id}',
|
|
),
|
|
));
|
|
},
|
|
child: Container(
|
|
height: 55,
|
|
alignment: Alignment.topCenter,
|
|
child: ClipOval(
|
|
child: CachedNetworkImage(
|
|
width: 43,
|
|
height: 43,
|
|
imageUrl: data.UserIocn,
|
|
errorWidget: (context, url, error) => const Icon(Icons.error),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
|
|
///关注
|
|
Positioned(
|
|
bottom: 2,
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
if (!data.IsFollow) {
|
|
data.IsFollow = true;
|
|
_viewModel.userFollow("${data.UserId}");
|
|
}
|
|
},
|
|
child: !data.IsFollow
|
|
? const Image(
|
|
width: 20,
|
|
height: 20,
|
|
image: AssetImage('assets/images/ic_follow.png'),
|
|
)
|
|
: Container(),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
|
|
///点赞收藏
|
|
GestureDetector(
|
|
onTap: () {
|
|
if (NetworkConfig.userId == "${data.UserId}") {
|
|
return;
|
|
}
|
|
data.IsMyLike = !data.IsMyLike;
|
|
|
|
if (data.IsMyLike) {
|
|
data.LikeNum = data.LikeNum + 1;
|
|
} else {
|
|
data.LikeNum = data.LikeNum - 1;
|
|
if (data.LikeNum < 0) {
|
|
data.LikeNum = data.LikeNum = 0;
|
|
}
|
|
}
|
|
_viewModel.userDrawCollect(data.IsMyLike, "${data.Id}");
|
|
setState(() {});
|
|
},
|
|
child: Container(
|
|
margin: const EdgeInsets.only(top: 17),
|
|
child: Column(
|
|
children: [
|
|
Image(
|
|
width: 32,
|
|
height: 30,
|
|
image: data.IsMyLike ? const AssetImage('assets/images/ic_like_in.png') : const AssetImage('assets/images/ic_like.png'),
|
|
),
|
|
Text(
|
|
"${data.LikeNum}",
|
|
style: const TextStyle(color: Colors.white, fontSize: 12),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
|
|
///下载
|
|
GestureDetector(
|
|
onTap: () {
|
|
if (data.TaskResult != "") {
|
|
AppUtil.saveImage(data.TaskResult);
|
|
// if (artDetailBean != null) {
|
|
// SensorsAnalyticsFlutterPlugin.track(
|
|
// 'PaintingDownload', {'AuthorUserID': artDetailBean!.UserId!, 'PaintID': artDetailBean!.Id.toString()});
|
|
// }
|
|
}
|
|
},
|
|
child: Container(
|
|
margin: const EdgeInsets.only(top: 17),
|
|
child: Column(
|
|
children: [
|
|
const Image(
|
|
width: 32,
|
|
height: 30,
|
|
image: AssetImage('assets/images/ic_download.png'),
|
|
),
|
|
Text(
|
|
S.of(context).Download,
|
|
style: const TextStyle(color: Colors.white, fontSize: 10),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
|
|
///画同款
|
|
GestureDetector(
|
|
onTap: () {
|
|
NetworkConfig.prompt = data.Prompt;
|
|
NetworkConfig.templateId = data.TemplateId;
|
|
NetworkConfig.sizeTemplateId = data.SizeTemplateId;
|
|
NetworkConfig.followId = data.Id;
|
|
NetworkConfig.followUrl = data.TaskResult;
|
|
|
|
NetworkConfig.isImitate = true;
|
|
EventBusUtil.fire(TabBarJumpEvent(1));
|
|
EventBusUtil.fire(CopyDrawingEvent());
|
|
|
|
Navigator.of(context).popUntil(ModalRoute.withName('/HomePage'));
|
|
},
|
|
child: Container(
|
|
margin: const EdgeInsets.only(top: 17),
|
|
child: Column(
|
|
children: [
|
|
const Image(
|
|
width: 32,
|
|
height: 30,
|
|
image: AssetImage('assets/images/ic_same_style.png'),
|
|
),
|
|
Text(
|
|
S.of(context).copy_it,
|
|
style: const TextStyle(color: Colors.white, fontSize: 10),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
|
|
///分享
|
|
GestureDetector(
|
|
onTap: () {
|
|
if (data.TaskResult != "") {
|
|
// if (artDetailBean != null && artDetailBean!.UserNickName != null) {
|
|
FunctionUtil.popDialog(context, ShareDialog(data.TaskResult, data.UserNickName));
|
|
// } else {
|
|
// FunctionUtil.popDialog(context, ShareDialog(data.TaskResult!, NetworkConfig.userData!.NickName!));
|
|
// }
|
|
} else {
|
|
Fluttertoast.showToast(
|
|
msg: S.of(context).Please_wait,
|
|
toastLength: Toast.LENGTH_SHORT,
|
|
gravity: ToastGravity.CENTER,
|
|
timeInSecForIosWeb: 1,
|
|
backgroundColor: const Color(0x8B000000),
|
|
textColor: Colors.white,
|
|
fontSize: 16.0);
|
|
}
|
|
},
|
|
child: Container(
|
|
margin: const EdgeInsets.only(top: 17),
|
|
child: Column(
|
|
children: [
|
|
const Image(
|
|
width: 32,
|
|
height: 30,
|
|
image: AssetImage('assets/images/ic_share.png'),
|
|
),
|
|
Text(
|
|
S.of(context).Share,
|
|
style: TextStyle(color: Colors.white, fontSize: 10),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
|
|
///展开
|
|
Positioned(
|
|
left: 15,
|
|
bottom: 31,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
data.UserNickName,
|
|
style: const TextStyle(color: Colors.white),
|
|
),
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
Container(
|
|
margin: const EdgeInsets.only(top: 12),
|
|
width: 230,
|
|
child: Text(
|
|
data.Prompt,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: const TextStyle(color: Colors.white, fontSize: 13),
|
|
),
|
|
),
|
|
GestureDetector(
|
|
onTap: () {
|
|
FunctionUtil.bottomSheetDialog(
|
|
context,
|
|
InfluentialPromptDialog(
|
|
prompt: data.Prompt,
|
|
onTap: () {
|
|
NetworkConfig.prompt = data.Prompt;
|
|
NetworkConfig.templateId = data.TemplateId;
|
|
NetworkConfig.sizeTemplateId = data.SizeTemplateId;
|
|
NetworkConfig.followId = data.Id;
|
|
NetworkConfig.followUrl = "";
|
|
|
|
NetworkConfig.isImitate = true;
|
|
EventBusUtil.fire(TabBarJumpEvent(1));
|
|
EventBusUtil.fire(CopyDrawingEvent());
|
|
|
|
Navigator.of(context).popUntil(ModalRoute.withName('/HomePage'));
|
|
},
|
|
));
|
|
},
|
|
child: Text(
|
|
S.of(context).Expand,
|
|
style: const TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.w500),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
],
|
|
)),
|
|
],
|
|
);
|
|
}
|
|
}
|