fix: 动态渲染异常

This commit is contained in:
guozhigq
2023-08-20 18:10:54 +08:00
parent 5f03244085
commit 8c8ddc9d93
4 changed files with 70 additions and 44 deletions

View File

@ -8,7 +8,9 @@ class FollowUpModel {
List<UpItem>? upList;
FollowUpModel.fromJson(Map<String, dynamic> json) {
liveUsers = LiveUsers.fromJson(json['live_users']);
liveUsers = json['live_users'] != null
? LiveUsers.fromJson(json['live_users'])
: null;
upList = json['up_list'] != null
? json['up_list'].map<UpItem>((e) => UpItem.fromJson(e)).toList()
: [];

View File

@ -54,6 +54,7 @@ class DynamicsController extends GetxController {
Box userInfoCache = GStrorage.userInfo;
RxBool userLogin = false.obs;
var userInfo;
RxBool isLoadingDynamic = false.obs;
@override
void onInit() {
@ -69,12 +70,14 @@ class DynamicsController extends GetxController {
if (type == 'init') {
dynamicsList.clear();
}
isLoadingDynamic.value = true;
var res = await DynamicsHttp.followDynamic(
page: type == 'init' ? 1 : page,
type: dynamicsType.value.values,
offset: offset,
mid: mid.value,
);
isLoadingDynamic.value = false;
if (res['status']) {
if (type == 'init') {
dynamicsList.value = res['data'].items;
@ -194,11 +197,15 @@ class DynamicsController extends GetxController {
return {'status': false, 'msg': '账号未登录'};
}
if (type == 'init') {
upData = FollowUpModel().obs;
upData.value.upList = [];
upData.value.liveUsers = LiveUsers();
}
var res = await DynamicsHttp.followUp();
if (res['status']) {
upData.value = res['data'];
if (upData.value.upList!.isEmpty) {
mid.value = -1;
}
}
return res;
}
@ -212,7 +219,7 @@ class DynamicsController extends GetxController {
onRefresh() async {
page = 1;
queryFollowUp();
await queryFollowUp();
await queryFollowDynamic();
}
@ -232,7 +239,7 @@ class DynamicsController extends GetxController {
mid.value = -1;
dynamicsType.value = DynamicsType.values[0];
initialValue.value = 1;
SmartDialog.showToast('还原默认加载', alignment: Alignment.topCenter);
SmartDialog.showToast('还原默认加载');
dynamicsList.value = [DynamicItemModel()];
queryFollowDynamic();
}

View File

@ -7,6 +7,7 @@ import 'package:get/get.dart';
import 'package:hive/hive.dart';
import 'package:pilipala/common/skeleton/dynamic_card.dart';
import 'package:pilipala/common/widgets/http_error.dart';
import 'package:pilipala/common/widgets/no_data.dart';
import 'package:pilipala/models/dynamics/result.dart';
import 'package:pilipala/pages/main/index.dart';
import 'package:pilipala/utils/event_bus.dart';
@ -152,14 +153,12 @@ class _DynamicsPageState extends State<DynamicsPage>
.textTheme
.labelMedium!
.fontSize)),
// 4: Text(
// '专栏',
// style: TextStyle(
// fontSize: Theme.of(context)
// .textTheme
// .labelMedium!
// .fontSize),
// ),
4: Text('专栏',
style: TextStyle(
fontSize: Theme.of(context)
.textTheme
.labelMedium!
.fontSize)),
},
padding: 13.0,
decoration: BoxDecoration(
@ -186,22 +185,22 @@ class _DynamicsPageState extends State<DynamicsPage>
)
],
),
Obx(
() => Visibility(
visible: _dynamicsController.userLogin.value,
child: Positioned(
right: 4,
top: 0,
bottom: 0,
child: IconButton(
padding: EdgeInsets.zero,
onPressed: () =>
{feedBack(), _dynamicsController.resetSearch()},
icon: const Icon(Icons.history, size: 21),
),
),
),
),
// Obx(
// () => Visibility(
// visible: _dynamicsController.userLogin.value,
// child: Positioned(
// right: 4,
// top: 0,
// bottom: 0,
// child: IconButton(
// padding: EdgeInsets.zero,
// onPressed: () =>
// {feedBack(), _dynamicsController.resetSearch()},
// icon: const Icon(Icons.history, size: 21),
// ),
// ),
// ),
// ),
],
),
),
@ -240,14 +239,24 @@ class _DynamicsPageState extends State<DynamicsPage>
List<DynamicItemModel> list =
_dynamicsController.dynamicsList;
return Obx(
() => list.isEmpty
? skeleton()
: SliverList(
delegate:
SliverChildBuilderDelegate((context, index) {
() {
if (list.isEmpty) {
if (_dynamicsController.isLoadingDynamic.value) {
return skeleton();
} else {
return const NoData();
}
} else {
return SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
return DynamicPanel(item: list[index]);
}, childCount: list.length),
},
childCount: list.length,
),
);
}
},
);
} else {
return HttpError(

View File

@ -31,7 +31,9 @@ class _UpPanelState extends State<UpPanel> {
void initState() {
super.initState();
upList = widget.upData!.upList!;
liveList = widget.upData!.liveUsers!.items!;
if (widget.upData!.liveUsers != null) {
liveList = widget.upData!.liveUsers!.items!;
}
upList.insert(
0,
UpItem(
@ -66,15 +68,20 @@ class _UpPanelState extends State<UpPanel> {
controller: scrollController,
children: [
const SizedBox(width: 10),
for (int i = 0; i < liveList.length; i++) ...[
upItemBuild(liveList[i], i)
if (liveList.isNotEmpty) ...[
for (int i = 0; i < liveList.length; i++) ...[
upItemBuild(liveList[i], i)
],
VerticalDivider(
indent: 20,
endIndent: 40,
width: 26,
color: Theme.of(context)
.colorScheme
.primary
.withOpacity(0.5),
),
],
VerticalDivider(
indent: 20,
endIndent: 40,
width: 26,
color: Theme.of(context).primaryColor.withOpacity(0.5),
),
for (int i = 0; i < upList.length; i++) ...[
upItemBuild(upList[i], i)
],
@ -125,7 +132,8 @@ class _UpPanelState extends State<UpPanel> {
double itemWidth = contentWidth + itemPadding.horizontal;
double screenWidth = MediaQuery.of(context).size.width;
double moveDistance = 0.0;
if ((upLen - i - 0.5) * itemWidth > screenWidth / 2) {
if (itemWidth * (upList.length + liveList.length) <= screenWidth) {
} else if ((upLen - i - 0.5) * itemWidth > screenWidth / 2) {
moveDistance =
(i + liveLen + 0.5) * itemWidth + 46 - screenWidth / 2;
} else {