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.

206 lines
6.0 KiB

3 years ago
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
3 years ago
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
3 years ago
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/base_data.dart';
3 years ago
import 'package:huixiang/retrofit/data/follow_list.dart';
import 'package:huixiang/retrofit/data/page.dart';
3 years ago
import 'package:huixiang/retrofit/data/vip_card.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/classic_header.dart';
import 'package:huixiang/view_widget/custom_image.dart';
import 'package:huixiang/view_widget/my_footer.dart';
import 'package:huixiang/view_widget/no_data_view.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
class FollowPage extends StatefulWidget {
3 years ago
final Function refresh;
FollowPage(
this.refresh
);
3 years ago
@override
State<StatefulWidget> createState() {
return _FollowPage();
}
}
class _FollowPage extends State<FollowPage> {
RefreshController _refreshController;
ApiService apiService;
3 years ago
int pageNum = 1;
List<ListData> list = [];
3 years ago
@override
void initState() {
super.initState();
_refreshController = RefreshController();
SharedPreferences.getInstance().then((value) {
apiService =
ApiService(Dio(), context: context, token: value.getString("token"));
3 years ago
_queryFollowList();
3 years ago
});
}
3 years ago
///我的关注列表
_queryFollowList() async {
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
if (apiService == null)
apiService = ApiService(
Dio(),
context: context,
token: sharedPreferences.getString("token"),
showLoading: false,
);
BaseData<PageInfo<ListData>> baseData = await apiService.followList({
"isMyFans": false,
"pageNum": 1,
"pageSize": 100,
}).catchError((error) {
_refreshController.refreshFailed();
_refreshController.loadFailed();
});
3 years ago
3 years ago
_refreshController.refreshCompleted();
_refreshController.loadComplete();
if (baseData != null && baseData.isSuccess) {
if (pageNum == 1) {
list.clear();
}
list.addAll(baseData.data.list);
print("list: ${list.length}");
if (int.tryParse(baseData.data.total) < (pageNum * 10)) {
_refreshController.loadNoData();
}
setState(() {});
}
}
3 years ago
3 years ago
///关注/取关会员
_vipFollow(followId) async {
BaseData baseData = await apiService.follow(followId);
if (baseData != null && baseData.isSuccess) {
widget.refresh();
_queryFollowList();
SmartDialog.showToast("取关成功", alignment: Alignment.center);
} else {
SmartDialog.showToast(baseData.msg, alignment: Alignment.center);
}
}
3 years ago
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
3 years ago
margin: EdgeInsets.only(top: 2),
color:Colors.white,
3 years ago
child: SmartRefresher(
enablePullDown: true,
enablePullUp: false,
header: MyHeader(),
footer: CustomFooter(
builder: (context, mode) {
return MyFooter(mode);
},
),
controller: _refreshController,
3 years ago
onRefresh: (){_queryFollowList();},
3 years ago
physics: BouncingScrollPhysics(),
3 years ago
child: ListView.builder(
itemCount: list == null ? 0 : list.length,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
3 years ago
padding: EdgeInsets.symmetric(vertical: 8.h),
itemBuilder: (context, position) {
3 years ago
return Container(
child: followItem(list[position]),
3 years ago
);
},
3 years ago
),
3 years ago
// NoDataView(
// isShowBtn: false,
// text: "共关注0人",
// fontSize: 16.sp,
// margin: EdgeInsets.only(top: 120.h),
// ),
),
3 years ago
3 years ago
),
);
}
3 years ago
Widget followItem(ListData list) {
3 years ago
return Container(
margin: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.h),
child:Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment:CrossAxisAlignment.center,
children: [
MImage(
3 years ago
list != null ? (list.avatar ?? "") : "",
3 years ago
width: 44,
height: 44,
isCircle: true,
fit: BoxFit.cover,
errorSrc: "assets/image/default_1.png",
fadeSrc: "assets/image/default_1.png",
),
SizedBox(
width:8,
),
Expanded(child:Text(
3 years ago
list != null ? (list.nickname ?? "") : "",
3 years ago
style: TextStyle(
color: Color(0xFF1A1A1A),
fontSize: 14.sp,
fontWeight: MyFontWeight.medium,
),
)),
Container(
3 years ago
width: 56.w,
height: 25.h,
3 years ago
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(11.w),
color: Color(0xFFE6E6E6),
),
3 years ago
child:
GestureDetector(onTap: (){
_vipFollow(list.mid);
},
3 years ago
child:Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment:CrossAxisAlignment.center,
children: [
Icon(
Icons.check,
color: Color(0xFF808080),
size: 14,
),
SizedBox(
width:4,
),
Text(
"已关注",
style: TextStyle(
color: Color(0xFF808080),
3 years ago
fontSize: 10.sp,
3 years ago
fontWeight: MyFontWeight.regular,
),
),
],
3 years ago
),),
3 years ago
),
],
),
);
}
}