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

@@ -17,10 +17,12 @@ class LiveAreaChildPage extends StatefulWidget {
super.key,
required this.areaId,
required this.parentAreaId,
required this.showFirstFrame,
});
final dynamic areaId;
final dynamic parentAreaId;
final bool showFirstFrame;
@override
State<LiveAreaChildPage> createState() => _LiveAreaChildPageState();
@@ -120,7 +122,10 @@ class _LiveAreaChildPageState extends State<LiveAreaChildPage>
if (index == response.length - 1) {
_controller.onLoadMore();
}
return LiveCardVApp(item: response[index]);
return LiveCardVApp(
item: response[index],
showFirstFrame: widget.showFirstFrame,
);
},
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/models_new/live/live_area_list/area_item.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
extends CommonListController<List<AreaItem>?, AreaItem> {
extends CommonListController<List<AreaItem>?, AreaItem>
with GetSingleTickerProviderStateMixin {
LiveAreaDetailController(this.areaId, this.parentAreaId);
final dynamic areaId;
final dynamic parentAreaId;
late int initialIndex = 0;
TabController? tabController;
bool showFirstFrame = false;
@override
void onInit() {
@@ -22,7 +27,13 @@ class LiveAreaDetailController
@override
List<AreaItem>? getDataList(List<AreaItem>? response) {
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;
}
@@ -30,4 +41,11 @@ class LiveAreaDetailController
@override
Future<LoadingState<List<AreaItem>?>> customGetData() =>
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:flutter/material.dart';
import 'package:get/get.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
class LiveAreaDetailPage extends StatefulWidget {
const LiveAreaDetailPage({
@@ -73,71 +74,81 @@ class _LiveAreaDetailPageState extends State<LiveAreaDetailPage> {
Loading() => const SizedBox.shrink(),
Success(:final response) =>
response != null && response.isNotEmpty
? DefaultTabController(
initialIndex: _controller.initialIndex,
length: response.length,
child: Builder(
builder: (context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: TabBar(
dividerHeight: 0,
dividerColor: Colors.transparent,
isScrollable: true,
tabAlignment: TabAlignment.start,
tabs: response
.map((e) => Tab(text: e.name ?? ''))
.toList(),
onTap: (index) {
try {
if (!DefaultTabController.of(
context,
).indexIsChanging) {
final item = response[index];
Get.find<LiveAreaChildController>(
tag: '${item.id}${item.parentId}',
).animateToTop();
}
} catch (_) {}
},
),
),
iconButton(
icon: const Icon(Icons.menu),
onPressed: () =>
_showTags(context, theme, bottom, response),
),
],
? Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: TabBar(
dividerHeight: 0,
isScrollable: true,
tabAlignment: TabAlignment.start,
dividerColor: Colors.transparent,
controller: _controller.tabController,
tabs: response
.map((e) => Tab(text: e.name ?? ''))
.toList(),
onTap: (index) {
try {
if (!_controller.tabController!.indexIsChanging) {
final item = response[index];
Get.find<LiveAreaChildController>(
tag: '${item.id}${item.parentId}',
).animateToTop();
}
} catch (_) {}
},
),
const Divider(height: 1),
Expanded(
child: tabBarView(
children: response
.map(
(e) => LiveAreaChildPage(
areaId: e.id,
parentAreaId: e.parentId,
),
)
.toList(),
),
),
],
);
},
),
),
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),
onPressed: () =>
_showTags(context, theme, bottom, response),
),
],
),
const Divider(height: 1),
Expanded(
child: tabBarView(
controller: _controller.tabController,
children: response
.map(
(e) => LiveAreaChildPage(
areaId: e.id,
parentAreaId: e.parentId,
showFirstFrame: _controller.showFirstFrame,
),
)
.toList(),
),
),
],
)
: LiveAreaChildPage(
areaId: widget.areaId,
parentAreaId: widget.parentAreaId,
showFirstFrame: _controller.showFirstFrame,
),
Error() => LiveAreaChildPage(
areaId: widget.areaId,
parentAreaId: widget.parentAreaId,
showFirstFrame: _controller.showFirstFrame,
),
};
}
@@ -226,7 +237,7 @@ class _LiveAreaDetailPageState extends State<LiveAreaDetailPage> {
item: list[index],
onTap: () {
Get.back();
DefaultTabController.of(context).index = index;
_controller.tabController?.index = index;
},
);
},