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.

314 lines
10 KiB

4 years ago
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
4 years ago
import 'package:flutter_screenutil/flutter_screenutil.dart';
4 years ago
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/article.dart';
3 years ago
import 'package:huixiang/utils/flutter_utils.dart';
import 'package:huixiang/utils/font_weight.dart';
4 years ago
import 'package:huixiang/view_widget/custom_image.dart';
4 years ago
import 'package:huixiang/view_widget/icon_text.dart';
3 years ago
import 'package:huixiang/view_widget/round_button.dart';
4 years ago
3 years ago
class HotArticleItem extends StatefulWidget {
4 years ago
final Article article;
3 years ago
final bool isHot;
4 years ago
3 years ago
HotArticleItem({this.article, this.isHot});
4 years ago
3 years ago
@override
State<StatefulWidget> createState() {
return _HotArticleItem();
}
}
class _HotArticleItem extends State<HotArticleItem> {
4 years ago
@override
Widget build(BuildContext context) {
4 years ago
return GestureDetector(
4 years ago
onTap: () {
3 years ago
click();
4 years ago
},
4 years ago
child: hotItem(context),
4 years ago
);
4 years ago
}
3 years ago
click() async {
await Navigator.of(context).pushNamed('/router/store_detail_page',
arguments: {"articleId": widget.article.id});
widget.article.viewers = (widget.article.viewers + 1);
setState(() {});
}
4 years ago
Widget hotItem(BuildContext context) {
4 years ago
return Container(
3 years ago
padding: EdgeInsets.all((widget.isHot == null || !widget.isHot) ? 8 : 0),
4 years ago
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
3 years ago
color: Colors.green.withAlpha(12),
4 years ago
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
)
],
borderRadius: BorderRadius.circular(4),
),
3 years ago
child: (widget.isHot == null || !widget.isHot)
3 years ago
? Row(
4 years ago
children: [
3 years ago
Visibility(
3 years ago
visible: widget.article != null &&
widget.article.coverImg != null &&
widget.article.coverImg != "",
child: Stack(
alignment: Alignment.center,
children: [
MImage(
widget.article != null ? widget.article.coverImg : "",
fit: BoxFit.cover,
radius: BorderRadius.circular(2),
aspectRatio: 1,
errorSrc: "assets/image/default_1.png",
fadeSrc: "assets/image/default_1.png",
),
Visibility(
visible: (widget.article != null &&
widget.article.coverImg != "" &&
widget.article.coverImg.endsWith(".mp4")),
child: Icon(
Icons.play_circle_outline,
size: 24,
color: Colors.white,
),
),
],
),
),
Expanded(
child: Container(
margin: EdgeInsets.only(left: 8.w),
child: articleText(context),
3 years ago
),
4 years ago
),
4 years ago
],
3 years ago
)
3 years ago
: Column(
3 years ago
children: articleContent(context),
),
3 years ago
);
}
Widget articleText(context) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
3 years ago
(widget.isHot == null || !widget.isHot)
3 years ago
? Text(
3 years ago
widget.article != null ? widget.article.mainTitle : "",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 14.sp,
color: Colors.black,
),
)
3 years ago
: Row(
3 years ago
children: [
RoundButton(
text: "HOT",
textColor: Colors.white,
backgroup: Color(0xFFFF441A),
radius: 2,
fontSize: 10.sp,
fontWeight: MyFontWeight.medium,
padding: EdgeInsets.all(2),
),
SizedBox(
width: 6.w,
),
Expanded(
child: Text(
widget.article != null
? widget.article.mainTitle
: "",
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 14.sp,
color: Colors.black,
),
),
flex: 1,
),
],
4 years ago
),
3 years ago
SizedBox(
height: 4.h,
),
Text(
3 years ago
widget.article != null ? (widget.article.viceTitle ?? "") : "",
3 years ago
maxLines: AppUtils.textScale(context) > 1.05 ? 1 : 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.w400,
color: Color(0xFF353535),
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
3 years ago
children: [
Text(
3 years ago
S.of(context).zuozhe((widget.article != null &&
widget.article.author != null)
? widget.article.author.name
: ""),
3 years ago
style: TextStyle(
fontSize: 10.sp,
fontWeight: FontWeight.w400,
color: Color(0xFFB2B2B2),
),
4 years ago
),
3 years ago
SizedBox(
3 years ago
width: 12.w,
3 years ago
),
3 years ago
Container(
alignment: Alignment.topRight,
child: Row(
children: [
Image.asset(
"assets/image/icon_likes.png",
width: 16.w,
height: 16.h,
),
Text(
3 years ago
(widget.article != null)
? "${widget.article.likes}"
: "",
3 years ago
style: TextStyle(
fontSize: 10.sp,
color: Color(0xFFB2B2B2),
),
3 years ago
),
],
4 years ago
),
3 years ago
),
3 years ago
SizedBox(
width: 12.w,
),
3 years ago
Container(
alignment: Alignment.topRight,
child: Row(
children: [
Image.asset(
"assets/image/icon_views.png",
width: 16.w,
height: 16.h,
),
Text(
3 years ago
(widget.article != null)
? "${widget.article.viewers}"
: "",
3 years ago
style: TextStyle(
fontSize: 10.sp,
color: Color(0xFFB2B2B2),
),
),
],
4 years ago
),
3 years ago
),
],
),
flex: 1,
),
IconText(
3 years ago
widget.article != null
? (widget.article.createTime.split(" ")[0])
: "",
3 years ago
textStyle: TextStyle(
fontSize: 10.sp,
fontWeight: FontWeight.w400,
color: Color(0xFFB2B2B2),
),
leftIcon: Icons.access_time_rounded,
iconSize: 10,
iconColor: Color(0xFFB2B2B2),
4 years ago
),
3 years ago
],
),
],
);
}
List<Widget> articleContent(context) {
return [
Expanded(
child: Visibility(
3 years ago
visible: widget.article != null &&
widget.article.coverImg != null &&
widget.article.coverImg != "",
3 years ago
child: Stack(
alignment: Alignment.center,
children: [
Positioned(
child: MImage(
3 years ago
widget.article != null ? widget.article.coverImg : "",
3 years ago
fit: BoxFit.cover,
radius: BorderRadius.circular(4),
width: MediaQuery.of(context).size.width - 32.w,
height: 150.h,
),
top: 0,
bottom: 0,
right: 0,
left: 0,
),
Positioned(
child: Visibility(
3 years ago
visible: (widget.article != null &&
widget.article.coverImg != "" &&
widget.article.coverImg.endsWith(".mp4")),
3 years ago
child: Center(
child: Icon(
Icons.play_circle_outline,
size: 24,
color: Colors.white,
),
),
),
top: 0,
bottom: 0,
right: 0,
left: 0,
),
],
4 years ago
),
3 years ago
),
flex: 150,
4 years ago
),
3 years ago
Expanded(
flex: 97,
child: Container(
child: articleText(context),
padding: EdgeInsets.all(8),
),
),
];
4 years ago
}
}