diff --git a/lib/im/chat_friend_group.dart b/lib/im/chat_friend_group.dart index f0b1af9e..3bd669b4 100644 --- a/lib/im/chat_friend_group.dart +++ b/lib/im/chat_friend_group.dart @@ -37,7 +37,7 @@ class _ChatFriendGroup extends State } loadFinish() { - _allKey = [GlobalKey(), GlobalKey(), GlobalKey(), GlobalKey()]; + _allKey = [GlobalKey(), GlobalKey(), GlobalKey()]; setState(() {}); } @@ -46,7 +46,7 @@ class _ChatFriendGroup extends State return Scaffold( backgroundColor: Color(0xFFFFFFFF), appBar: MyAppBar( - title: "好友(2)", + title: "${S.of(context).haoyou}(2)", titleColor: Color(0xFF0D0D0D), titleSize: 17.sp, leading: true, @@ -120,9 +120,9 @@ class _ChatFriendGroup extends State child: TabBarView( controller: tabController, children: [ - FriendGroupList(_allKey[0]), - FriendGroupList(_allKey[1]), - FriendGroupList(_allKey[2]), + FriendGroupList(_allKey[0],"","好友"), + FriendGroupList(_allKey[1],"false", "关注"), + FriendGroupList(_allKey[2],"true","粉丝"), ], ), ) diff --git a/lib/im/im_view/friend_groip_list.dart b/lib/im/im_view/friend_groip_list.dart index b7d87fc5..5acb9abb 100644 --- a/lib/im/im_view/friend_groip_list.dart +++ b/lib/im/im_view/friend_groip_list.dart @@ -1,12 +1,24 @@ +import 'package:dio/dio.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; - +import 'package:pull_to_refresh/pull_to_refresh.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import '../../retrofit/data/base_data.dart'; +import '../../retrofit/data/follow_list.dart'; +import '../../retrofit/data/page.dart'; import '../../retrofit/retrofit_api.dart'; +import 'package:huixiang/im/database/message.dart'; + +import '../../view_widget/custom_image.dart'; +import '../../view_widget/no_data_view.dart'; class FriendGroupList extends StatefulWidget { + final String isMyFans; + final String title; + FriendGroupList( - Key key, + Key key,this.isMyFans,this.title ) : super(key: key); @override @@ -18,11 +30,22 @@ class FriendGroupList extends StatefulWidget { class _FriendGroupList extends State { ApiService apiService; final TextEditingController editingController = TextEditingController(); + RefreshController _refreshController; FocusNode _focusNode = FocusNode(); + List userIds = []; + List messages = []; + int pageNum = 1; + List list = []; @override void initState() { super.initState(); + // loadMessageList(); + if( widget.isMyFans == ""){ + queryMutualFollowList(); + } else{ + queryFollowList(); + } } ///离开页面记着销毁和清除 @@ -32,6 +55,86 @@ class _FriendGroupList extends State { super.dispose(); } + // loadMessageList() async { + // SharedPreferences shared = await SharedPreferences.getInstance(); + // String userId = shared.getString("userId"); + // messages = await hxDatabase.queryList(userId); + // messages.forEach((element) { + // debugPrint("messages: ${element.toJson()}"); + // }); + // userIds = messages + // .map((e) => e.toId != userId ? e.toId : e.fromId) + // .toSet().where((element) => element != userId) + // .toList(); + // if (mounted) { + // setState(() {}); + // } + // + // } + + ///关注、粉丝列表 + queryFollowList() async { + SharedPreferences sharedPreferences = await SharedPreferences.getInstance(); + if (apiService == null) + apiService = ApiService( + Dio(), + context: context, + token: sharedPreferences.getString("token"), + showLoading: false, + ); + BaseData> baseData = await apiService.followList({ + "isMyFans": widget.isMyFans, + "pageNum": pageNum, + "pageSize": 100, + }).catchError((error) { + _refreshController.refreshFailed(); + _refreshController.loadFailed(); + }); + if (baseData != null && baseData.isSuccess) { + if (pageNum == 1) { + list.clear(); + } + list.addAll(baseData.data.list); + setState(() {}); + } + } + + + + ///好友列表 + queryMutualFollowList() async { + SharedPreferences sharedPreferences = await SharedPreferences.getInstance(); + if (apiService == null) + apiService = ApiService( + Dio(), + context: context, + token: sharedPreferences.getString("token"), + showLoading: false, + ); + BaseData> baseData = await apiService.mutualFollowList({ + "isMyFans": widget.isMyFans, + "pageNum": 1, + "pageSize": 100, + }).catchError((error) { + _refreshController.refreshFailed(); + _refreshController.loadFailed(); + }); + + _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(() {}); + } + } + @override Widget build(BuildContext context) { return Container( @@ -39,13 +142,30 @@ class _FriendGroupList extends State { child: Column( children: [ friendGroupSearch(), - Expanded( + (list == null || list.length == 0) + ? NoDataView( + src: "assets/image/guan_zhu.webp", + isShowBtn: false, + text: "目前暂无${widget?.title ?? ""},听说多发动态可以涨粉哦~", + fontSize: 16.sp, + margin: EdgeInsets.only(top: 120.h,left: 60.w,right: 60.w), + ):Expanded( child: ListView.builder( - itemCount: 10, + itemCount: list.length ?? 0, physics: BouncingScrollPhysics(), shrinkWrap: true, itemBuilder: (context, position) { - return friendGroupItem(); + return GestureDetector( + onTap:(){ + Navigator.of(context).pushNamed( + '/router/chat_details_page', + arguments: { + "toId":list[position].mid, + }, + ); + }, + child:friendGroupItem(list[position]), + ); }, )), ], @@ -53,7 +173,7 @@ class _FriendGroupList extends State { ); } - Widget friendGroupItem() { + Widget friendGroupItem(ListData list) { return Container( margin: EdgeInsets.only(left:16.w,right:16.w,bottom: 24.h), child: Row(children: [ @@ -61,17 +181,20 @@ class _FriendGroupList extends State { decoration: BoxDecoration( borderRadius: BorderRadius.circular(26.5.r), ), - child: Image.asset( - "assets/image/bs_mine_heading.webp", - width: 54.h, - height: 54.h, - fit: BoxFit.fill, + child: MImage( + list?.avatar ?? "", + isCircle: true, + width: 66, + height: 66, + fit: BoxFit.cover, + errorSrc: "assets/image/default_user.webp", + fadeSrc: "assets/image/default_user.webp", ), ), Padding( padding: EdgeInsets.only(left: 4.w), child: Text( - "哈喽喽哈", + list?.nickname ?? "", style: TextStyle( fontSize: 16.sp, color: Color(0xFF060606),