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.
 
 
 
 
 
 

205 lines
6.7 KiB

import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.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/view_widget/classic_header.dart';
import 'package:huixiang/view_widget/custom_image.dart';
import 'package:huixiang/view_widget/loading_view.dart';
import 'package:huixiang/view_widget/my_footer.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:shared_preferences/shared_preferences.dart';
class ActivityListPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _ActivityListPage();
}
}
class _ActivityListPage extends State<ActivityListPage>
with AutomaticKeepAliveClientMixin {
ApiService apiService;
@override
void initState() {
super.initState();
SharedPreferences.getInstance().then((value) => {
apiService = ApiService(Dio(), context: context, token: value.getString('token')),
queryActivity(),
});
}
List<Activity> activityList;
queryActivity() async {
showCupertinoDialog(
context: context,
barrierDismissible: true,
builder: (context) {
return LoadingView();
});
BaseData baseData = await apiService.informationList({
"pageNum": 1,
"pageSize": 10,
"searchKey": "",
"type": 1,
"state": 1
}).catchError((error) {
_refreshController.refreshFailed();
});
if (Navigator.canPop(context)) Navigator.of(context).pop();
if (baseData != null && baseData.isSuccess) {
PageInfo pageInfo = PageInfo.fromJson(baseData.data);
_refreshController.refreshCompleted();
setState(() {
activityList = pageInfo.list.map((e) => Activity.fromJson(e)).toList();
});
} else {
Fluttertoast.showToast(msg: baseData.msg);
}
}
RefreshController _refreshController = RefreshController();
@override
Widget build(BuildContext context) {
super.build(context);
return Container(
child: SmartRefresher(
controller: _refreshController,
enablePullDown: true,
enablePullUp: false,
header: MyHeader(),
footer: CustomFooter(
builder: (context, mode) {
return MyFooter(mode);
},
),
onRefresh: queryActivity,
child: ListView.builder(
physics: BouncingScrollPhysics(),
itemCount: activityList == null ? 0 : activityList.length,
itemBuilder: (context, position) {
return InkWell(
onTap: () {
Navigator.of(context)
.pushNamed('/router/store_detail_page', arguments: {
"html": activityList[position].content,
"title": activityList[position].mainTitle,
"time": activityList[position].createTime,
"author": activityList[position].storeName
});
},
child: activityItem(activityList[position]),
);
},
),
),
);
}
Widget activityItem(Activity activity) {
return AspectRatio(
aspectRatio: 1.34,
child: Container(
margin: EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 8),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
)
],
borderRadius: BorderRadius.all(Radius.circular(8)),
),
child: Column(
children: [
MImage(
activity.coverImg,
aspectRatio: 2.1,
radius: BorderRadius.only(
topLeft: Radius.circular(8),
topRight: Radius.circular(8),
),
fit: BoxFit.cover,
errorSrc: "assets/image/default_2_1.png",
fadeSrc: "assets/image/default_2_1.png",
),
Container(
padding: EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 12),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
activity.mainTitle,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14,
color: Colors.black,
),
),
SizedBox(
height: 4,
),
Text(
activity.viceTitle ?? "",
style: TextStyle(
fontSize: 10,
color: Color(0xFF727272),
),
),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
activity.storeName == null ? "" : activity.storeName,
style: TextStyle(
color: Color(0xFF060606),
fontSize: 12,
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
activity.startTime.split(" ")[1],
style: TextStyle(
color: Color(0xFF32A060),
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
Text(
activity.startTime.split(" ")[0],
style: TextStyle(
color: Color(0xFF32A060),
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
],
)
],
)
],
),
)
],
),
),
);
}
@override
bool get wantKeepAlive => true;
}