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 createState() { return _ActivityListPage(); } } class _ActivityListPage extends State { ApiService apiService; @override void initState() { super.initState(); SharedPreferences.getInstance().then((value) => { apiService = ApiService(Dio(), token: value.getString('token')), queryActivity(), }); } BuildContext dialogContext; List activityList; queryActivity() async { showCupertinoDialog( context: context, barrierDismissible: true, builder: (context) { dialogContext = context; return LoadingView(); }); BaseData baseData = await apiService.informationList({ "pageNum": 1, "pageSize": 10, "searchKey": "", "state": 1 }).catchError((error) { _refreshController.refreshFailed(); }); Navigator.of(dialogContext).pop(); if (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 activityItem(activityList[position]); }, ), ), ); } Widget activityItem(Activity activity) { return 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, // radius: BorderRadius.only( // topLeft: Radius.circular(8), topRight: Radius.circular(8)), // fit: BoxFit.cover, // errorSrc: "assets/image/default_avatar.png", // fadeSrc: "assets/image/default_avatar.png", // ), ClipRRect( borderRadius: BorderRadius.only( topLeft: Radius.circular(8), topRight: Radius.circular(8)), child: Image.network( "https://t7.baidu.com/it/u=1297102096,3476971300&fm=193&f=GIF", fit: BoxFit.cover, ), ), Container( padding: EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 12), child: Column( mainAxisAlignment: MainAxisAlignment.spaceAround, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( activity.mainTitle, style: TextStyle( fontWeight: FontWeight.bold, fontSize: 14, color: Colors.black), ), 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), ), ], ) ], ) ], ), ) ], ), ); } }