opt: fav panel: use DraggableScrollableSheet

This commit is contained in:
bggRGjQaUbCoE
2024-10-01 11:59:27 +08:00
parent 793f1a340f
commit 832b20fc12
4 changed files with 191 additions and 126 deletions

View File

@@ -117,7 +117,8 @@ class BangumiInfo extends StatefulWidget {
State<BangumiInfo> createState() => _BangumiInfoState(); State<BangumiInfo> createState() => _BangumiInfoState();
} }
class _BangumiInfoState extends State<BangumiInfo> { class _BangumiInfoState extends State<BangumiInfo>
with SingleTickerProviderStateMixin {
String heroTag = Get.arguments['heroTag']; String heroTag = Get.arguments['heroTag'];
late final BangumiIntroController bangumiIntroController; late final BangumiIntroController bangumiIntroController;
late final VideoDetailController videoDetailCtr; late final VideoDetailController videoDetailCtr;
@@ -157,10 +158,28 @@ class _BangumiInfoState extends State<BangumiInfo> {
} }
showModalBottomSheet( showModalBottomSheet(
context: context, context: context,
useRootNavigator: true, useSafeArea: true,
isScrollControlled: true, isScrollControlled: true,
transitionAnimationController: AnimationController(
duration: const Duration(milliseconds: 200),
vsync: this,
),
sheetAnimationStyle: AnimationStyle(curve: Curves.ease),
builder: (BuildContext context) { builder: (BuildContext context) {
return FavPanel(ctr: bangumiIntroController); return DraggableScrollableSheet(
minChildSize: 0,
maxChildSize: 1,
initialChildSize: 0.6,
snap: true,
expand: false,
snapSizes: const [0.6],
builder: (BuildContext context, ScrollController scrollController) {
return FavPanel(
ctr: bangumiIntroController,
scrollController: scrollController,
);
},
);
}, },
); );
} }

View File

