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.

213 lines
6.9 KiB

4 years ago
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
4 years ago
import 'package:flutter/material.dart';
4 years ago
import 'package:fluttertoast/fluttertoast.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/view_widget/classic_header.dart';
import 'package:huixiang/view_widget/custom_image.dart';
4 years ago
import 'package:huixiang/view_widget/item_title.dart';
4 years ago
import 'package:huixiang/view_widget/loading_view.dart';
4 years ago
import 'package:huixiang/view_widget/round_button.dart';
4 years ago
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:shared_preferences/shared_preferences.dart';
4 years ago
class ActivityListPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _ActivityListPage();
}
}
class _ActivityListPage extends State<ActivityListPage> {
4 years ago
ApiService apiService;
4 years ago
@override
4 years ago
void initState() {
super.initState();
SharedPreferences.getInstance().then((value) => {
apiService = ApiService(Dio(), token: value.getString('token')),
queryActivity(),
});
4 years ago
}
4 years ago
List<Activity> activityList;
queryActivity() async {
showCupertinoDialog(
context: context,
barrierDismissible: true,
builder: (context) {
return LoadingView();
});
BaseData baseData = await apiService.informationList({
"pageNum": 1,
"pageSize": 10,
"searchKey": "",
4 years ago
"type": 1,
4 years ago
"state": 1
}).catchError((error) {
_refreshController.refreshFailed();
});
4 years ago
if(Navigator.canPop(context))
Navigator.of(context).pop();
4 years ago
if (baseData.isSuccess) {
PageInfo pageInfo = PageInfo.fromJson(baseData.data);
_refreshController.refreshCompleted();
setState(() {
activityList = pageInfo.list.map((e) => Activity.fromJson(e)).toList();
});
4 years ago
} else {
4 years ago
Fluttertoast.showToast(msg: baseData.msg);
4 years ago
}
}
4 years ago
RefreshController _refreshController = RefreshController();
@override
Widget build(BuildContext context) {
4 years ago
return Container(
4 years ago
child: SmartRefresher(
controller: _refreshController,
enablePullDown: true,
enablePullUp: false,
header: MyHeader(),
footer: CustomFooter(
builder: (context, mode) {
Widget body;
if (mode == LoadStatus.idle) {
body = Text("pull up load");
} else if (mode == LoadStatus.loading) {
body = CupertinoActivityIndicator();
} else if (mode == LoadStatus.failed) {
body = Text("Load Failed!Click retry!");
} else if (mode == LoadStatus.canLoading) {
body = Text("release to load more");
} else {
body = Text(S.of(context).meiyougengduoyouhuiquan);
}
return Container(
height: 55.0,
child: Center(child: body),
);
},
),
onRefresh: queryActivity,
child: ListView.builder(
physics: BouncingScrollPhysics(),
itemCount: activityList == null ? 0 : activityList.length,
itemBuilder: (context, position) {
4 years ago
return InkWell(
onTap: () {
Navigator.of(context).pushNamed('/router/store_detail_page');
},
child: activityItem(activityList[position]),
);
4 years ago
},
),
4 years ago
),
);
}
4 years ago
Widget activityItem(Activity activity) {
4 years ago
return AspectRatio(
4 years ago
aspectRatio: 1.38,
4 years ago
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,
4 years ago
aspectRatio: 2.1,
4 years ago
radius: BorderRadius.only(
topLeft: Radius.circular(8),
topRight: Radius.circular(8),
),
4 years ago
fit: BoxFit.cover,
4 years ago
errorSrc: "assets/image/default_2_1.png",
fadeSrc: "assets/image/default_2_1.png",
4 years ago
),
4 years ago
Container(
padding: EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 12),
child: Column(
4 years ago
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
4 years ago
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
activity.mainTitle,
style: TextStyle(
4 years ago
fontWeight: FontWeight.bold,
fontSize: 14,
4 years ago
color: Colors.black,
),
),
SizedBox(
height: 4,
),
Text(
activity.viceTitle,
style: TextStyle(
fontSize: 10,
color: Color(0xFF727272),
4 years ago
),
4 years ago
),
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(
4 years ago
color: Color(0xFF32A060),
fontSize: 12,
4 years ago
fontWeight: FontWeight.bold,
),
),
Text(
activity.startTime.split(" ")[0],
style: TextStyle(
4 years ago
color: Color(0xFF32A060),
fontSize: 12,
4 years ago
fontWeight: FontWeight.bold,
),
),
],
)
],
)
],
),
)
],
),
4 years ago
),
);
}
}