import 'package:dio/dio.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:huixiang/generated/l10n.dart'; 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'; import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/view_widget/item_title.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:shared_preferences/shared_preferences.dart'; class FeaturedActivity extends StatefulWidget { @override State createState() { return _FeaturedActivity(); } } class _FeaturedActivity extends State { ApiService apiService; @override void initState() { super.initState(); queryActivity(); } List activityList; queryActivity() async { final SharedPreferences value = await SharedPreferences.getInstance(); apiService = ApiService(Dio(), context: context, token: value.getString('token')); BaseData> baseData = await apiService.informationList({ "pageNum": 1, "pageSize": 10, "searchKey": "", "type": 1, "state": 1 }).catchError((error) {}); if (baseData != null && baseData.isSuccess) { activityList = baseData.data.list; if (activityList != null && activityList.length == 1) activityList.add(activityList[0]); if (activityList != null && activityList.length == 2) activityList.add(activityList[1]); } } @override Widget build(BuildContext context) { return Column( children: [ ItemTitle( text: "精选活动", imgPath: "assets/image/home_activity.png", moreText: S.of(context).chakangengduo, onTap: () { Navigator.of(context).pushNamed('/router/activity_list'); }, ), SizedBox( height: 10.h, ), Container( margin: EdgeInsets.symmetric(horizontal: 9.w), child: Row( children: [ if (activityList != null && activityList.length > 0) 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: 190.h, decoration: BoxDecoration( borderRadius: BorderRadius.circular(4), color: Colors.red, image: DecorationImage( image: NetworkImage( activityList[0].coverImg, ), fit: BoxFit.cover, ), ), ), ), if (activityList != null && activityList.length > 1) 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: 190.h / 2, decoration: BoxDecoration( borderRadius: BorderRadius.circular(4), color: Colors.green, image: DecorationImage( image: NetworkImage( activityList[1].coverImg, ), fit: BoxFit.cover, ), ), ), ), 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.cover, ), ), ), ), ], ), ), ], ), ), SizedBox( height: 28.h, ), ], ); } Widget stackItem(double textSize, Activity activity) { return Container(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: textSize, color: Colors.white, ), ), SizedBox( height: 2, ), Text( activity?.viceTitle??"", style: TextStyle( fontWeight: MyFontWeight.semi_bold, fontSize: 12.sp, color: Colors.white, ), ), ], ), ), Container( width: 58.w, margin: EdgeInsets.only(left: 8, bottom: 8), padding: EdgeInsets.symmetric( vertical: 4.h, horizontal: 8.w, ), decoration: BoxDecoration( color: Color(0xFF32A060), borderRadius: BorderRadius.circular(20), ), 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, ), ], ), ), ], )); } }