@@ -216,7 +216,7 @@ class _RepostPanelState extends State<RepostPanel> {
?.url; ?.url;
return AnimatedSize( return AnimatedSize(
alignment: Alignment.topCenter, alignment: Alignment.topCenter,
curve: Curves.linearToEaseOut, curve: Curves.ease,
duration: const Duration(milliseconds: 300), duration: const Duration(milliseconds: 300),
child: Column( child: Column(
mainAxisSize: _isMax ? MainAxisSize.max : MainAxisSize.min, mainAxisSize: _isMax ? MainAxisSize.max : MainAxisSize.min,
@@ -345,7 +345,10 @@ class _RepostPanelState extends State<RepostPanel> {
padding: const EdgeInsets.all(10), padding: const EdgeInsets.all(10),
margin: const EdgeInsets.symmetric(horizontal: 16), margin: const EdgeInsets.symmetric(horizontal: 16),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Theme.of(context).colorScheme.onInverseSurface, color: Theme.of(context).colorScheme.surfaceContainerHigh ==
Theme.of(context).colorScheme.surface
? Theme.of(context).colorScheme.onInverseSurface
: Theme.of(context).colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
), ),
child: Row( child: Row(

View File

@@ -42,7 +42,7 @@ class VideoIntroPanel extends StatefulWidget {
} }
class _VideoIntroPanelState extends State<VideoIntroPanel> class _VideoIntroPanelState extends State<VideoIntroPanel>
with AutomaticKeepAliveClientMixin { with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin {
late String heroTag; late String heroTag;
late VideoIntroController videoIntroController; late VideoIntroController videoIntroController;
VideoDetailData? videoDetail; VideoDetailData? videoDetail;
@@ -164,6 +164,33 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
enableAi = setting.get(SettingBoxKey.enableAi, defaultValue: true); enableAi = setting.get(SettingBoxKey.enableAi, defaultValue: true);
} }
void _showFavBottomSheet() => showModalBottomSheet(
context: context,
useSafeArea: true,
isScrollControlled: true,
transitionAnimationController: AnimationController(
duration: const Duration(milliseconds: 200),
vsync: this,
),
sheetAnimationStyle: AnimationStyle(curve: Curves.ease),
builder: (BuildContext context) {
return DraggableScrollableSheet(
minChildSize: 0,
maxChildSize: 1,
initialChildSize: 0.6,
snap: true,
expand: false,
snapSizes: const [0.6],
builder: (BuildContext context, ScrollController scrollController) {
return FavPanel(
ctr: videoIntroController,
scrollController: scrollController,
);
},
);
},
);
// 收藏 // 收藏
showFavBottomSheet({type = 'tap'}) { showFavBottomSheet({type = 'tap'}) {
if (videoIntroController.userInfo == null) { if (videoIntroController.userInfo == null) {
@@ -179,24 +206,10 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
if (type == 'tap') { if (type == 'tap') {
videoIntroController.actionFavVideo(type: 'default'); videoIntroController.actionFavVideo(type: 'default');
} else { } else {
showModalBottomSheet( _showFavBottomSheet();
context: context,
useRootNavigator: true,
isScrollControlled: true,
builder: (BuildContext context) {
return FavPanel(ctr: videoIntroController);
},
);
} }
} else if (type != 'longPress') { } else if (type != 'longPress') {
showModalBottomSheet( _showFavBottomSheet();
context: context,
useRootNavigator: true,
isScrollControlled: true,
builder: (BuildContext context) {
return FavPanel(ctr: videoIntroController);
},
);
} }
} }

View File

@@ -6,8 +6,14 @@ import 'package:PiliPalaX/utils/feed_back.dart';
import '../../../../../utils/utils.dart'; import '../../../../../utils/utils.dart';
class FavPanel extends StatefulWidget { class FavPanel extends StatefulWidget {
const FavPanel({super.key, this.ctr}); const FavPanel({
super.key,
this.ctr,
this.scrollController,
});
final dynamic ctr; final dynamic ctr;
final ScrollController? scrollController;
@override @override
State<FavPanel> createState() => _FavPanelState(); State<FavPanel> createState() => _FavPanelState();
@@ -24,20 +30,34 @@ class _FavPanelState extends State<FavPanel> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return NotificationListener<DraggableScrollableNotification>(
height: Utils.getSheetHeight(context), onNotification: (notification) {
if (notification.extent <= 1e-5) {
Get.back();
}
return false;
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(18),
color: Theme.of(context).colorScheme.surface, color: Theme.of(context).colorScheme.surface,
),
child: Column( child: Column(
children: [ children: [
AppBar( AppBar(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(18),
),
),
centerTitle: false, centerTitle: false,
elevation: 0, elevation: 0,
leading: IconButton( leading: IconButton(
tooltip: '关闭', tooltip: '关闭',
onPressed: () => Get.back(), onPressed: () => Get.back(),
icon: const Icon(Icons.close_outlined)), icon: const Icon(Icons.close_outlined)),
title: title: Text('添加到收藏夹',
Text('添加到收藏夹', style: Theme.of(context).textTheme.titleMedium), style: Theme.of(context).textTheme.titleMedium),
), ),
Expanded( Expanded(
child: Material( child: Material(
@@ -49,6 +69,7 @@ class _FavPanelState extends State<FavPanel> {
if (data['status']) { if (data['status']) {
return Obx( return Obx(
() => ListView.builder( () => ListView.builder(
controller: widget.scrollController,
itemCount: itemCount:
widget.ctr!.favFolderData.value.list!.length, widget.ctr!.favFolderData.value.list!.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
@@ -72,8 +93,8 @@ class _FavPanelState extends State<FavPanel> {
value: widget.ctr!.favFolderData.value value: widget.ctr!.favFolderData.value
.list![index].favState == .list![index].favState ==
1, 1,
onChanged: (bool? checkValue) => onChanged: (bool? checkValue) => widget.ctr!
widget.ctr!.onChoose(checkValue!, index), .onChoose(checkValue!, index),
), ),
), ),
); );
@@ -111,24 +132,32 @@ class _FavPanelState extends State<FavPanel> {
TextButton( TextButton(
onPressed: () => Get.back(), onPressed: () => Get.back(),
style: TextButton.styleFrom( style: TextButton.styleFrom(
padding: const EdgeInsets.only(left: 30, right: 30), padding: const EdgeInsets.symmetric(
horizontal: 20, vertical: 10),
visualDensity: const VisualDensity(
horizontal: -1,
vertical: -2,
),
foregroundColor: Theme.of(context).colorScheme.outline,
backgroundColor: Theme.of(context) backgroundColor: Theme.of(context)
.colorScheme .colorScheme
.onInverseSurface, // 设置按钮背景色 .onInverseSurface, // 设置按钮背景色
), ),
child: const Text('取消'), child: const Text('取消'),
), ),
const SizedBox(width: 10), const SizedBox(width: 25),
TextButton( FilledButton.tonal(
onPressed: () async { onPressed: () async {
feedBack(); feedBack();
await widget.ctr!.actionFavVideo(); await widget.ctr!.actionFavVideo();
}, },
style: TextButton.styleFrom( style: FilledButton.styleFrom(
padding: const EdgeInsets.only(left: 30, right: 30), padding: const EdgeInsets.symmetric(
foregroundColor: Theme.of(context).colorScheme.onPrimary, horizontal: 20, vertical: 10),
backgroundColor: visualDensity: const VisualDensity(
Theme.of(context).colorScheme.primary, // 设置按钮背景色 horizontal: -1,
vertical: -2,
),
), ),
child: const Text('完成'), child: const Text('完成'),
), ),
@@ -137,6 +166,7 @@ class _FavPanelState extends State<FavPanel> {
), ),
], ],
), ),
),
); );
} }
} }