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.
212 lines
6.9 KiB
212 lines
6.9 KiB
import 'package:dio/dio.dart'; |
|
import 'package:flutter/cupertino.dart'; |
|
import 'package:flutter/material.dart'; |
|
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'; |
|
import 'package:huixiang/view_widget/item_title.dart'; |
|
import 'package:huixiang/view_widget/loading_view.dart'; |
|
import 'package:huixiang/view_widget/round_button.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> { |
|
ApiService apiService; |
|
|
|
@override |
|
void initState() { |
|
super.initState(); |
|
SharedPreferences.getInstance().then((value) => { |
|
apiService = ApiService(Dio(), 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) { |
|
return Container( |
|
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) { |
|
return InkWell( |
|
onTap: () { |
|
Navigator.of(context).pushNamed('/router/store_detail_page'); |
|
}, |
|
child: activityItem(activityList[position]), |
|
); |
|
}, |
|
), |
|
), |
|
); |
|
} |
|
|
|
Widget activityItem(Activity activity) { |
|
return AspectRatio( |
|
aspectRatio: 1.38, |
|
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, |
|
), |
|
), |
|
], |
|
) |
|
], |
|
) |
|
], |
|
), |
|
) |
|
], |
|
), |
|
), |
|
); |
|
} |
|
}
|
|
|