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.
345 lines
13 KiB
345 lines
13 KiB
3 years ago
|
import 'package:dio/dio.dart';
|
||
|
import 'package:flutter/cupertino.dart';
|
||
|
import 'package:flutter/material.dart';
|
||
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||
|
import 'package:huixiang/retrofit/data/article.dart';
|
||
|
import 'package:huixiang/retrofit/data/base_data.dart';
|
||
|
import 'package:huixiang/retrofit/data/headlines_list.dart';
|
||
|
import 'package:huixiang/retrofit/data/headlines_list_details.dart';
|
||
|
import 'package:huixiang/retrofit/retrofit_api.dart';
|
||
|
import 'package:huixiang/utils/font_weight.dart';
|
||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||
|
import 'package:huixiang/view_widget/custom_image.dart';
|
||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||
|
|
||
|
class HeadlinesColumnDetails extends StatefulWidget {
|
||
|
final Map<String, dynamic> arguments;
|
||
|
|
||
|
HeadlinesColumnDetails({this.arguments});
|
||
|
|
||
|
@override
|
||
|
State<StatefulWidget> createState() {
|
||
|
return _HeadlinesColumnDetails();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class _HeadlinesColumnDetails extends State<HeadlinesColumnDetails>
|
||
|
with WidgetsBindingObserver {
|
||
|
ApiService apiService;
|
||
|
List<Article> articles;
|
||
|
HeadlinesListDetails headlinesListDetails;
|
||
|
List<HeadlinesList> headlines = [];
|
||
|
|
||
|
@override
|
||
|
void initState() {
|
||
|
super.initState();
|
||
|
articles = widget.arguments["articles"];
|
||
|
WidgetsBinding.instance.addObserver(this);
|
||
|
queryHeadlinesDetails(widget.arguments["id"]);
|
||
|
queryHeadlinesList(widget.arguments["id"]);
|
||
|
}
|
||
|
|
||
|
///文章合集详情
|
||
|
queryHeadlinesDetails(id) async {
|
||
|
if (apiService == null) {
|
||
|
SharedPreferences value = await SharedPreferences.getInstance();
|
||
|
apiService = ApiService(
|
||
|
Dio(),
|
||
|
context: context,
|
||
|
token: value.getString("token"),
|
||
|
);
|
||
|
}
|
||
|
BaseData<HeadlinesListDetails> baseData =
|
||
|
await apiService.headlinesDetails(id).catchError((error) {});
|
||
|
if (baseData != null && baseData.isSuccess) {
|
||
|
setState(() {
|
||
|
headlinesListDetails = baseData.data;
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
///文章合集列表
|
||
|
queryHeadlinesList(id) async {
|
||
|
if (apiService == null) {
|
||
|
SharedPreferences value = await SharedPreferences.getInstance();
|
||
|
apiService = ApiService(
|
||
|
Dio(),
|
||
|
context: context,
|
||
|
token: value.getString("token"),
|
||
|
);
|
||
|
}
|
||
|
BaseData<List<HeadlinesList>> baseData = await apiService.headlinesList().catchError((onError) {});
|
||
|
if (baseData != null && baseData.isSuccess) {
|
||
|
setState(() {
|
||
|
headlines.clear();
|
||
|
headlines.addAll(baseData.data);
|
||
|
headlines.forEach((element) {
|
||
|
// collectCourse(element.id);
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
EasyLoading.dismiss();
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Scaffold(
|
||
|
body: Container(
|
||
|
child: Column(
|
||
|
children: [
|
||
|
Expanded(
|
||
|
child: SingleChildScrollView(
|
||
|
physics: BouncingScrollPhysics(),
|
||
|
child: Column(
|
||
|
children: [
|
||
|
Stack(
|
||
|
alignment: Alignment.bottomCenter,
|
||
|
children: [
|
||
|
Stack(
|
||
|
children: [
|
||
|
Positioned(child:
|
||
|
MImage(
|
||
|
headlinesListDetails?.coverImg ?? "",
|
||
|
width:double.infinity,
|
||
|
height: 260.h,
|
||
|
fit: BoxFit.cover,
|
||
|
errorSrc: "assets/image/default_1.png",
|
||
|
fadeSrc: "assets/image/default_1.png",
|
||
|
),
|
||
|
),
|
||
|
Container(
|
||
|
margin: EdgeInsets.only(
|
||
|
top: 50.h, left: 16.w, right: 16.w),
|
||
|
decoration: BoxDecoration(
|
||
|
color: Colors.transparent,
|
||
|
),
|
||
|
child: Column(
|
||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||
|
children: [
|
||
|
GestureDetector(
|
||
|
child: Image.asset(
|
||
|
"assets/image/integral_return.png",
|
||
|
width: 24,
|
||
|
height: 24,
|
||
|
),
|
||
|
onTap: () {
|
||
|
Navigator.of(context).pop();
|
||
|
},
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
Container(
|
||
|
child: Column(
|
||
|
children: [
|
||
|
Padding(padding:EdgeInsets.only(left: 16),
|
||
|
child:Row(
|
||
|
children: [
|
||
|
Container(
|
||
|
margin: EdgeInsets.only(right:4),
|
||
|
padding:EdgeInsets.only(left:2,right:2),
|
||
|
height:20.h,
|
||
|
alignment: Alignment.center,
|
||
|
decoration: BoxDecoration(
|
||
|
borderRadius:
|
||
|
BorderRadius.circular(2),
|
||
|
color: Color(0xFF32A060),
|
||
|
),
|
||
|
child: Text(
|
||
|
"专栏",
|
||
|
style: TextStyle(
|
||
|
fontSize: 12.sp,
|
||
|
fontWeight: MyFontWeight.medium,
|
||
|
color: Colors.white,
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
SizedBox(
|
||
|
width: 6.w,
|
||
|
),
|
||
|
Expanded(
|
||
|
child: Text(
|
||
|
headlinesListDetails?.name ?? "",
|
||
|
overflow: TextOverflow.ellipsis,
|
||
|
maxLines: 2,
|
||
|
style: TextStyle(
|
||
|
fontSize: 18.sp,
|
||
|
fontWeight: MyFontWeight.semi_bold,
|
||
|
color: Colors.white,
|
||
|
),
|
||
|
),
|
||
|
flex: 1,
|
||
|
)
|
||
|
],
|
||
|
),),
|
||
|
Container(
|
||
|
width: double.infinity,
|
||
|
decoration: BoxDecoration(
|
||
|
border: Border.all(
|
||
|
width: 0,
|
||
|
color: Colors.white,
|
||
|
),
|
||
|
color: Colors.white,
|
||
|
borderRadius: new BorderRadius.only(
|
||
|
topLeft: Radius.circular(8.0),
|
||
|
topRight: Radius.circular(8.0),
|
||
|
),
|
||
|
),
|
||
|
margin: EdgeInsets.only(top: 16),
|
||
|
// padding: EdgeInsets.all(16),
|
||
|
child: Column(
|
||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||
|
children: [
|
||
|
Padding(padding:EdgeInsets.all(16),
|
||
|
child: Text(
|
||
|
"简介:${headlinesListDetails?.introduce ?? ""}",
|
||
|
overflow: TextOverflow.ellipsis,
|
||
|
maxLines: 2,
|
||
|
style: TextStyle(
|
||
|
fontSize: 14.sp,
|
||
|
fontWeight: MyFontWeight.medium ,
|
||
|
color: Colors.black,
|
||
|
),
|
||
|
)),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
ListView.builder(
|
||
|
padding: EdgeInsets.zero,
|
||
|
itemCount:headlines == null ? 0 : headlines.length,
|
||
|
scrollDirection: Axis.vertical,
|
||
|
shrinkWrap: true,
|
||
|
physics: NeverScrollableScrollPhysics(),
|
||
|
itemBuilder: (context, position) {
|
||
|
return GestureDetector(
|
||
|
onTap: () {
|
||
|
Navigator.of(context).pushNamed(
|
||
|
'/router/web_page',
|
||
|
arguments: {"articleId": articles[position].id});
|
||
|
articles[position].viewers = (articles[position].viewers + 1);
|
||
|
setState(() {}
|
||
|
);
|
||
|
},
|
||
|
child: articleColumnItem(articles[position]),
|
||
|
);
|
||
|
},
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
flex: 1,
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
Widget articleColumnItem(Article articles) {
|
||
|
return Container(
|
||
|
width: double.infinity,
|
||
|
// padding: EdgeInsets.all(16),
|
||
|
color: Colors.white,
|
||
|
child:Column(
|
||
|
children: [
|
||
|
Container(
|
||
|
// margin: EdgeInsets.only(top: 16,bottom: 16),
|
||
|
width: double.infinity,
|
||
|
height: 0.5.h,
|
||
|
color: Color(0xFFF5F5F5),
|
||
|
),
|
||
|
Padding(padding: EdgeInsets.all(16),
|
||
|
child:Row(
|
||
|
children: [
|
||
|
Expanded(child: Column(
|
||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||
|
children: [
|
||
|
Text(
|
||
|
articles?.mainTitle ?? "",
|
||
|
overflow: TextOverflow.ellipsis,
|
||
|
maxLines: 1,
|
||
|
style: TextStyle(
|
||
|
fontSize: 14.sp,
|
||
|
fontWeight: MyFontWeight.medium,
|
||
|
color: Colors.black,
|
||
|
),
|
||
|
),
|
||
|
SizedBox(height:5),
|
||
|
Text(
|
||
|
articles?.viceTitle ?? "",
|
||
|
// overflow: TextOverflow.ellipsis,
|
||
|
// maxLines: 1,
|
||
|
style: TextStyle(
|
||
|
fontSize: 12.sp,
|
||
|
fontWeight: MyFontWeight.regular,
|
||
|
color: Color(0xFF353535),
|
||
|
),
|
||
|
),
|
||
|
SizedBox(height: 10),
|
||
|
Row(
|
||
|
children: [
|
||
|
Text(
|
||
|
(articles != null &&
|
||
|
articles.author != null)
|
||
|
? articles.author.name
|
||
|
: "",
|
||
|
style: TextStyle(
|
||
|
fontSize: 12.sp,
|
||
|
fontWeight: MyFontWeight.medium,
|
||
|
color: Color(0xFF8E8E8E),
|
||
|
),
|
||
|
),
|
||
|
SizedBox(width:8),
|
||
|
Image.asset(
|
||
|
"assets/image/browse.png",
|
||
|
width: 14,
|
||
|
height: 14,
|
||
|
color: Color(0xFF808080),
|
||
|
),
|
||
|
Expanded(child: Text(
|
||
|
"${articles?.viewers}"
|
||
|
?? "",
|
||
|
style: TextStyle(
|
||
|
fontSize: 12.sp,
|
||
|
fontWeight: MyFontWeight.regular,
|
||
|
color: Color(0xFF8D8D8D),
|
||
|
),
|
||
|
)),
|
||
|
Text(
|
||
|
articles?.createTime ?? "",
|
||
|
style: TextStyle(
|
||
|
fontSize: 12.sp,
|
||
|
fontWeight: MyFontWeight.regular,
|
||
|
color: Color(0xFF8D8D8D),
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
],
|
||
|
),),
|
||
|
SizedBox(width:12),
|
||
|
MImage(
|
||
|
articles?.coverImg ?? "",
|
||
|
fit: BoxFit.cover,
|
||
|
radius: BorderRadius.all(Radius.circular(2)),
|
||
|
width:96,
|
||
|
height:96,
|
||
|
),
|
||
|
],
|
||
|
)),
|
||
|
],
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|