You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
4.1 KiB

4 years ago
import 'package:flutter/material.dart';
import 'package:flustars/flustars.dart';
import 'package:get/get.dart';
import 'package:velocity_x/velocity_x.dart';
import 'package:aku_community/const/resource.dart';
import 'package:aku_community/constants/api.dart';
import 'package:aku_community/model/common/img_model.dart';
import 'package:aku_community/model/community/board_model.dart';
import 'package:aku_community/ui/community/notice/notice_detail_page.dart';
import 'package:aku_community/utils/headers.dart';
import 'package:aku_community/widget/picker/bee_image_preview.dart';
class NoticeCard extends StatelessWidget {
final BoardItemModel model;
3 years ago
final BoardItemModel? preModel;
const NoticeCard({
3 years ago
Key? key,
required this.model,
required this.preModel,
}) : super(key: key);
bool get sameDay =>
3 years ago
model.releaseDate!.year == (preModel?.releaseDate?.year ?? 0) &&
model.releaseDate!.month == (preModel?.releaseDate?.month ?? 0) &&
model.releaseDate!.day == (preModel?.releaseDate?.day ?? 0);
bool get isYesterday {
DateTime now = DateTime.now();
DateTime yestoday = DateTime(now.year, now.month, now.day - 1);
3 years ago
return yestoday.year == model.releaseDate!.year &&
yestoday.month == model.releaseDate!.month &&
yestoday.day == model.releaseDate!.day;
}
bool get isFirst => preModel == null;
bool get notSameYear =>
3 years ago
model.releaseDate!.year != (preModel?.releaseDate?.year ?? 0);
Widget title() {
3 years ago
if (DateUtil.isToday(model.releaseDate!.millisecond))
return '今天'.text.size(52.sp).bold.make();
if (isYesterday)
return '昨天'.text.size(52.sp).bold.make();
else
return Row(
mainAxisSize: MainAxisSize.min,
children: [
3 years ago
model.releaseDate!.day.toString().text.size(52.sp).bold.make(),
'${model.releaseDate!.month}'.text.size(36.sp).make(),
],
);
}
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
3 years ago
(notSameYear && model.releaseDate!.year != DateTime.now().year)
? '${model.releaseDate!.year}'
.text
.bold
.size(52.sp)
.make()
.paddingOnly(left: 32.w, top: isFirst ? 0 : 64.w, bottom: 32.w)
: SizedBox(),
MaterialButton(
onPressed: () {
Get.to(() => NoticeDetailPage(id: model.id));
},
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 200.w,
padding: EdgeInsets.only(left: 32.w),
alignment: Alignment.topLeft,
child: sameDay ? SizedBox() : title(),
),
3 years ago
model.imgUrls!.length == 0
? SizedBox(height: 152.w)
: GestureDetector(
onTap: () {
BeeImagePreview.toPath(
path: ImgModel.first(model.imgUrls),
tag: ImgModel.first(model.imgUrls),
);
},
child: Container(
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
color: Colors.black12,
borderRadius: BorderRadius.circular(8.w),
),
child: Hero(
tag: ImgModel.first(model.imgUrls),
child: FadeInImage.assetNetwork(
placeholder: R.ASSETS_IMAGES_PLACEHOLDER_WEBP,
image: API.image(ImgModel.first(model.imgUrls)),
width: 152.w,
height: 152.w,
fit: BoxFit.cover,
),
),
),
),
10.wb,
3 years ago
model.title!.text.make().expand(),
],
),
),
],
);
}
}