Skip to content

Commit

Permalink
fix: 关闭弹出层错误
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Jan 12, 2025
1 parent 0965952 commit 91fe501
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 64 deletions.
11 changes: 6 additions & 5 deletions lib/common/widgets/list_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ListSheet {
aid: aid,
currentCid: currentCid,
changeFucCall: changeFucCall,
onClose: SmartDialog.dismiss,
// onClose: SmartDialog.dismiss,
));
}
}
Expand All @@ -50,15 +50,15 @@ class ListSheetContent extends StatefulWidget {
this.aid,
required this.currentCid,
required this.changeFucCall,
required this.onClose,
// required this.onClose,
});

final dynamic episodes;
final String? bvid;
final int? aid;
final int currentCid;
final Function changeFucCall;
final Function() onClose;
// final Function() onClose;

@override
State<ListSheetContent> createState() => _ListSheetContentState();
Expand Down Expand Up @@ -112,7 +112,8 @@ class _ListSheetContentState extends State<ListSheetContent> {
}
}
SmartDialog.showToast('切换到:$title');
widget.onClose();
// widget.onClose();
Get.back();
if (episode.runtimeType.toString() == "EpisodeItem") {
widget.changeFucCall(episode.bvid, episode.cid, episode.aid);
} else {
Expand Down Expand Up @@ -218,7 +219,7 @@ class _ListSheetContentState extends State<ListSheetContent> {
IconButton(
tooltip: '关闭',
icon: const Icon(Icons.close),
onPressed: widget.onClose,
onPressed: Get.back,
),
],
),
Expand Down
5 changes: 2 additions & 3 deletions lib/common/widgets/overlay_pop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import '../constants.dart';
import 'network_img_layer.dart';

