import 'package:PiliPlus/common/widgets/scroll_physics.dart'; import 'package:PiliPlus/http/loading_state.dart'; import 'package:PiliPlus/models/common/fav_type.dart'; import 'package:PiliPlus/models/user/fav_folder.dart'; import 'package:PiliPlus/pages/fav/video/controller.dart'; import 'package:PiliPlus/pages/fav_folder_sort/view.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; class FavPage extends StatefulWidget { const FavPage({super.key}); @override State createState() => _FavPageState(); } class _FavPageState extends State with SingleTickerProviderStateMixin { late final TabController _tabController; final FavController _favController = Get.put(FavController()); late final RxBool _showVideoFavMenu; void listener() { _showVideoFavMenu.value = _tabController.index == 0; } @override void initState() { super.initState(); int initialIndex = Get.arguments is int ? Get.arguments as int : 0; _showVideoFavMenu = (initialIndex == 0).obs; _tabController = TabController( length: FavTabType.values.length, vsync: this, initialIndex: initialIndex, ); _tabController.addListener(listener); } @override void dispose() { _tabController ..removeListener(listener) ..dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('我的收藏'), actions: [ Obx( () => _showVideoFavMenu.value ? IconButton( onPressed: () { Get.toNamed('/createFav')?.then( (data) { if (data != null) { List list = _favController .loadingState.value is Success ? (_favController.loadingState.value as Success) .response : []; list.insert(list.isNotEmpty ? 1 : 0, data); _favController.loadingState.refresh(); } }, ); }, icon: const Icon(Icons.add), tooltip: '新建收藏夹', ) : const SizedBox.shrink(), ), Obx( () => _showVideoFavMenu.value ? IconButton( onPressed: () { Get.to(FavFolderSortPage(favController: _favController)); }, icon: const Icon(Icons.sort), tooltip: '收藏夹排序', ) : const SizedBox.shrink(), ), Obx( () => _showVideoFavMenu.value ? IconButton( onPressed: () { if (_favController.loadingState.value is Success) { try { final item = (_favController.loadingState.value as Success) .response .first; Get.toNamed( '/favSearch', arguments: { 'type': 1, 'mediaId': item.id, 'title': item.title, 'count': item.mediaCount, 'isOwner': true, }, ); } catch (_) {} } }, icon: const Icon(Icons.search_outlined), tooltip: '搜索', ) : const SizedBox.shrink(), ), const SizedBox(width: 6), ], bottom: TabBar( controller: _tabController, tabs: FavTabType.values.map((item) => Tab(text: item.title)).toList(), ), ), body: SafeArea( top: false, bottom: false, child: tabBarView( controller: _tabController, children: FavTabType.values.map((item) => item.page).toList(), ), ), ); } }