fix: 点赞异常、动态课程内容渲染
This commit is contained in:
@ -408,6 +408,7 @@ class DynamicMajorModel {
|
|||||||
this.live,
|
this.live,
|
||||||
this.none,
|
this.none,
|
||||||
this.type,
|
this.type,
|
||||||
|
this.courses,
|
||||||
});
|
});
|
||||||
|
|
||||||
DynamicArchiveModel? archive;
|
DynamicArchiveModel? archive;
|
||||||
@ -422,6 +423,7 @@ class DynamicMajorModel {
|
|||||||
// MAJOR_TYPE_ARCHIVE 视频
|
// MAJOR_TYPE_ARCHIVE 视频
|
||||||
// MAJOR_TYPE_OPUS 图文/文章
|
// MAJOR_TYPE_OPUS 图文/文章
|
||||||
String? type;
|
String? type;
|
||||||
|
Map? courses;
|
||||||
|
|
||||||
DynamicMajorModel.fromJson(Map<String, dynamic> json) {
|
DynamicMajorModel.fromJson(Map<String, dynamic> json) {
|
||||||
archive = json['archive'] != null
|
archive = json['archive'] != null
|
||||||
@ -444,6 +446,7 @@ class DynamicMajorModel {
|
|||||||
none =
|
none =
|
||||||
json['none'] != null ? DynamicNoneModel.fromJson(json['none']) : null;
|
json['none'] != null ? DynamicNoneModel.fromJson(json['none']) : null;
|
||||||
type = json['type'];
|
type = json['type'];
|
||||||
|
courses = json['courses'] ?? {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -70,6 +70,10 @@ class DynamicsController extends GetxController {
|
|||||||
if (type == 'init') {
|
if (type == 'init') {
|
||||||
dynamicsList.clear();
|
dynamicsList.clear();
|
||||||
}
|
}
|
||||||
|
// 下拉刷新数据渲染时会触发onLoad
|
||||||
|
if (type == 'onLoad' && page == 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
isLoadingDynamic.value = true;
|
isLoadingDynamic.value = true;
|
||||||
var res = await DynamicsHttp.followDynamic(
|
var res = await DynamicsHttp.followDynamic(
|
||||||
page: type == 'init' ? 1 : page,
|
page: type == 'init' ? 1 : page,
|
||||||
@ -79,6 +83,10 @@ class DynamicsController extends GetxController {
|
|||||||
);
|
);
|
||||||
isLoadingDynamic.value = false;
|
isLoadingDynamic.value = false;
|
||||||
if (res['status']) {
|
if (res['status']) {
|
||||||
|
if (type == 'onLoad' && res['data'].items.isEmpty) {
|
||||||
|
SmartDialog.showToast('没有更多了');
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (type == 'init') {
|
if (type == 'init') {
|
||||||
dynamicsList.value = res['data'].items;
|
dynamicsList.value = res['data'].items;
|
||||||
} else {
|
} else {
|
||||||
@ -219,6 +227,7 @@ class DynamicsController extends GetxController {
|
|||||||
|
|
||||||
onRefresh() async {
|
onRefresh() async {
|
||||||
page = 1;
|
page = 1;
|
||||||
|
print('onRefresh');
|
||||||
await queryFollowUp();
|
await queryFollowUp();
|
||||||
await queryFollowDynamic();
|
await queryFollowDynamic();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:custom_sliding_segmented_control/custom_sliding_segmented_control.dart';
|
import 'package:custom_sliding_segmented_control/custom_sliding_segmented_control.dart';
|
||||||
|
import 'package:easy_debounce/easy_throttle.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
@ -30,7 +31,6 @@ class _DynamicsPageState extends State<DynamicsPage>
|
|||||||
final DynamicsController _dynamicsController = Get.put(DynamicsController());
|
final DynamicsController _dynamicsController = Get.put(DynamicsController());
|
||||||
late Future _futureBuilderFuture;
|
late Future _futureBuilderFuture;
|
||||||
late Future _futureBuilderFutureUp;
|
late Future _futureBuilderFutureUp;
|
||||||
bool _isLoadingMore = false;
|
|
||||||
Box userInfoCache = GStrorage.userInfo;
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
EventBus eventBus = EventBus();
|
EventBus eventBus = EventBus();
|
||||||
late ScrollController scrollController;
|
late ScrollController scrollController;
|
||||||
@ -50,11 +50,10 @@ class _DynamicsPageState extends State<DynamicsPage>
|
|||||||
() async {
|
() async {
|
||||||
if (scrollController.position.pixels >=
|
if (scrollController.position.pixels >=
|
||||||
scrollController.position.maxScrollExtent - 200) {
|
scrollController.position.maxScrollExtent - 200) {
|
||||||
if (!_isLoadingMore) {
|
EasyThrottle.throttle(
|
||||||
_isLoadingMore = true;
|
'queryFollowDynamic', const Duration(seconds: 1), () {
|
||||||
await _dynamicsController.queryFollowDynamic(type: 'onLoad');
|
_dynamicsController.queryFollowDynamic(type: 'onLoad');
|
||||||
_isLoadingMore = false;
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final ScrollDirection direction =
|
final ScrollDirection direction =
|
||||||
@ -277,6 +276,7 @@ class _DynamicsPageState extends State<DynamicsPage>
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
const SliverToBoxAdapter(child: SizedBox(height: 40))
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -37,7 +37,7 @@ class _ActionPanelState extends State<ActionPanel> {
|
|||||||
String dynamicId = item.idStr!;
|
String dynamicId = item.idStr!;
|
||||||
// 1 已点赞 2 不喜欢 0 未操作
|
// 1 已点赞 2 不喜欢 0 未操作
|
||||||
Like like = item.modules.moduleStat.like;
|
Like like = item.modules.moduleStat.like;
|
||||||
int count = int.parse(like.count!);
|
int count = like.count == '点赞' ? 0 : int.parse(like.count ?? '0');
|
||||||
bool status = like.status!;
|
bool status = like.status!;
|
||||||
int up = status ? 2 : 1;
|
int up = status ? 2 : 1;
|
||||||
var res = await DynamicsHttp.likeDynamic(dynamicId: dynamicId, up: up);
|
var res = await DynamicsHttp.likeDynamic(dynamicId: dynamicId, up: up);
|
||||||
@ -47,7 +47,11 @@ class _ActionPanelState extends State<ActionPanel> {
|
|||||||
item.modules.moduleStat.like.count = (count + 1).toString();
|
item.modules.moduleStat.like.count = (count + 1).toString();
|
||||||
item.modules.moduleStat.like.status = true;
|
item.modules.moduleStat.like.status = true;
|
||||||
} else {
|
} else {
|
||||||
item.modules.moduleStat.like.count = (count - 1).toString();
|
if (count == 1) {
|
||||||
|
item.modules.moduleStat.like.count = '点赞';
|
||||||
|
} else {
|
||||||
|
item.modules.moduleStat.like.count = (count - 1).toString();
|
||||||
|
}
|
||||||
item.modules.moduleStat.like.status = false;
|
item.modules.moduleStat.like.status = false;
|
||||||
}
|
}
|
||||||
setState(() {});
|
setState(() {});
|
||||||
@ -63,54 +67,63 @@ class _ActionPanelState extends State<ActionPanel> {
|
|||||||
return Row(
|
return Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||||
children: [
|
children: [
|
||||||
TextButton.icon(
|
Expanded(
|
||||||
onPressed: () {},
|
flex: 1,
|
||||||
icon: const Icon(
|
child: TextButton.icon(
|
||||||
FontAwesomeIcons.shareFromSquare,
|
onPressed: () {},
|
||||||
size: 16,
|
icon: const Icon(
|
||||||
|
FontAwesomeIcons.shareFromSquare,
|
||||||
|
size: 16,
|
||||||
|
),
|
||||||
|
style: TextButton.styleFrom(
|
||||||
|
padding: const EdgeInsets.fromLTRB(15, 0, 15, 0),
|
||||||
|
foregroundColor: Theme.of(context).colorScheme.outline,
|
||||||
|
),
|
||||||
|
label: Text(stat.forward!.count ?? '转发'),
|
||||||
),
|
),
|
||||||
style: TextButton.styleFrom(
|
|
||||||
padding: const EdgeInsets.fromLTRB(15, 0, 15, 0),
|
|
||||||
foregroundColor: Theme.of(context).colorScheme.outline,
|
|
||||||
),
|
|
||||||
label: Text(stat.forward!.count ?? '转发'),
|
|
||||||
),
|
),
|
||||||
TextButton.icon(
|
Expanded(
|
||||||
onPressed: () =>
|
flex: 1,
|
||||||
_dynamicsController.pushDetail(widget.item, 1, action: 'comment'),
|
child: TextButton.icon(
|
||||||
icon: const Icon(
|
onPressed: () => _dynamicsController.pushDetail(widget.item, 1,
|
||||||
FontAwesomeIcons.comment,
|
action: 'comment'),
|
||||||
size: 16,
|
icon: const Icon(
|
||||||
|
FontAwesomeIcons.comment,
|
||||||
|
size: 16,
|
||||||
|
),
|
||||||
|
style: TextButton.styleFrom(
|
||||||
|
padding: const EdgeInsets.fromLTRB(15, 0, 15, 0),
|
||||||
|
foregroundColor: Theme.of(context).colorScheme.outline,
|
||||||
|
),
|
||||||
|
label: Text(stat.comment!.count ?? '评论'),
|
||||||
),
|
),
|
||||||
style: TextButton.styleFrom(
|
|
||||||
padding: const EdgeInsets.fromLTRB(15, 0, 15, 0),
|
|
||||||
foregroundColor: Theme.of(context).colorScheme.outline,
|
|
||||||
),
|
|
||||||
label: Text(stat.comment!.count ?? '评论'),
|
|
||||||
),
|
),
|
||||||
TextButton.icon(
|
Expanded(
|
||||||
onPressed: () => onLikeDynamic(),
|
flex: 1,
|
||||||
icon: Icon(
|
child: TextButton.icon(
|
||||||
stat.like!.status!
|
onPressed: () => onLikeDynamic(),
|
||||||
? FontAwesomeIcons.solidThumbsUp
|
icon: Icon(
|
||||||
: FontAwesomeIcons.thumbsUp,
|
stat.like!.status!
|
||||||
size: 16,
|
? FontAwesomeIcons.solidThumbsUp
|
||||||
color: stat.like!.status! ? primary : color,
|
: FontAwesomeIcons.thumbsUp,
|
||||||
),
|
size: 16,
|
||||||
style: TextButton.styleFrom(
|
color: stat.like!.status! ? primary : color,
|
||||||
padding: const EdgeInsets.fromLTRB(15, 0, 15, 0),
|
),
|
||||||
foregroundColor: Theme.of(context).colorScheme.outline,
|
style: TextButton.styleFrom(
|
||||||
),
|
padding: const EdgeInsets.fromLTRB(15, 0, 15, 0),
|
||||||
label: AnimatedSwitcher(
|
foregroundColor: Theme.of(context).colorScheme.outline,
|
||||||
duration: const Duration(milliseconds: 400),
|
),
|
||||||
transitionBuilder: (Widget child, Animation<double> animation) {
|
label: AnimatedSwitcher(
|
||||||
return ScaleTransition(scale: animation, child: child);
|
duration: const Duration(milliseconds: 400),
|
||||||
},
|
transitionBuilder: (Widget child, Animation<double> animation) {
|
||||||
child: Text(
|
return ScaleTransition(scale: animation, child: child);
|
||||||
stat.like!.count ?? '点赞',
|
},
|
||||||
key: ValueKey<String>(stat.like!.count ?? '点赞'),
|
child: Text(
|
||||||
style: TextStyle(
|
stat.like!.count ?? '点赞',
|
||||||
color: stat.like!.status! ? primary : color,
|
key: ValueKey<String>(stat.like!.count ?? '点赞'),
|
||||||
|
style: TextStyle(
|
||||||
|
color: stat.like!.status! ? primary : color,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -100,6 +100,7 @@ Widget forWard(item, context, ctr, source, {floor = 1}) {
|
|||||||
// 直播
|
// 直播
|
||||||
case 'DYNAMIC_TYPE_LIVE_RCMD':
|
case 'DYNAMIC_TYPE_LIVE_RCMD':
|
||||||
return liveRcmdPanel(item, context, floor: floor);
|
return liveRcmdPanel(item, context, floor: floor);
|
||||||
|
// 直播
|
||||||
case 'DYNAMIC_TYPE_LIVE':
|
case 'DYNAMIC_TYPE_LIVE':
|
||||||
return livePanel(item, context, floor: floor);
|
return livePanel(item, context, floor: floor);
|
||||||
// 合集
|
// 合集
|
||||||
@ -147,6 +148,7 @@ Widget forWard(item, context, ctr, source, {floor = 1}) {
|
|||||||
return videoSeasonWidget(item, context, 'pgc', floor: floor);
|
return videoSeasonWidget(item, context, 'pgc', floor: floor);
|
||||||
case 'DYNAMIC_TYPE_PGC_UNION':
|
case 'DYNAMIC_TYPE_PGC_UNION':
|
||||||
return videoSeasonWidget(item, context, 'pgc', floor: floor);
|
return videoSeasonWidget(item, context, 'pgc', floor: floor);
|
||||||
|
// 直播结束
|
||||||
case 'DYNAMIC_TYPE_NONE':
|
case 'DYNAMIC_TYPE_NONE':
|
||||||
return Row(
|
return Row(
|
||||||
children: [
|
children: [
|
||||||
@ -158,7 +160,23 @@ Widget forWard(item, context, ctr, source, {floor = 1}) {
|
|||||||
Text(item.modules.moduleDynamic.major.none.tips)
|
Text(item.modules.moduleDynamic.major.none.tips)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
// 课堂
|
||||||
|
case 'DYNAMIC_TYPE_COURSES_SEASON':
|
||||||
|
return Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
"课堂💪:${item.modules.moduleDynamic.major.courses['title']}",
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
default:
|
default:
|
||||||
return const SizedBox(height: 0);
|
return const SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
child: Text('🙏 暂未支持的类型,请联系开发者反馈 '),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user