mod: 关注、粉丝页面优化

This commit is contained in:
guozhigq
2023-08-31 21:42:59 +08:00
parent 08e4e64764
commit 01df8622e0
4 changed files with 97 additions and 28 deletions

View File

@ -1,3 +1,4 @@
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:hive/hive.dart';
import 'package:pilipala/http/fan.dart';
@ -7,11 +8,13 @@ import 'package:pilipala/utils/storage.dart';
class FansController extends GetxController {
Box userInfoCache = GStrorage.userInfo;
int pn = 1;
int ps = 20;
int total = 0;
RxList<FansItemModel> fansList = [FansItemModel()].obs;
late int mid;
late String name;
var userInfo;
RxString loadingText = '加载中...'.obs;
@override
void onInit() {
@ -26,23 +29,31 @@ class FansController extends GetxController {
Future queryFans(type) async {
if (type == 'init') {
pn = 1;
loadingText.value == '加载中...';
}
if (loadingText.value == '没有更多了') {
return;
}
var res = await FanHttp.fans(
vmid: mid,
pn: pn,
ps: 20,
ps: ps,
orderType: 'attention',
);
if (res['status']) {
if (type == 'init') {
fansList.value = res['data'].list;
total = res['data'].total;
} else if (type == 'onRefresh') {
fansList.insertAll(0, res['data'].list);
} else if (type == 'onLoad') {
fansList.addAll(res['data'].list);
}
print(total);
if ((pn == 1 && total < ps) || res['data'].list.isEmpty) {
loadingText.value = '没有更多了';
}
pn += 1;
} else {
SmartDialog.showToast(res['msg']);
}
return res;
}

View File

@ -1,6 +1,8 @@
import 'package:easy_debounce/easy_throttle.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:pilipala/common/widgets/http_error.dart';
import 'package:pilipala/common/widgets/no_data.dart';
import 'package:pilipala/models/fans/result.dart';
import 'controller.dart';
@ -17,7 +19,6 @@ class _FansPageState extends State<FansPage> {
final FansController _fansController = Get.put(FansController());
final ScrollController scrollController = ScrollController();
Future? _futureBuilderFuture;
bool _isLoadingMore = false;
@override
void initState() {
@ -27,11 +28,9 @@ class _FansPageState extends State<FansPage> {
() async {
if (scrollController.position.pixels >=
scrollController.position.maxScrollExtent - 200) {
if (!_isLoadingMore) {
_isLoadingMore = true;
await _fansController.queryFans('onLoad');
_isLoadingMore = false;
}
EasyThrottle.throttle('follow', const Duration(seconds: 1), () {
_fansController.queryFans('onLoad');
});
}
},
);
@ -66,14 +65,38 @@ class _FansPageState extends State<FansPage> {
if (data['status']) {
List<FansItemModel> list = _fansController.fansList;
return Obx(
() => list.length == 1
? const SizedBox()
: ListView.builder(
() => list.isNotEmpty
? ListView.builder(
controller: scrollController,
itemCount: list.length,
itemCount: list.length + 1,
itemBuilder: (BuildContext context, int index) {
return fanItem(item: list[index]);
if (index == list.length) {
return Container(
height:
MediaQuery.of(context).padding.bottom + 60,
padding: EdgeInsets.only(
bottom:
MediaQuery.of(context).padding.bottom),
child: Center(
child: Obx(
() => Text(
_fansController.loadingText.value,
style: TextStyle(
color: Theme.of(context)
.colorScheme
.outline,
fontSize: 13),
),
),
),
);
} else {
return fanItem(item: list[index]);
}
},
)
: const CustomScrollView(
slivers: [NoData()],
),
);
} else {

View File

@ -1,3 +1,4 @@
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:hive/hive.dart';
import 'package:pilipala/http/follow.dart';
@ -7,11 +8,13 @@ import 'package:pilipala/utils/storage.dart';
class FollowController extends GetxController {
Box userInfoCache = GStrorage.userInfo;
int pn = 1;
int ps = 20;
int total = 0;
RxList<FollowItemModel> followList = [FollowItemModel()].obs;
late int mid;
late String name;
var userInfo;
RxString loadingText = '加载中...'.obs;
@override
void onInit() {
@ -26,23 +29,30 @@ class FollowController extends GetxController {
Future queryFollowings(type) async {
if (type == 'init') {
pn = 1;
loadingText.value == '加载中...';
}
if (loadingText.value == '没有更多了') {
return;
}
var res = await FollowHttp.followings(
vmid: mid,
pn: pn,
ps: 20,
ps: ps,
orderType: 'attention',
);
if (res['status']) {
if (type == 'init') {
followList.value = res['data'].list;
total = res['data'].total;
} else if (type == 'onRefresh') {
followList.insertAll(0, res['data'].list);
} else if (type == 'onLoad') {
followList.addAll(res['data'].list);
}
if ((pn == 1 && total < ps) || res['data'].list.isEmpty) {
loadingText.value = '没有更多了';
}
pn += 1;
} else {
SmartDialog.showToast(res['msg']);
}
return res;
}

View File

@ -1,6 +1,8 @@
import 'package:easy_debounce/easy_throttle.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:pilipala/common/widgets/http_error.dart';
import 'package:pilipala/common/widgets/no_data.dart';
import 'package:pilipala/models/follow/result.dart';
import 'controller.dart';
@ -17,7 +19,6 @@ class _FollowPageState extends State<FollowPage> {
final FollowController _followController = Get.put(FollowController());
final ScrollController scrollController = ScrollController();
Future? _futureBuilderFuture;
bool _isLoadingMore = false;
@override
void initState() {
@ -27,11 +28,9 @@ class _FollowPageState extends State<FollowPage> {
() async {
if (scrollController.position.pixels >=
scrollController.position.maxScrollExtent - 200) {
if (!_isLoadingMore) {
_isLoadingMore = true;
await _followController.queryFollowings('onLoad');
_isLoadingMore = false;
}
EasyThrottle.throttle('follow', const Duration(seconds: 1), () {
_followController.queryFollowings('onLoad');
});
}
},
);
@ -67,14 +66,40 @@ class _FollowPageState extends State<FollowPage> {
if (data['status']) {
List<FollowItemModel> list = _followController.followList;
return Obx(
() => list.length == 1
? const SizedBox()
: ListView.builder(
() => list.isNotEmpty
? ListView.builder(
controller: scrollController,
itemCount: list.length,
itemCount: list.length + 1,
itemBuilder: (BuildContext context, int index) {
return followItem(item: list[index]);
if (index == list.length) {
return Container(
height:
MediaQuery.of(context).padding.bottom +
60,
padding: EdgeInsets.only(
bottom: MediaQuery.of(context)
.padding
.bottom),
child: Center(
child: Obx(
() => Text(
_followController.loadingText.value,
style: TextStyle(
color: Theme.of(context)
.colorScheme
.outline,
fontSize: 13),
),
),
),
);
} else {
return followItem(item: list[index]);
}
},
)
: const CustomScrollView(
slivers: [NoData()],
),
);
} else {