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.
 
 
 
 
 
 

207 lines
6.3 KiB

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:huixiang/data/base_data.dart';
import 'package:huixiang/data/follow.dart';
import 'package:huixiang/data/page.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 {
final Function refresh;
FollowPage(this.refresh);
@override
State<StatefulWidget> createState() {
return _FollowPage();
}
}
class _FollowPage extends State<FollowPage>
with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
late RefreshController _refreshController;
ApiService? apiService;
int pageNum = 1;
List<Follow> list = [];
@override
void initState() {
super.initState();
_refreshController = RefreshController();
SharedPreferences.getInstance().then((value) {
apiService =
ApiService(Dio(), context: context, token: value.getString("token"));
_queryFollowList();
});
}
///我的关注列表
_queryFollowList() async {
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
BaseData<PageInfo<Follow>>? baseData = await apiService?.followList({
"isMyFans": false,
"pageNum": 1,
"pageSize": 100,
}).catchError((error) {
_refreshController.refreshFailed();
_refreshController.loadFailed();
});
_refreshController.refreshCompleted();
_refreshController.loadComplete();
if (baseData?.isSuccess ?? false) {
if (baseData?.data?.list?.isNotEmpty ?? false) {
if (pageNum == 1) {
list.clear();
}
list.addAll(baseData!.data!.list!);
}
print("list: ${list.length}");
if ((int.tryParse("${baseData?.data?.total}") ?? 0) < (pageNum * 10)) {
_refreshController.loadNoData();
}
setState(() {});
}
}
///关注/取关会员
_vipFollow(followId) async {
BaseData? baseData = await apiService?.follow(followId);
if (baseData?.isSuccess ?? false) {
widget.refresh();
_queryFollowList();
SmartDialog.showToast("取关成功", alignment: Alignment.center);
} else {
SmartDialog.showToast("${baseData?.msg}", alignment: Alignment.center);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
margin: EdgeInsets.only(top: 2),
color: Colors.white,
child: SmartRefresher(
enablePullDown: true,
enablePullUp: false,
header: MyHeader(),
footer: CustomFooter(
builder: (context, mode) {
return MyFooter(mode);
},
),
controller: _refreshController,
onRefresh: () {
_queryFollowList();
},
physics: BouncingScrollPhysics(),
child: (list.isEmpty)
? NoDataView(
src: "assets/image/guan_zhu.webp",
isShowBtn: false,
text: "目前暂无添加关注,可在推荐中关注自己喜欢的人哦~",
fontSize: 16.sp,
margin: EdgeInsets.only(
top: 120.h,
left: 60.w,
right: 60.w,
),
)
: ListView.builder(
itemCount: list.length ?? 0,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
padding: EdgeInsets.symmetric(vertical: 8.h),
itemBuilder: (context, position) {
return Container(
child: followItem(list[position]),
);
},
)),
),
);
}
Widget followItem(Follow list) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.h),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
MImage(
(list.avatar ?? ""),
width: 44,
height: 44,
isCircle: true,
fit: BoxFit.cover,
errorSrc: "assets/image/default_1.webp",
fadeSrc: "assets/image/default_1.webp",
),
SizedBox(
width: 8,
),
Expanded(
child: Text(
list.nickname ?? "",
style: TextStyle(
color: Color(0xFF1A1A1A),
fontSize: 14.sp,
fontWeight: MyFontWeight.medium,
),
),
),
Container(
width: 56.w,
height: 25.h,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(11.w),
color: Color(0xFFE6E6E6),
),
child: GestureDetector(
onTap: () {
_vipFollow(list.mid);
},
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),
fontSize: 10.sp,
fontWeight: MyFontWeight.regular,
),
),
],
),
),
),
],
),
);
}
@override
bool get wantKeepAlive => true;
}