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.

236 lines
8.4 KiB

3 years ago
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
3 years ago
import 'package:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart';
3 years ago
import 'package:huixiang/retrofit/data/activity.dart';
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/page.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
3 years ago
import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/item_title.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
3 years ago
import 'package:shared_preferences/shared_preferences.dart';
3 years ago
class FeaturedActivity extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _FeaturedActivity();
}
}
class _FeaturedActivity extends State<FeaturedActivity> {
3 years ago
ApiService apiService;
@override
void initState() {
super.initState();
queryActivity();
}
List<Activity> activityList;
queryActivity() async {
final SharedPreferences value = await SharedPreferences.getInstance();
apiService =
ApiService(Dio(), context: context, token: value.getString('token'));
BaseData<PageInfo<Activity>> baseData = await apiService.informationList({
"pageNum": 1,
"pageSize": 10,
"searchKey": "",
"type": 1,
"state": 1
3 years ago
}).catchError((error) {});
3 years ago
if (baseData != null && baseData.isSuccess) {
activityList = baseData.data.list;
3 years ago
if (activityList != null && activityList.length == 1)
3 years ago
activityList.add(activityList[0]);
3 years ago
if (activityList != null && activityList.length == 2)
3 years ago
activityList.add(activityList[1]);
}
}
3 years ago
@override
Widget build(BuildContext context) {
return Column(
children: [
ItemTitle(
3 years ago
text: "精选活动",
imgPath: "assets/image/home_activity.webp",
3 years ago
moreText: S.of(context).chakangengduo,
3 years ago
onTap: () {
Navigator.of(context).pushNamed('/router/activity_list');
},
3 years ago
),
SizedBox(
height: 10.h,
),
Container(
3 years ago
margin: EdgeInsets.symmetric(horizontal: 9.w),
3 years ago
child: Row(
children: [
3 years ago
if (activityList != null && activityList.length > 0)
3 years ago
GestureDetector(
onTap: () {
Navigator.of(context).pushNamed('/router/web_page',
arguments: {"activityId": activityList[0].id});
},
child: Container(
child: stackItem(18.sp, activityList[0]),
margin: EdgeInsets.symmetric(horizontal: 5.w),
width: (MediaQuery.of(context).size.width - 42) / 2,
height: 125.h,
3 years ago
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
3 years ago
color: Colors.red,
image: DecorationImage(
image: NetworkImage(
activityList[0].coverImg,
),
3 years ago
fit: BoxFit.cover,
3 years ago
),
3 years ago
),
),
),
3 years ago
if (activityList != null && activityList.length > 1)
Expanded(
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
GestureDetector(
onTap: () {
Navigator.of(context).pushNamed('/router/web_page',
arguments: {"activityId": activityList[1].id});
},
child: Container(
child: stackItem(12.sp, activityList[1]),
margin: EdgeInsets.symmetric(horizontal: 5.w),
width: (MediaQuery.of(context).size.width - 42) / 2,
height:125.h,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
color: Colors.green,
image: DecorationImage(
image: NetworkImage(
activityList[1].coverImg,
),
3 years ago
fit: BoxFit.cover,
3 years ago
),
3 years ago
),
3 years ago
),
),
// SizedBox(
// height: 5,
// ),
// GestureDetector(
// onTap: () {
// Navigator.of(context).pushNamed('/router/web_page',
// arguments: {"activityId": activityList[2].id});
// },
// child: Container(
// child: stackItem(12.sp, activityList[2]),
// margin: EdgeInsets.symmetric(horizontal: 5.w),
// width: (MediaQuery.of(context).size.width - 42) / 2,
// height: 190.h / 2,
// decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(4),
// color: Colors.blue,
// image: DecorationImage(
// image: NetworkImage(
// activityList[2].coverImg,
// ),
// fit: BoxFit.fill,
// ),
// ),
// ),
// ),
],
),
3 years ago
),
3 years ago
),
],
),
),
SizedBox(
height: 28.h,
),
],
);
}
3 years ago
Widget stackItem(double textSize, Activity activity) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
color: Color.fromARGB(80, 0, 0, 0),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: EdgeInsets.only(left: 8, top: 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
activity.mainTitle,
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize: 14.sp,
color: Colors.white,
),
),
SizedBox(
height: 2,
),
Text(
activity?.viceTitle ?? "",
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize: 12.sp,
color: Colors.white,
),
),
],
3 years ago
),
),
Container(
width: 48.w,
margin: EdgeInsets.only(left: 8, bottom: 8),
padding: EdgeInsets.symmetric(
vertical: 4.h,
horizontal: 8.w,
3 years ago
),
decoration: BoxDecoration(
color: Color(0xFF32A060),
borderRadius: BorderRadius.circular(20),
3 years ago
),
alignment: Alignment.center,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"了解",
style: TextStyle(
fontSize: 10.sp,
fontWeight: MyFontWeight.medium,
color: Colors.white,
),
),
Icon(
Icons.keyboard_arrow_right,
color: Colors.white,
size: 12,
),
],
3 years ago
),
),
],
));
3 years ago
}
}