AI_Drawing/lib/tools/me/my_collect_page.dart
2024-06-03 15:30:15 +08:00

234 lines
8.7 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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: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 MyCollectPage extends StatefulWidget {
const MyCollectPage({Key? key}) : super(key: key);
@override
State<MyCollectPage> createState() => _MyCollectPageState();
}
class _MyCollectPageState extends State<MyCollectPage> {
StreamSubscription? subscription;
final MeModel _viewModel = MeModel();
List<UserDrawBean> list = [];
int sortType = 0; //排序类型
@override
void initState() {
// TODO: implement initState
super.initState();
//网络请求回调
subscription = _viewModel.streamController.stream.listen((newData) {
String code = newData['code'];
if (code.isNotEmpty) {
EasyLoading.dismiss();
if (code == "getMyFavoriteList") {
list = newData['data'];
for (var value in list) {
value.IsCheck = false;
}
list.sort((a, b) => b.FavoriteDateTime!.compareTo(a.FavoriteDateTime!));
}
}
setState(() {});
});
EasyLoading.show(status: 'loading...');
_viewModel.getMyFavoriteList();
}
@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(
children: [
Column(
children: [
list.isNotEmpty
? Container(
height: 20,
alignment: Alignment.centerLeft,
margin: const EdgeInsets.only(top: 30),
child: Stack(
children: [
///收藏数量
Positioned(
left: 15,
child: Text(
'${S.of(context).Number_collections}${list.length}',
style: const TextStyle(color: Colors.black, fontSize: 12),
),
),
///排序
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: 1,
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!));
}
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(),
///收藏列表
list != null && list.isNotEmpty
? Expanded(
child: Container(
margin: const EdgeInsets.only(left: 15, right: 15),
child: SingleChildScrollView(
child: MasonryGridView.count(
padding: const EdgeInsets.only(left: 0, right: 0, top: 10),
crossAxisCount: 2,
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_collect.png'),
),
),
),
],
),
],
));
}
_item(UserDrawBean bean, int index) {
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DrawDetailsPage(
false,
drawId: bean.DrawId.toString(),
isMyWork: false,
status: 3,
)));
},
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: const TextStyle(color: Colors.black),
),
),
),
Positioned(
right: 10,
child: Row(
children: [
const Image(
width: 13,
height: 12,
image: AssetImage('assets/images/ic_collect_s.png'),
),
Container(
margin: const EdgeInsets.only(left: 5),
child: Text(
bean.CollectNumber.toString(),
style: const TextStyle(color: Color(0xFFBB72E0), fontSize: 12),
),
)
],
),
),
],
),
),
],
),
],
),
);
}
}