class OverlayPop extends StatelessWidget {
const OverlayPop({super.key, this.videoItem, this.closeFn});
const OverlayPop({super.key, this.videoItem});

final dynamic videoItem;
final Function? closeFn;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -55,7 +54,7 @@ class OverlayPop extends StatelessWidget {
style: ButtonStyle(
padding: WidgetStateProperty.all(EdgeInsets.zero),
),
onPressed: () => closeFn!(),
onPressed: Get.back,
icon: const Icon(
Icons.close,
size: 18,
Expand Down
7 changes: 1 addition & 6 deletions lib/common/widgets/video_card_h.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,7 @@ class VideoCardH extends StatelessWidget {
useSystem: true,
alignment: Alignment.center,
builder: (BuildContext context) {
return OverlayPop(
videoItem: videoItem,
closeFn: () {
SmartDialog.dismiss();
},
);
return OverlayPop(videoItem: videoItem);
},
);
},
Expand Down
7 changes: 1 addition & 6 deletions lib/common/widgets/video_card_v.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,7 @@ class VideoCardV extends StatelessWidget {
useSystem: true,
alignment: Alignment.center,
builder: (BuildContext context) {
return OverlayPop(
videoItem: videoItem,
closeFn: () {
SmartDialog.dismiss();
},
);
return OverlayPop(videoItem: videoItem);
},
);
},
Expand Down
7 changes: 1 addition & 6 deletions lib/pages/dynamics/widgets/video_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,7 @@ Widget videoSeasonWidget(item, context, type, source, {floor = 1}) {
useSystem: true,
alignment: Alignment.center,
builder: (BuildContext context) {
return OverlayPop(
videoItem: content,
closeFn: () {
SmartDialog.dismiss();
},
);
return OverlayPop(videoItem: content);
},
);
},
Expand Down
7 changes: 1 addition & 6 deletions lib/pages/live/widgets/live_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,7 @@ class LiveCardV extends StatelessWidget {
useSystem: true,
alignment: Alignment.center,
builder: (BuildContext context) {
return OverlayPop(
videoItem: liveItem,
closeFn: () {
SmartDialog.dismiss();
},
);
return OverlayPop(videoItem: liveItem);
},
);
},
Expand Down
53 changes: 27 additions & 26 deletions lib/pages/video/widgets/header_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class _HeaderControlState extends State<HeaderControl> {
key: const Key('onlyPlayAudio'),
icon: Icons.hourglass_top_outlined,
onTap: () {
SmartDialog.dismiss();
Get.back();
scheduleExit();
},
text: "定时关闭",
Expand All @@ -171,10 +171,10 @@ class _HeaderControlState extends State<HeaderControl> {
ActionRowLineItem(
icon: Icons.watch_later_outlined,
onTap: () async {
Get.back();
final res = await UserHttp.toViewLater(
bvid: widget.videoDetailCtr!.bvid);
SmartDialog.showToast(res['msg']);
SmartDialog.dismiss();
},
text: "稍后看",
selectStatus: false,
Expand All @@ -184,9 +184,10 @@ class _HeaderControlState extends State<HeaderControl> {
key: const Key('continuePlayInBackground'),
icon: Icons.refresh_outlined,
onTap: () {
widget.controller!.setContinuePlayInBackground(null);
Get.back();
widget.videoDetailCtr!.queryVideoUrl();
},
text: "重载视频",
text: "刷新",
selectStatus: false,
),
]),
Expand All @@ -198,14 +199,15 @@ class _HeaderControlState extends State<HeaderControl> {
children: [
Obx(
() => ActionRowLineItem(
key: const Key('flipX'),
icon: Icons.flip,
key: const Key('continuePlayInBackground'),
icon: MdiIcons.locationExit,
onTap: () {
widget.controller!.flipX.value =
!widget.controller!.flipX.value;
widget.controller!
.setContinuePlayInBackground(null);
},
text: "镜像翻转",
selectStatus: widget.controller!.flipX.value,
text: "后台续播",
selectStatus:
widget.controller!.continuePlayInBackground.value,
),
),
const SizedBox(width: 8),
Expand All @@ -221,20 +223,19 @@ class _HeaderControlState extends State<HeaderControl> {
),
),
const SizedBox(width: 8),
// const SizedBox(width: 10),
Obx(
() => ActionRowLineItem(
key: const Key('continuePlayInBackground'),
icon: MdiIcons.locationExit,
key: const Key('flipX'),
icon: Icons.flip,
onTap: () {
widget.controller!
.setContinuePlayInBackground(null);
widget.controller!.flipX.value =
!widget.controller!.flipX.value;
},
text: "后台续播",
selectStatus:
widget.controller!.continuePlayInBackground.value,
text: "镜像",
selectStatus: widget.controller!.flipX.value,
),
),
// const SizedBox(width: 10),
],
),
),
Expand Down Expand Up @@ -516,7 +517,7 @@ class _HeaderControlState extends State<HeaderControl> {
style: subTitleStyle,
),
onTap: () async {
SmartDialog.dismiss();
Get.back();
String? result = await showDialog(
context: context,
builder: (context) {
Expand Down Expand Up @@ -601,7 +602,7 @@ class _HeaderControlState extends State<HeaderControl> {
isSending = false; // 发送结束,更新状态
});
if (res['status']) {
SmartDialog.dismiss();
Get.back();
SmartDialog.showToast('发送成功');
// 发送成功,自动预览该弹幕,避免重新请求
// TODO: 暂停状态下预览弹幕仍会移动与计时,可考虑添加到dmSegList或其他方式实现
Expand Down Expand Up @@ -666,7 +667,7 @@ class _HeaderControlState extends State<HeaderControl> {
shutdownTimerService.scheduledExitInMinutes =
choice;
shutdownTimerService.startShutdownTimer();
SmartDialog.dismiss();
Get.back();
},
contentPadding: const EdgeInsets.only(),
dense: true,
Expand Down Expand Up @@ -841,7 +842,7 @@ class _HeaderControlState extends State<HeaderControl> {
.description;
setting.put(
SettingBoxKey.defaultVideoQa, quality);
SmartDialog.dismiss();
Get.back();
SmartDialog.showToast(
"默认画质由:$oldQualityDesc 变为:${VideoQualityCode.fromCode(quality)!.description}");
widget.videoDetailCtr!.updatePlayer();
Expand Down Expand Up @@ -920,7 +921,7 @@ class _HeaderControlState extends State<HeaderControl> {
AudioQuality.values.last.code))!
.description;
setting.put(SettingBoxKey.defaultAudioQa, quality);
SmartDialog.dismiss();
Get.back();
SmartDialog.showToast(
"默认音质由:$oldQualityDesc 变为:${AudioQualityCode.fromCode(quality)!.description}");
widget.videoDetailCtr!.updatePlayer();
Expand Down Expand Up @@ -999,7 +1000,7 @@ class _HeaderControlState extends State<HeaderControl> {
widget.videoDetailCtr!.currentDecodeFormats =
VideoDecodeFormatsCode.fromString(i)!;
widget.videoDetailCtr!.updatePlayer();
SmartDialog.dismiss();
Get.back();
},
dense: true,
contentPadding:
Expand Down Expand Up @@ -1115,7 +1116,7 @@ class _HeaderControlState extends State<HeaderControl> {
),
onPressed: () {
// 弹出对话框
SmartDialog.dismiss();
Get.back();
showDialog(
context: context,
useSafeArea: true,
Expand Down Expand Up @@ -1454,7 +1455,7 @@ class _HeaderControlState extends State<HeaderControl> {
ListTile(
onTap: () {
widget.controller!.setPlayRepeat(i);
SmartDialog.dismiss();
Get.back();
},
dense: true,
contentPadding:
Expand Down
12 changes: 6 additions & 6 deletions lib/services/shutdown_timer_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:io';
import 'package:PiliPalaX/plugin/pl_player/index.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';

class ShutdownTimerService with WidgetsBindingObserver {
static final ShutdownTimerService _instance =
Expand Down Expand Up @@ -60,7 +61,7 @@ class ShutdownTimerService with WidgetsBindingObserver {
child: const Text('确认'),
onPressed: () {
cancelShutdownTimer();
SmartDialog.dismiss();
Get.back();
},
),
],
Expand All @@ -81,7 +82,7 @@ class ShutdownTimerService with WidgetsBindingObserver {
// Start the 10-second timer to auto close the dialog
_autoCloseDialogTimer?.cancel();
_autoCloseDialogTimer = Timer(const Duration(seconds: 10), () {
SmartDialog.dismiss(); // Close the dialog
Get.back();
_executeShutdown();
});
return AlertDialog(
Expand All @@ -91,16 +92,15 @@ class ShutdownTimerService with WidgetsBindingObserver {
TextButton(
child: const Text('取消关闭'),
onPressed: () {
_autoCloseDialogTimer?.cancel(); // Cancel the auto-close timer
cancelShutdownTimer(); // Cancel the shutdown timer
SmartDialog.dismiss(); // Close the dialog
Get.back();
_autoCloseDialogTimer?.cancel();
cancelShutdownTimer();
},
),
],
);
},
).then((_) {
// Cleanup when the dialog is dismissed
_autoCloseDialogTimer?.cancel();
});
}
Expand Down

0 comments on commit 91fe501

Please sign in to comment.