421 lines
17 KiB
Dart
421 lines
17 KiB
Dart
|
||
import 'dart:async';
|
||
import 'dart:convert';
|
||
|
||
import 'package:aiplot/network/NetworkConfig.dart';
|
||
import 'package:cached_network_image/cached_network_image.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
||
|
||
import '../../bean/user_draw_bean.dart';
|
||
import '../../generated/l10n.dart';
|
||
import '../drawdetails/draw_details_page.dart';
|
||
import 'me_model.dart';
|
||
import 'screen_tips.dart';
|
||
|
||
///我的作品
|
||
class MyWorksPage extends StatefulWidget {
|
||
const MyWorksPage({Key? key}) : super(key: key);
|
||
|
||
@override
|
||
State<MyWorksPage> createState() => _MyWorksPageState();
|
||
}
|
||
|
||
class _MyWorksPageState extends State<MyWorksPage> {
|
||
StreamSubscription? subscription;
|
||
final MeModel _viewModel = MeModel();
|
||
List<UserDrawBean>? list;
|
||
bool isChecks = false; //是否多选状态
|
||
int isCheckNum = 0; //选中数量
|
||
int sortType = 0; //排序类型
|
||
List<String> drawIdList = []; //多选删除集合
|
||
|
||
@override
|
||
void initState() {
|
||
// TODO: implement initState
|
||
super.initState();
|
||
//网络请求回调
|
||
subscription = _viewModel.streamController.stream.listen((newData) {
|
||
String code = newData['code'];
|
||
if (code.isNotEmpty) {
|
||
EasyLoading.dismiss();
|
||
switch (code) {
|
||
case "getUserDrawList":
|
||
list = newData['data'];
|
||
for (var value in list!) {
|
||
value.IsCheck = false;
|
||
}
|
||
list!.sort((a, b) => b.FavoriteDateTime!.compareTo(a.FavoriteDateTime!));
|
||
break;
|
||
case "delMyDrawCollect": //删除
|
||
String message = newData['data'];
|
||
EasyLoading.showToast(message);
|
||
drawIdList = [];
|
||
sortType = 0;
|
||
isChecks = false;
|
||
_viewModel.getUserDrawList();
|
||
break;
|
||
}
|
||
}
|
||
setState(() {});
|
||
});
|
||
EasyLoading.show(status: 'loading...');
|
||
_viewModel.getUserDrawList();
|
||
}
|
||
|
||
@override
|
||
void dispose() {
|
||
// TODO: implement dispose
|
||
super.dispose();
|
||
subscription?.cancel();
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final size = MediaQuery.of(context).size;
|
||
return Scaffold(
|
||
backgroundColor: Colors.white,
|
||
body: Stack(
|
||
alignment: Alignment.center,
|
||
children: [
|
||
Column(
|
||
children: [
|
||
list != null && list!.isNotEmpty
|
||
? Container(
|
||
height: 20,
|
||
alignment: Alignment.centerLeft,
|
||
margin: EdgeInsets.only(top: 30),
|
||
child: Stack(
|
||
children: [
|
||
///作品数量
|
||
Positioned(
|
||
left: 15,
|
||
child: Text(
|
||
'${S.of(context).Number_works}:${list!.length}/${NetworkConfig.saveImageNumber}',
|
||
style: TextStyle(color: Colors.black, fontSize: 12),
|
||
),
|
||
),
|
||
|
||
///排序
|
||
!isChecks
|
||
? Positioned(
|
||
right: 15,
|
||
child: GestureDetector(
|
||
onTapDown: (details) {
|
||
//排序弹框
|
||
showDialog(
|
||
context: context,
|
||
builder: (BuildContext ctx) => ScreenTips(
|
||
index: sortType,
|
||
dx: details.globalPosition.dx,
|
||
dy: details.globalPosition.dy,
|
||
type: 0,
|
||
onTap: (index) {
|
||
sortType = index;
|
||
if (sortType == 0) {
|
||
list!.sort((a, b) => b.FavoriteDateTime!.compareTo(a.FavoriteDateTime!));
|
||
} else if (sortType == 1) {
|
||
list!.sort((a, b) => a.FavoriteDateTime!.compareTo(b.FavoriteDateTime!));
|
||
} else if (sortType == 2) {
|
||
list!.sort((a, b) => b.FavoriteDateTime!.compareTo(a.FavoriteDateTime!));
|
||
//根据优先级进行排序:降序
|
||
list!.sort((a, b) => b.CollectNumber!.compareTo(a.CollectNumber!));
|
||
} else if (sortType == 3) {
|
||
list!.sort((a, b) => b.FavoriteDateTime!.compareTo(a.FavoriteDateTime!));
|
||
//根据优先级进行排序:降序
|
||
list!.sort((a, b) => a.CollectNumber!.compareTo(b.CollectNumber!));
|
||
}
|
||
setState(() {});
|
||
},
|
||
));
|
||
},
|
||
child: Row(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: [
|
||
const Image(width: 13, height: 13, image: AssetImage('assets/images/ic_sort.png')),
|
||
Container(
|
||
margin: const EdgeInsets.only(left: 4),
|
||
child: Text(
|
||
S.of(context).Sort_by,
|
||
style: const TextStyle(color: Color(0xFF666666), fontSize: 12),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
)
|
||
: Container(),
|
||
|
||
///多选
|
||
!isChecks
|
||
? Positioned(
|
||
right: NetworkConfig.Language != "zh" ? 90 : 70,
|
||
child: GestureDetector(
|
||
onTap: () {
|
||
isChecks = true;
|
||
setState(() {});
|
||
},
|
||
child: Row(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: [
|
||
const Image(width: 13, height: 13, image: AssetImage('assets/images/ic_check.png')),
|
||
Container(
|
||
margin: const EdgeInsets.only(left: 4),
|
||
child: Text(
|
||
S.of(context).Selects,
|
||
style: const TextStyle(color: Color(0xFF666666), fontSize: 12),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
)
|
||
: Container(),
|
||
|
||
///取消
|
||
isChecks
|
||
? Positioned(
|
||
right: 15,
|
||
child: GestureDetector(
|
||
onTap: () {
|
||
isChecks = false;
|
||
for (var value in list!) {
|
||
value.IsCheck = false;
|
||
}
|
||
setState(() {});
|
||
},
|
||
child: Text(
|
||
S.of(context).Cancel,
|
||
style: const TextStyle(color: Color(0xFF666666), fontSize: 12),
|
||
),
|
||
))
|
||
: Container(),
|
||
],
|
||
),
|
||
)
|
||
: Container(),
|
||
|
||
///作品列表
|
||
list != null && list!.isNotEmpty
|
||
? Expanded(
|
||
child: Container(
|
||
margin: const EdgeInsets.only(left: 15, right: 15),
|
||
child: SingleChildScrollView(
|
||
child: MasonryGridView.count(
|
||
crossAxisCount: 2,
|
||
padding: const EdgeInsets.only(left: 0, right: 0, top: 10),
|
||
itemCount: list!.length,
|
||
itemBuilder: (BuildContext context, int index) {
|
||
return _item(list![index], index);
|
||
},
|
||
// 纵向元素间距
|
||
mainAxisSpacing: 10,
|
||
// 横向元素间距
|
||
crossAxisSpacing: 10,
|
||
physics: const NeverScrollableScrollPhysics(),
|
||
shrinkWrap: true,
|
||
),
|
||
),
|
||
),
|
||
)
|
||
: Expanded(
|
||
child: Container(
|
||
alignment: Alignment.center,
|
||
child: const Image(
|
||
width: 150,
|
||
image: AssetImage('assets/images/ic_no_content.png'),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
|
||
///批量删除
|
||
isChecks
|
||
? Positioned(
|
||
bottom: 0,
|
||
child: Container(
|
||
color: const Color(0x99000000),
|
||
width: size.width,
|
||
height: 50,
|
||
child: Stack(
|
||
alignment: Alignment.center,
|
||
children: [
|
||
Positioned(
|
||
left: 15,
|
||
child: GestureDetector(
|
||
onTap: () {
|
||
isChecks = false;
|
||
for (var value in list!) {
|
||
value.IsCheck = false;
|
||
isCheckNum = 0;
|
||
}
|
||
setState(() {});
|
||
},
|
||
child: Text(
|
||
S.of(context).Cancel,
|
||
style: const TextStyle(color: Colors.white, fontSize: 16),
|
||
),
|
||
),
|
||
),
|
||
|
||
///已选中
|
||
GestureDetector(
|
||
child: Text(
|
||
"${S.of(context).Selected} $isCheckNum/${list!.length}",
|
||
style: const TextStyle(color: Colors.white, fontSize: 16),
|
||
),
|
||
),
|
||
Positioned(
|
||
right: 15,
|
||
child: GestureDetector(
|
||
onTap: () {
|
||
if (drawIdList.isNotEmpty) {
|
||
EasyLoading.show(status: 'loading...');
|
||
|
||
String drawList = json.encode(drawIdList);
|
||
_viewModel.delMyDrawCollect(drawList);
|
||
} else {
|
||
EasyLoading.showToast(S.of(context).Please_select);
|
||
}
|
||
},
|
||
child: Text(
|
||
S.of(context).Delete,
|
||
style: const TextStyle(color: Colors.white, fontSize: 16),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
))
|
||
: Container(),
|
||
],
|
||
));
|
||
}
|
||
|
||
_item(UserDrawBean bean, int index) {
|
||
return GestureDetector(
|
||
onTap: () {
|
||
//选中判断
|
||
if (!isChecks) {
|
||
Navigator.push(
|
||
context,
|
||
MaterialPageRoute(
|
||
builder: (context) => DrawDetailsPage(
|
||
false,
|
||
taskId: bean.TaskId,
|
||
describeText: bean.Title,
|
||
drawId: bean.DrawId.toString(),
|
||
isMyWork: true,
|
||
status: bean.Status!,
|
||
))).then((value) => {_viewModel.getUserDrawList()});
|
||
} else {
|
||
setState(() {
|
||
_deleteList(bean.DrawId.toString());
|
||
bean.IsCheck = !bean.IsCheck!;
|
||
if (bean.IsCheck!) {
|
||
isCheckNum++;
|
||
} else {
|
||
isCheckNum--;
|
||
}
|
||
});
|
||
}
|
||
},
|
||
child: Stack(
|
||
children: [
|
||
Column(
|
||
children: [
|
||
ClipRRect(
|
||
borderRadius: BorderRadius.circular(7),
|
||
child: CachedNetworkImage(
|
||
imageUrl: bean.ImageUrl!,
|
||
errorWidget: (context, url, error) => Icon(Icons.error),
|
||
),
|
||
),
|
||
SizedBox(
|
||
height: 40,
|
||
width: double.infinity,
|
||
child: Stack(
|
||
alignment: Alignment.center,
|
||
children: [
|
||
Positioned(
|
||
left: 0,
|
||
child: SizedBox(
|
||
width: 100,
|
||
child: Text(
|
||
bean.Title!,
|
||
maxLines: 1,
|
||
overflow: TextOverflow.ellipsis,
|
||
style: TextStyle(color: Colors.black),
|
||
),
|
||
),
|
||
),
|
||
Positioned(
|
||
right: 10,
|
||
child: Row(
|
||
children: [
|
||
const Image(
|
||
width: 13,
|
||
height: 12,
|
||
image: AssetImage('assets/images/ic_collect.png'),
|
||
),
|
||
Container(
|
||
margin: const EdgeInsets.only(left: 5),
|
||
child: Text(
|
||
bean.CollectNumber.toString(),
|
||
style: const TextStyle(color: Colors.black, fontSize: 12),
|
||
),
|
||
)
|
||
],
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
],
|
||
),
|
||
|
||
///复选框
|
||
isChecks
|
||
? Positioned(
|
||
right: 5,
|
||
top: 5,
|
||
child: Container(
|
||
width: 20,
|
||
height: 20,
|
||
decoration: BoxDecoration(color: Colors.white, border: Border.all(color: const Color(0xFFBB72E0))),
|
||
child: Checkbox(
|
||
value: bean.IsCheck,
|
||
checkColor: const Color(0xFF8841FF),
|
||
fillColor: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
|
||
return Colors.white;
|
||
}),
|
||
onChanged: (value) {
|
||
setState(() {
|
||
_deleteList(bean.DrawId.toString());
|
||
if (value!) {
|
||
isCheckNum++;
|
||
} else {
|
||
isCheckNum--;
|
||
}
|
||
bean.IsCheck = value;
|
||
});
|
||
},
|
||
),
|
||
))
|
||
: Container()
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
_deleteList(String drawId) {
|
||
if (drawIdList.contains(drawId)) {
|
||
drawIdList.remove(drawId);
|
||
} else {
|
||
drawIdList.add(drawId);
|
||
}
|
||
}
|
||
}
|