live first frame

Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
dom
2026-03-10 11:35:24 +08:00
parent 98ce99202e
commit 3090cfc6f9
9 changed files with 215 additions and 138 deletions

View File

@@ -1,4 +1,5 @@
import 'package:PiliPlus/models_new/live/live_feed_index/watched_show.dart'; import 'package:PiliPlus/models_new/live/live_feed_index/watched_show.dart';
import 'package:PiliPlus/utils/parse_string.dart';
class CardLiveItem { class CardLiveItem {
int? roomid; int? roomid;
@@ -6,6 +7,7 @@ class CardLiveItem {
String? uname; String? uname;
String? face; String? face;
String? cover; String? cover;
String? systemCover;
String? title; String? title;
int? liveTime; int? liveTime;
String? areaName; String? areaName;
@@ -21,6 +23,7 @@ class CardLiveItem {
this.uname, this.uname,
this.face, this.face,
this.cover, this.cover,
this.systemCover,
this.title, this.title,
this.liveTime, this.liveTime,
this.areaName, this.areaName,
@@ -37,6 +40,7 @@ class CardLiveItem {
uname: json['uname'] as String?, uname: json['uname'] as String?,
face: json['face'] as String?, face: json['face'] as String?,
cover: json['cover'] as String?, cover: json['cover'] as String?,
systemCover: noneNullOrEmptyString(json['system_cover']),
title: json['title'] as String?, title: json['title'] as String?,
liveTime: json['live_time'] as int?, liveTime: json['live_time'] as int?,
areaName: json['area_name'] as String?, areaName: json['area_name'] as String?,

View File

@@ -36,6 +36,8 @@ class LiveController extends CommonListController with AccountMixin {
final followController = ScrollController(); final followController = ScrollController();
bool showFirstFrame = false;
@override @override
void checkIsEnd(int length) { void checkIsEnd(int length) {
if (count != null && length >= count!) { if (count != null && length >= count!) {

View File

@@ -21,6 +21,7 @@ import 'package:PiliPlus/utils/platform_utils.dart';
import 'package:PiliPlus/utils/utils.dart'; import 'package:PiliPlus/utils/utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
class LivePage extends StatefulWidget { class LivePage extends StatefulWidget {
const LivePage({super.key}); const LivePage({super.key});
@@ -128,6 +129,20 @@ class _LivePageState extends State<LivePage>
}), }),
), ),
), ),
iconButton(
size: 26,
iconSize: 18,
context: context,
tooltip: '切换${controller.showFirstFrame ? '封面' : '首帧'}',
icon: controller.showFirstFrame
? const Icon(MdiIcons.alphaFBox)
: const Icon(MdiIcons.image),
onPressed: () {
controller.showFirstFrame = !controller.showFirstFrame;
setState(() {});
},
),
const SizedBox(width: 8),
iconButton( iconButton(
size: 26, size: 26,
iconSize: 16, iconSize: 16,
@@ -224,9 +239,13 @@ class _LivePageState extends State<LivePage>
if (item is LiveCardList) { if (item is LiveCardList) {
return LiveCardVApp( return LiveCardVApp(
item: item.cardData!.smallCardV1!, item: item.cardData!.smallCardV1!,
showFirstFrame: controller.showFirstFrame,
); );
} }
return LiveCardVApp(item: item); return LiveCardVApp(
item: item,
showFirstFrame: controller.showFirstFrame,
);
}, },
itemCount: response.length, itemCount: response.length,
) )

View File

@@ -10,10 +10,12 @@ import 'package:flutter/material.dart' hide LayoutBuilder;
// 视频卡片 - 垂直布局 // 视频卡片 - 垂直布局
class LiveCardVApp extends StatelessWidget { class LiveCardVApp extends StatelessWidget {
final CardLiveItem item; final CardLiveItem item;
final bool showFirstFrame;
const LiveCardVApp({ const LiveCardVApp({
super.key, super.key,
required this.item, required this.item,
this.showFirstFrame = false,
}); });
@override @override
@@ -40,7 +42,9 @@ class LiveCardVApp extends StatelessWidget {
clipBehavior: Clip.none, clipBehavior: Clip.none,
children: [ children: [
NetworkImgLayer( NetworkImgLayer(
src: item.cover!, src: showFirstFrame
? (item.systemCover ?? item.cover)
: item.cover,
width: maxWidth, width: maxWidth,
height: maxHeight, height: maxHeight,
type: .emote, type: .emote,

View File

@@ -4,16 +4,19 @@ import 'package:PiliPlus/models_new/live/live_area_list/area_item.dart';
import 'package:PiliPlus/models_new/live/live_area_list/area_list.dart'; import 'package:PiliPlus/models_new/live/live_area_list/area_list.dart';
import 'package:PiliPlus/pages/common/common_list_controller.dart'; import 'package:PiliPlus/pages/common/common_list_controller.dart';
import 'package:PiliPlus/utils/accounts.dart'; import 'package:PiliPlus/utils/accounts.dart';
import 'package:flutter/material.dart' show TabController;
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
class LiveAreaController class LiveAreaController extends CommonListController<List<AreaList>?, AreaList>
extends CommonListController<List<AreaList>?, AreaList> { with GetSingleTickerProviderStateMixin {
late final isLogin = Accounts.main.isLogin; late final isLogin = Accounts.main.isLogin;
late final isEditing = false.obs; late final isEditing = false.obs;
late final favInfo = {}; late final favInfo = {};
TabController? tabController;
@override @override
void onInit() { void onInit() {
super.onInit(); super.onInit();
@@ -31,6 +34,16 @@ class LiveAreaController
return super.onRefresh(); return super.onRefresh();
} }
@override
bool customHandleResponse(bool isRefresh, Success<List<AreaList>?> response) {
assert(tabController == null);
final length = response.response?.length;
if (length != null && length != 0) {
tabController = TabController(length: length, vsync: this);
}
return super.customHandleResponse(isRefresh, response);
}
Rx<LoadingState<List<AreaItem>>> favState = Rx<LoadingState<List<AreaItem>>> favState =
LoadingState<List<AreaItem>>.loading().obs; LoadingState<List<AreaItem>>.loading().obs;
@@ -65,4 +78,11 @@ class LiveAreaController
isEditing.value = !isEditing.value; isEditing.value = !isEditing.value;
} }
} }
@override
void onClose() {
tabController?.dispose();
tabController = null;
super.onClose();
}
} }

View File

@@ -80,18 +80,18 @@ class _LiveAreaPageState extends State<LiveAreaPage> {
Loading() => const SizedBox.shrink(), Loading() => const SizedBox.shrink(),
Success(:final response) => Success(:final response) =>
response != null && response.isNotEmpty response != null && response.isNotEmpty
? DefaultTabController( ? Column(
length: response.length,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
TabBar( TabBar(
isScrollable: true, isScrollable: true,
tabAlignment: TabAlignment.start, tabAlignment: TabAlignment.start,
controller: _controller.tabController,
tabs: response.map((e) => Tab(text: e.name)).toList(), tabs: response.map((e) => Tab(text: e.name)).toList(),
), ),
Expanded( Expanded(
child: tabBarView( child: tabBarView(
controller: _controller.tabController,
children: response children: response
.map( .map(
(e) => KeepAliveWrapper( (e) => KeepAliveWrapper(
@@ -122,21 +122,18 @@ class _LiveAreaPageState extends State<LiveAreaPage> {
bool? isFav = bool? isFav =
_controller.favInfo[item.id]; _controller.favInfo[item.id];
if (isFav == true) { if (isFav == true) {
_controller.favInfo[item.id] = _controller.favInfo[item.id] = false;
false;
_controller.favState _controller.favState
..value.data.remove(item) ..value.data.remove(item)
..refresh(); ..refresh();
(context as Element) (context as Element).markNeedsBuild();
.markNeedsBuild();
} else { } else {
// check // check
if (_controller if (_controller
.favState .favState
.value .value
.isSuccess) { .isSuccess) {
_controller.favInfo[item.id] = _controller.favInfo[item.id] = true;
true;
_controller.favState _controller.favState
..value.data.add(item) ..value.data.add(item)
..refresh(); ..refresh();
@@ -155,7 +152,6 @@ class _LiveAreaPageState extends State<LiveAreaPage> {
), ),
), ),
], ],
),
) )
: scrollErrorWidget(onReload: _controller.onReload), : scrollErrorWidget(onReload: _controller.onReload),
Error(:final errMsg) => scrollErrorWidget( Error(:final errMsg) => scrollErrorWidget(
@@ -192,9 +188,7 @@ class _LiveAreaPageState extends State<LiveAreaPage> {
const SizedBox(height: 8), const SizedBox(height: 8),
if (response != null && response.isNotEmpty) ...[ if (response != null && response.isNotEmpty) ...[
SortableWrap( SortableWrap(
onSortStart: (index) { onSortStart: (index) => _controller.isEditing.value = true,
_controller.isEditing.value = true;
},
onSorted: (int oldIndex, int newIndex) { onSorted: (int oldIndex, int newIndex) {
response.insert(newIndex, response.removeAt(oldIndex)); response.insert(newIndex, response.removeAt(oldIndex));
}, },

View File

@@ -17,10 +17,12 @@ class LiveAreaChildPage extends StatefulWidget {
super.key, super.key,
required this.areaId, required this.areaId,
required this.parentAreaId, required this.parentAreaId,
required this.showFirstFrame,
}); });
final dynamic areaId; final dynamic areaId;
final dynamic parentAreaId; final dynamic parentAreaId;
final bool showFirstFrame;
@override @override
State<LiveAreaChildPage> createState() => _LiveAreaChildPageState(); State<LiveAreaChildPage> createState() => _LiveAreaChildPageState();
@@ -120,7 +122,10 @@ class _LiveAreaChildPageState extends State<LiveAreaChildPage>
if (index == response.length - 1) { if (index == response.length - 1) {
_controller.onLoadMore(); _controller.onLoadMore();
} }
return LiveCardVApp(item: response[index]); return LiveCardVApp(
item: response[index],
showFirstFrame: widget.showFirstFrame,
);
}, },
itemCount: response.length, itemCount: response.length,
) )

View File

@@ -4,14 +4,19 @@ import 'package:PiliPlus/http/live.dart';
import 'package:PiliPlus/http/loading_state.dart'; import 'package:PiliPlus/http/loading_state.dart';
import 'package:PiliPlus/models_new/live/live_area_list/area_item.dart'; import 'package:PiliPlus/models_new/live/live_area_list/area_item.dart';
import 'package:PiliPlus/pages/common/common_list_controller.dart'; import 'package:PiliPlus/pages/common/common_list_controller.dart';
import 'package:flutter/material.dart' show TabController;
import 'package:get/get_state_manager/src/rx_flutter/rx_ticket_provider_mixin.dart';
class LiveAreaDetailController class LiveAreaDetailController
extends CommonListController<List<AreaItem>?, AreaItem> { extends CommonListController<List<AreaItem>?, AreaItem>
with GetSingleTickerProviderStateMixin {
LiveAreaDetailController(this.areaId, this.parentAreaId); LiveAreaDetailController(this.areaId, this.parentAreaId);
final dynamic areaId; final dynamic areaId;
final dynamic parentAreaId; final dynamic parentAreaId;
late int initialIndex = 0; TabController? tabController;
bool showFirstFrame = false;
@override @override
void onInit() { void onInit() {
@@ -22,7 +27,13 @@ class LiveAreaDetailController
@override @override
List<AreaItem>? getDataList(List<AreaItem>? response) { List<AreaItem>? getDataList(List<AreaItem>? response) {
if (response != null && response.isNotEmpty) { if (response != null && response.isNotEmpty) {
initialIndex = max(0, response.indexWhere((e) => e.id == areaId)); assert(tabController == null);
final initialIndex = max(0, response.indexWhere((e) => e.id == areaId));
tabController = TabController(
length: response.length,
initialIndex: initialIndex,
vsync: this,
);
} }
return response; return response;
} }
@@ -30,4 +41,11 @@ class LiveAreaDetailController
@override @override
Future<LoadingState<List<AreaItem>?>> customGetData() => Future<LoadingState<List<AreaItem>?>> customGetData() =>
LiveHttp.liveRoomAreaList(parentid: parentAreaId); LiveHttp.liveRoomAreaList(parentid: parentAreaId);
@override
void onClose() {
tabController?.dispose();
tabController = null;
super.onClose();
}
} }

View File

@@ -10,6 +10,7 @@ import 'package:PiliPlus/pages/live_area_detail/controller.dart';
import 'package:PiliPlus/pages/live_search/view.dart'; import 'package:PiliPlus/pages/live_search/view.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
class LiveAreaDetailPage extends StatefulWidget { class LiveAreaDetailPage extends StatefulWidget {
const LiveAreaDetailPage({ const LiveAreaDetailPage({
@@ -73,12 +74,7 @@ class _LiveAreaDetailPageState extends State<LiveAreaDetailPage> {
Loading() => const SizedBox.shrink(), Loading() => const SizedBox.shrink(),
Success(:final response) => Success(:final response) =>
response != null && response.isNotEmpty response != null && response.isNotEmpty
? DefaultTabController( ? Column(
initialIndex: _controller.initialIndex,
length: response.length,
child: Builder(
builder: (context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Row( Row(
@@ -86,17 +82,16 @@ class _LiveAreaDetailPageState extends State<LiveAreaDetailPage> {
Expanded( Expanded(
child: TabBar( child: TabBar(
dividerHeight: 0, dividerHeight: 0,
dividerColor: Colors.transparent,
isScrollable: true, isScrollable: true,
tabAlignment: TabAlignment.start, tabAlignment: TabAlignment.start,
dividerColor: Colors.transparent,
controller: _controller.tabController,
tabs: response tabs: response
.map((e) => Tab(text: e.name ?? '')) .map((e) => Tab(text: e.name ?? ''))
.toList(), .toList(),
onTap: (index) { onTap: (index) {
try { try {
if (!DefaultTabController.of( if (!_controller.tabController!.indexIsChanging) {
context,
).indexIsChanging) {
final item = response[index]; final item = response[index];
Get.find<LiveAreaChildController>( Get.find<LiveAreaChildController>(
tag: '${item.id}${item.parentId}', tag: '${item.id}${item.parentId}',
@@ -107,6 +102,21 @@ class _LiveAreaDetailPageState extends State<LiveAreaDetailPage> {
), ),
), ),
iconButton( iconButton(
iconSize: 20,
tooltip:
'切换${_controller.showFirstFrame ? '封面' : '首帧'}',
icon: _controller.showFirstFrame
? const Icon(MdiIcons.alphaFBox)
: const Icon(MdiIcons.image),
onPressed: () {
_controller.showFirstFrame =
!_controller.showFirstFrame;
setState(() {});
},
),
iconButton(
iconSize: 20,
tooltip: '显示菜单',
icon: const Icon(Icons.menu), icon: const Icon(Icons.menu),
onPressed: () => onPressed: () =>
_showTags(context, theme, bottom, response), _showTags(context, theme, bottom, response),
@@ -116,28 +126,29 @@ class _LiveAreaDetailPageState extends State<LiveAreaDetailPage> {
const Divider(height: 1), const Divider(height: 1),
Expanded( Expanded(
child: tabBarView( child: tabBarView(
controller: _controller.tabController,
children: response children: response
.map( .map(
(e) => LiveAreaChildPage( (e) => LiveAreaChildPage(
areaId: e.id, areaId: e.id,
parentAreaId: e.parentId, parentAreaId: e.parentId,
showFirstFrame: _controller.showFirstFrame,
), ),
) )
.toList(), .toList(),
), ),
), ),
], ],
);
},
),
) )
: LiveAreaChildPage( : LiveAreaChildPage(
areaId: widget.areaId, areaId: widget.areaId,
parentAreaId: widget.parentAreaId, parentAreaId: widget.parentAreaId,
showFirstFrame: _controller.showFirstFrame,
), ),
Error() => LiveAreaChildPage( Error() => LiveAreaChildPage(
areaId: widget.areaId, areaId: widget.areaId,
parentAreaId: widget.parentAreaId, parentAreaId: widget.parentAreaId,
showFirstFrame: _controller.showFirstFrame,
), ),
}; };
} }
@@ -226,7 +237,7 @@ class _LiveAreaDetailPageState extends State<LiveAreaDetailPage> {
item: list[index], item: list[index],
onTap: () { onTap: () {
Get.back(); Get.back();
DefaultTabController.of(context).index = index; _controller.tabController?.index = index;
}, },
); );
}, },