659 lines
28 KiB
Dart
659 lines
28 KiB
Dart
|
||
import 'dart:async';
|
||
import 'dart:convert';
|
||
|
||
import 'package:aiplot/common/EventBusUtil.dart';
|
||
import 'package:aiplot/dialog/delete_img.dart';
|
||
import 'package:aiplot/network/NetworkConfig.dart';
|
||
import 'package:aiplot/tools/drawdetails/draw_details_model.dart';
|
||
import 'package:aiplot/tools/drawdetails/picture_details_page.dart';
|
||
import 'package:cached_network_image/cached_network_image.dart';
|
||
import 'package:expandable_text/expandable_text.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter/services.dart';
|
||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||
import 'package:fluttertoast/fluttertoast.dart';
|
||
import 'package:sensors_analytics_flutter_plugin/sensors_analytics_flutter_plugin.dart';
|
||
|
||
import '../../bean/art_detail_bean.dart';
|
||
import '../../bean/text_to_image_bean.dart';
|
||
import '../../common/app_util.dart';
|
||
import '../../common/func.dart';
|
||
import '../../dialog/share_dialog.dart';
|
||
import '../../generated/l10n.dart';
|
||
|
||
///绘制详情页
|
||
class DrawDetailsPage extends StatefulWidget {
|
||
String? taskId;
|
||
String? drawId;
|
||
String? describeText = ""; //描述文字
|
||
bool isCreate = false; //是否是新生成作品
|
||
bool isMyWork; //是否是我的作品
|
||
bool isCollect = false; //是否已收藏
|
||
int status; //作品状态
|
||
|
||
DrawDetailsPage(this.isCreate, {Key? key, this.taskId, this.drawId, this.describeText, this.isMyWork = false, this.status = 3}) : super(key: key);
|
||
|
||
@override
|
||
State<DrawDetailsPage> createState() => _DrawDetailsPageState();
|
||
}
|
||
|
||
class _DrawDetailsPageState extends State<DrawDetailsPage> {
|
||
StreamSubscription? subscription;
|
||
final DrawDetailsModel _viewModel = DrawDetailsModel();
|
||
Timer? timer;
|
||
double pace = 0.0; //进度条
|
||
ArtDetailBean? artDetailBean;
|
||
TextToImageBean? textToImageBean;
|
||
bool isShare = false; //是否分享画廊
|
||
String imageUrl = ""; //展示的图片
|
||
String resolutionRatio = "512*512"; //分辨率
|
||
int drawState = 0; //审核状态 0 未审核,1审核中
|
||
|
||
@override
|
||
void initState() {
|
||
// TODO: implement initState
|
||
super.initState();
|
||
|
||
NetworkConfig.isImitate = false;
|
||
|
||
//网络请求回调
|
||
subscription = _viewModel.streamController.stream.listen((newData) {
|
||
String code = newData['code'];
|
||
if (code.isNotEmpty) {
|
||
EasyLoading.dismiss();
|
||
switch (code) {
|
||
case "getProgress": //进度
|
||
textToImageBean = newData['data'];
|
||
pace = textToImageBean!.TaskPercent! * 0.01;
|
||
imageUrl = textToImageBean!.TaskResult!;
|
||
widget.drawId = textToImageBean!.SeqId.toString();
|
||
if (textToImageBean!.TaskResult != "") {
|
||
timer?.cancel();
|
||
}
|
||
break;
|
||
case "getArtDetail": //详情
|
||
artDetailBean = newData['data'];
|
||
widget.drawId = artDetailBean!.Id.toString();
|
||
widget.describeText = artDetailBean!.Prompt;
|
||
widget.isCollect = artDetailBean!.IsMyCollect!;
|
||
imageUrl = artDetailBean!.TaskResult!;
|
||
isShare = artDetailBean!.IsUserDrawGallery!;
|
||
drawState = artDetailBean!.DrawState!;
|
||
|
||
if (NetworkConfig.userId == artDetailBean!.UserId.toString()) {
|
||
widget.isMyWork = true;
|
||
} else {
|
||
widget.isMyWork = false;
|
||
}
|
||
|
||
NetworkConfig.prompt = artDetailBean!.Prompt!;
|
||
NetworkConfig.templateId = artDetailBean!.TemplateId!;
|
||
NetworkConfig.sizeTemplateId = artDetailBean!.SizeTemplateId!;
|
||
NetworkConfig.followId = artDetailBean!.Id!;
|
||
|
||
switch (artDetailBean!.SizeTemplateId) {
|
||
case 0:
|
||
resolutionRatio = "512*512";
|
||
break;
|
||
case 1:
|
||
resolutionRatio = "512*704";
|
||
break;
|
||
case 2:
|
||
resolutionRatio = "704*512";
|
||
break;
|
||
case 3:
|
||
resolutionRatio = "512*910";
|
||
break;
|
||
case 4:
|
||
resolutionRatio = "910*512";
|
||
break;
|
||
}
|
||
break;
|
||
case "delMyDrawCollect": //删除
|
||
String message = newData['data'];
|
||
EasyLoading.showToast(message);
|
||
Navigator.pop(context);
|
||
break;
|
||
case "userDrawGallery": //上传画廊
|
||
String message = newData['data'];
|
||
EasyLoading.showToast(message);
|
||
break;
|
||
default:
|
||
String message = newData['data'];
|
||
EasyLoading.showToast(message);
|
||
break;
|
||
}
|
||
}
|
||
setState(() {});
|
||
});
|
||
|
||
if (widget.isCreate) {
|
||
getProgress();
|
||
} else {
|
||
if (widget.status != 3) {
|
||
getProgress();
|
||
} else {
|
||
getArtDetail();
|
||
}
|
||
}
|
||
}
|
||
|
||
//加载进度
|
||
Future<void> getProgress() async {
|
||
EasyLoading.show(status: 'loading...');
|
||
NetworkConfig.prompt = widget.describeText!;
|
||
timer = Timer.periodic(const Duration(seconds: 2), (timer) {
|
||
_viewModel.getProgress(widget.taskId!);
|
||
});
|
||
}
|
||
|
||
//获取图片详情
|
||
Future<void> getArtDetail() async {
|
||
EasyLoading.show(status: 'loading...');
|
||
_viewModel.getArtDetail(widget.drawId!);
|
||
}
|
||
|
||
@override
|
||
void dispose() {
|
||
// TODO: implement dispose
|
||
subscription?.cancel();
|
||
timer?.cancel();
|
||
super.dispose();
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final size = MediaQuery.of(context).size;
|
||
final h332 = size.width / 1.0843373493975; //332
|
||
final t110 = size.width / 3.2727272727272;
|
||
final w23 = size.width / 15.652173913043;
|
||
final w200 = size.width / 1.8;
|
||
final w50 = size.width / 7.2;
|
||
final w66 = size.width / 5.45454545454;
|
||
final h32 = size.width / 11.25;
|
||
final w107 = size.width / 3.3644859813084;
|
||
final h70 = size.width / 5.1428571428571;
|
||
final t25 = size.width / 14.4;
|
||
final w39 = size.width / 9.2307692307692;
|
||
return Scaffold(
|
||
backgroundColor: Colors.white,
|
||
appBar: AppBar(
|
||
backgroundColor: Colors.white,
|
||
elevation: 1,
|
||
title: Row(
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: [
|
||
Container(
|
||
margin: EdgeInsets.only(right: 10),
|
||
child: Image(
|
||
width: w23,
|
||
height: w23,
|
||
image: AssetImage('assets/images/ic_title.png'),
|
||
),
|
||
),
|
||
Text(
|
||
S.of(context).details,
|
||
style: TextStyle(color: Colors.black, fontSize: 20),
|
||
),
|
||
],
|
||
),
|
||
leading: IconButton(
|
||
icon: ImageIcon(AssetImage('assets/images/ic_return.png')),
|
||
color: Colors.black,
|
||
onPressed: () {
|
||
Navigator.pop(context);
|
||
}),
|
||
centerTitle: true,
|
||
),
|
||
body: Stack(
|
||
children: [
|
||
SingleChildScrollView(
|
||
child: Column(
|
||
children: [
|
||
Container(
|
||
height: h332,
|
||
child: Stack(
|
||
alignment: Alignment.center,
|
||
children: [
|
||
const Image(fit: BoxFit.fill, image: AssetImage('assets/images/ic_bg.png')),
|
||
//进度条
|
||
widget.status != 3
|
||
? textToImageBean != null && textToImageBean!.TaskPercent != null && textToImageBean!.TaskPercent != 0
|
||
? SizedBox(
|
||
width: w200,
|
||
height: w200,
|
||
child: imageUrl == ""
|
||
? CircularProgressIndicator(
|
||
value: pace ?? 0.0,
|
||
backgroundColor: Colors.grey,
|
||
valueColor: AlwaysStoppedAnimation(Colors.white),
|
||
)
|
||
: Container(),
|
||
)
|
||
: Container()
|
||
: Container(),
|
||
widget.status != 3
|
||
? textToImageBean != null && textToImageBean!.TaskPercent != null && textToImageBean!.TaskPercent != 0
|
||
? Text(
|
||
"${S.of(context).Current_progress}:${(pace * 100).toInt()}%",
|
||
style: TextStyle(color: Colors.white),
|
||
)
|
||
: Container()
|
||
: Container(),
|
||
|
||
///加载动画
|
||
Positioned(
|
||
top: t110,
|
||
child: Image(
|
||
width: w50,
|
||
height: w50,
|
||
image: AssetImage('assets/images/ic_loading.webp'),
|
||
),
|
||
),
|
||
|
||
///排队中
|
||
textToImageBean != null && textToImageBean!.TaskPercent != null && textToImageBean!.TaskPercent == 0
|
||
? Positioned(
|
||
child: Text(
|
||
S.of(context).Waiting_in,
|
||
style: const TextStyle(color: Colors.white),
|
||
))
|
||
: Container(),
|
||
|
||
///生成完成展示的图片
|
||
imageUrl != ""
|
||
? GestureDetector(
|
||
onTap: () {
|
||
Navigator.push(
|
||
context,
|
||
MaterialPageRoute(
|
||
builder: (context) => PictureDetailsPage(imageUrl),
|
||
));
|
||
},
|
||
child: CachedNetworkImage(imageUrl: imageUrl),
|
||
)
|
||
: Container()
|
||
],
|
||
),
|
||
),
|
||
|
||
///图片描述
|
||
GestureDetector(
|
||
onTap: () {
|
||
EasyLoading.showToast(S.of(context).Already_copied);
|
||
Clipboard.setData(ClipboardData(text: widget.describeText));
|
||
},
|
||
child: widget.describeText != null
|
||
? Container(
|
||
margin: EdgeInsets.only(top: 14, left: 15, right: 15),
|
||
alignment: Alignment.center,
|
||
child: ExpandableText(
|
||
widget.describeText!,
|
||
expandText: S.of(context).Expand,
|
||
collapseText: S.of(context).Close,
|
||
maxLines: 3,
|
||
linkColor: Colors.blue,
|
||
),
|
||
)
|
||
: Container(),
|
||
),
|
||
Container(
|
||
margin: EdgeInsets.only(top: w23, left: 15, right: 15),
|
||
child: Row(
|
||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
///删除-收藏
|
||
GestureDetector(
|
||
onTap: () {
|
||
if (widget.isMyWork) {
|
||
FunctionUtil.popDialog(context, DeleteImg(
|
||
onTap: (index) {
|
||
switch (index) {
|
||
case 1:
|
||
List<String> list = [widget.drawId!];
|
||
String drawList = json.encode(list);
|
||
_viewModel.delMyDrawCollect(drawList);
|
||
break;
|
||
}
|
||
},
|
||
));
|
||
} else {
|
||
widget.isCollect = !widget.isCollect;
|
||
setState(() {});
|
||
_viewModel.userDrawCollect(widget.isCollect, widget.drawId!);
|
||
}
|
||
},
|
||
child: !widget.isMyWork
|
||
? widget.isCreate
|
||
? Container(
|
||
width: w66,
|
||
height: h32,
|
||
alignment: Alignment.center,
|
||
decoration: BoxDecoration(color: Color(0xFFEAEAEA), borderRadius: BorderRadius.all(Radius.circular(5))),
|
||
child: Text(
|
||
S.of(context).Delete,
|
||
style: TextStyle(color: Color(0xFF666666), fontSize: 13),
|
||
),
|
||
)
|
||
: Container(
|
||
width: w66,
|
||
height: h32,
|
||
alignment: Alignment.center,
|
||
decoration: BoxDecoration(
|
||
color: widget.isCollect ? Color(0xFFBA71E0) : Color(0xFFEAEAEA),
|
||
borderRadius: BorderRadius.all(Radius.circular(5))),
|
||
child: Text(
|
||
widget.isCollect ? S.of(context).Favorite : S.of(context).collect,
|
||
style: TextStyle(color: widget.isCollect ? Colors.white : Color(0xFF666666), fontSize: 13),
|
||
),
|
||
)
|
||
: Container(
|
||
width: w66,
|
||
height: h32,
|
||
alignment: Alignment.center,
|
||
decoration: BoxDecoration(color: Color(0xFFEAEAEA), borderRadius: BorderRadius.all(Radius.circular(5))),
|
||
child: Text(
|
||
S.of(context).Delete,
|
||
style: TextStyle(color: Color(0xFF666666), fontSize: 13),
|
||
),
|
||
),
|
||
),
|
||
|
||
///下载
|
||
GestureDetector(
|
||
onTap: () {
|
||
if (imageUrl != "") {
|
||
AppUtil.saveImage(imageUrl);
|
||
if (artDetailBean != null) {
|
||
SensorsAnalyticsFlutterPlugin.track(
|
||
'PaintingDownload', {'AuthorUserID': artDetailBean!.UserId!, 'PaintID': artDetailBean!.Id.toString()});
|
||
}
|
||
}
|
||
},
|
||
child: Container(
|
||
width: w66,
|
||
height: h32,
|
||
alignment: Alignment.center,
|
||
decoration: BoxDecoration(color: Color(0xFFEAEAEA), borderRadius: BorderRadius.all(Radius.circular(5))),
|
||
child: Text(
|
||
S.of(context).Download,
|
||
style: TextStyle(color: Color(0xFF666666), fontSize: 13),
|
||
),
|
||
),
|
||
),
|
||
|
||
///分享
|
||
GestureDetector(
|
||
onTap: () {
|
||
if (imageUrl != "") {
|
||
if (artDetailBean != null && artDetailBean!.UserNickName != null) {
|
||
FunctionUtil.popDialog(context, ShareDialog(imageUrl, artDetailBean!.UserNickName!));
|
||
} else {
|
||
FunctionUtil.popDialog(context, ShareDialog(imageUrl, 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(
|
||
width: w66,
|
||
height: h32,
|
||
alignment: Alignment.center,
|
||
decoration: BoxDecoration(color: Color(0xFFEAEAEA), borderRadius: BorderRadius.all(Radius.circular(5))),
|
||
child: Text(
|
||
S.of(context).Share,
|
||
style: TextStyle(color: Color(0xFF666666), fontSize: 13),
|
||
),
|
||
),
|
||
),
|
||
|
||
///重新生成 再画一张
|
||
GestureDetector(
|
||
onTap: () {
|
||
if (widget.isCreate) {
|
||
Navigator.pop(context);
|
||
} else {
|
||
NetworkConfig.isImitate = true;
|
||
EventBusUtil.fire(TabBarJumpEvent(1));
|
||
EventBusUtil.fire(CopyDrawingEvent());
|
||
Navigator.pop(context);
|
||
}
|
||
},
|
||
child: Container(
|
||
width: w107,
|
||
height: h32,
|
||
alignment: Alignment.center,
|
||
decoration: const BoxDecoration(
|
||
borderRadius: BorderRadius.all(Radius.circular(5)),
|
||
gradient: LinearGradient(
|
||
begin: Alignment.centerLeft, //渐变开始于上面的中间开始
|
||
end: Alignment.centerRight, //渐变结束于下面的中间
|
||
colors: [Color(0xFF808EEF), Color(0xFFBE6FDF)]),
|
||
),
|
||
child: Text(
|
||
widget.isCreate || widget.isMyWork ? S.of(context).Draw_another_picture : S.of(context).Draw_the_same,
|
||
style: TextStyle(color: Colors.white, fontSize: NetworkConfig.Language != "zh" ? 14 : 12),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
Container(
|
||
height: 1,
|
||
margin: EdgeInsets.only(top: 22),
|
||
color: Color(0xFFEAEAEA),
|
||
),
|
||
|
||
///上传画廊
|
||
widget.isMyWork || widget.isCreate
|
||
? SizedBox(
|
||
height: h70,
|
||
width: size.width,
|
||
child: Stack(
|
||
children: [
|
||
Positioned(
|
||
top: 14,
|
||
left: 15,
|
||
child: Row(
|
||
crossAxisAlignment: CrossAxisAlignment.end,
|
||
children: [
|
||
Text(
|
||
S.of(context).share_to_gallery,
|
||
style: const TextStyle(color: Colors.black, fontSize: 16),
|
||
),
|
||
drawState == 1
|
||
? Container(
|
||
padding: const EdgeInsets.only(left: 3, right: 3),
|
||
margin: const EdgeInsets.only(left: 7),
|
||
decoration: const BoxDecoration(
|
||
color: Color(0xFFF2F2F2),
|
||
borderRadius: BorderRadius.all(Radius.circular(2)),
|
||
),
|
||
child: Text(
|
||
S.of(context).In_review,
|
||
style: const TextStyle(color: Color(0xFF999999), fontSize: 10),
|
||
),
|
||
)
|
||
: drawState == 2
|
||
? Container(
|
||
padding: const EdgeInsets.only(left: 3, right: 3),
|
||
margin: const EdgeInsets.only(left: 7),
|
||
decoration: const BoxDecoration(
|
||
color: Color(0xFFF2F2F2),
|
||
borderRadius: BorderRadius.all(Radius.circular(2)),
|
||
),
|
||
child: Text(
|
||
S.of(context).uploaded,
|
||
style: const TextStyle(color: Color(0xFF999999), fontSize: 10),
|
||
),
|
||
)
|
||
: Container(),
|
||
],
|
||
),
|
||
),
|
||
Positioned(
|
||
right: 15,
|
||
top: t25,
|
||
child: GestureDetector(
|
||
onTap: () {
|
||
isShare = !isShare;
|
||
if (isShare) {
|
||
drawState = 1;
|
||
} else {
|
||
drawState = 0;
|
||
}
|
||
setState(() {});
|
||
_viewModel.userDrawGallery(isShare, widget.drawId!);
|
||
},
|
||
child: Image(
|
||
width: w39,
|
||
height: 18,
|
||
image: isShare ? const AssetImage('assets/images/ic_open.png') : const AssetImage('assets/images/ic_close.png'),
|
||
),
|
||
),
|
||
),
|
||
Positioned(
|
||
top: w39,
|
||
left: 15,
|
||
child: Text(
|
||
"${S.of(context).Obtained_after_review} ${NetworkConfig.appConfigBean!.SharingRewards!} ${S.of(context).Painting_points}",
|
||
style: const TextStyle(color: Color(0xFF8741FF), fontSize: 13),
|
||
),
|
||
),
|
||
Positioned(
|
||
bottom: 0,
|
||
child: Container(
|
||
height: 1,
|
||
width: size.width,
|
||
color: const Color(0xFFEAEAEA),
|
||
),
|
||
)
|
||
],
|
||
),
|
||
)
|
||
: Container(),
|
||
widget.isCreate
|
||
? Container(
|
||
alignment: Alignment.centerLeft,
|
||
margin: const EdgeInsets.all(15),
|
||
child: Text(
|
||
S.of(context).Check_in,
|
||
style: const TextStyle(color: Color(0xFF999999)),
|
||
),
|
||
)
|
||
: Container(),
|
||
|
||
///生成时间
|
||
!widget.isCreate
|
||
? Container(
|
||
margin: const EdgeInsets.only(left: 15, right: 15, top: 20),
|
||
child: Row(
|
||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
Text(
|
||
S.of(context).Generate_time,
|
||
style: const TextStyle(
|
||
color: Color(0xFF999999),
|
||
),
|
||
),
|
||
Text(
|
||
artDetailBean != null && artDetailBean!.CreateTime != null && artDetailBean!.CreateTime != ""
|
||
? artDetailBean!.CreateTime!.toString()
|
||
: "",
|
||
style: const TextStyle(color: Color(0xFF999999)),
|
||
),
|
||
],
|
||
),
|
||
)
|
||
: Container(),
|
||
|
||
///分辨率
|
||
!widget.isCreate
|
||
? Container(
|
||
margin: const EdgeInsets.only(left: 15, right: 15),
|
||
child: Row(
|
||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
Text(
|
||
S.of(context).Resolution,
|
||
style: const TextStyle(
|
||
color: Color(0xFF999999),
|
||
),
|
||
),
|
||
Text(
|
||
resolutionRatio,
|
||
style: const TextStyle(color: Color(0xFF999999)),
|
||
),
|
||
],
|
||
),
|
||
)
|
||
: Container(),
|
||
Container(
|
||
height: 1,
|
||
margin: const EdgeInsets.only(top: 22),
|
||
color: const Color(0xFFEAEAEA),
|
||
),
|
||
|
||
!widget.isMyWork
|
||
? Container(
|
||
alignment: Alignment.centerLeft,
|
||
margin: EdgeInsets.only(left: 16),
|
||
child: Text(
|
||
S.of(context).Author,
|
||
style: TextStyle(fontSize: 16),
|
||
),
|
||
)
|
||
: Container(),
|
||
|
||
!widget.isMyWork
|
||
? Container(
|
||
margin: EdgeInsets.only(left: 16, top: 7),
|
||
child: Row(
|
||
children: [
|
||
artDetailBean != null && artDetailBean!.UserIocn != null
|
||
? CachedNetworkImage(
|
||
fit: BoxFit.fitHeight,
|
||
width: 28,
|
||
height: 28,
|
||
imageUrl: artDetailBean!.UserIocn!,
|
||
errorWidget: (context, url, error) => const Image(
|
||
fit: BoxFit.fitWidth,
|
||
width: 28,
|
||
height: 28,
|
||
image: AssetImage('assets/images/head.png'),
|
||
),
|
||
)
|
||
: Container(),
|
||
artDetailBean != null && artDetailBean!.UserNickName != null
|
||
? Container(
|
||
margin: const EdgeInsets.only(left: 11),
|
||
child: Text(
|
||
artDetailBean!.UserNickName!,
|
||
maxLines: 1,
|
||
overflow: TextOverflow.ellipsis,
|
||
style: const TextStyle(color: Colors.black, fontSize: 13),
|
||
),
|
||
)
|
||
: Container(),
|
||
],
|
||
),
|
||
)
|
||
: Container(),
|
||
],
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|