Skip to content

Commit

Permalink
fix: 弹出层返回异常黑屏
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Jan 13, 2025
1 parent a881b6d commit 27e40ae
Show file tree
Hide file tree
Showing 17 changed files with 1,291 additions and 1,387 deletions.
65 changes: 37 additions & 28 deletions lib/common/widgets/list_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:material_design_icons_flutter/material_design_icons_flutter.dart
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';

import '../../utils/storage.dart';
import 'my_dialog.dart';

class ListSheet {
ListSheet({
Expand All @@ -26,19 +27,16 @@ class ListSheet {
final BuildContext context;

void buildShowBottomSheet() {
SmartDialog.show(
alignment: MediaQuery.of(context).orientation == Orientation.portrait
? Alignment.bottomRight
: Alignment.topRight,
useSystem: true,
builder: (BuildContext context) => ListSheetContent(
episodes: episodes,
bvid: bvid,
aid: aid,
currentCid: currentCid,
changeFucCall: changeFucCall,
// onClose: SmartDialog.dismiss,
));
MyDialog.showCorner(
context,
ListSheetContent(
episodes: episodes,
bvid: bvid,
aid: aid,
currentCid: currentCid,
changeFucCall: changeFucCall,
// onClose: SmartDialog.dismiss,
));
}
}

Expand Down Expand Up @@ -130,20 +128,22 @@ class _ListSheetContentState extends State<ListSheetContent> {
// semanticLabel: "正在播放:",
// )
// : null,
title: Text(
title,
style: TextStyle(
fontSize: 14,
color: isCurrentIndex
? primary
: Theme.of(context).colorScheme.onSurface,
),
semanticsLabel: isCurrentIndex ? "正在播放:$title" : title,
),
trailing: Row(
title: Row(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: Text(
title,
style: TextStyle(
fontSize: 14,
color: isCurrentIndex
? primary
: Theme.of(context).colorScheme.onSurface,
),
semanticsLabel: isCurrentIndex ? "正在播放:$title" : title,
)),
if (episode.badge != null) ...[
const SizedBox(width: 10),
if (episode.badge == '会员')
Image.asset(
'assets/images/big-vip.png',
Expand All @@ -154,8 +154,13 @@ class _ListSheetContentState extends State<ListSheetContent> {
const SizedBox(width: 10),
],
if (!(episode.runtimeType.toString() == 'EpisodeItem' &&
(episode.longTitle != null && episode.longTitle != '')))
Text('${index + 1}/${widget.episodes!.length}'),
(episode.longTitle != null && episode.longTitle != ''))) ...[
const SizedBox(width: 10),
Text(
'${index + 1}/${widget.episodes!.length}',
style: const TextStyle(fontSize: 13),
),
]
],
),
);
Expand All @@ -171,8 +176,8 @@ class _ListSheetContentState extends State<ListSheetContent> {
color: Theme.of(context).colorScheme.surface,
borderRadius: const BorderRadius.all(Radius.circular(12)),
),
margin: const EdgeInsets.symmetric(horizontal: 8, vertical: 30),
padding: const EdgeInsets.all(6),
// margin: const EdgeInsets.symmetric(horizontal: 8, vertical: 30),
padding: const EdgeInsets.only(left: 6, top: 3, bottom: 10),
child: Column(
children: [
Container(
Expand Down Expand Up @@ -226,6 +231,8 @@ class _ListSheetContentState extends State<ListSheetContent> {
),
Divider(
height: 1,
indent: 10,
endIndent: 20,
color: Theme.of(context).dividerColor.withOpacity(0.1),
),
const SizedBox(height: 1),
Expand All @@ -245,6 +252,8 @@ class _ListSheetContentState extends State<ListSheetContent> {
},
itemScrollController: itemScrollController,
separatorBuilder: (_, index) => Divider(
indent: 18,
endIndent: 25,
height: 1,
color: Theme.of(context).dividerColor.withOpacity(0.1),
),
Expand Down
38 changes: 38 additions & 0 deletions lib/common/widgets/my_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:PiliPalaX/common/constants.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';

class MyDialog {
static Future<void> show(BuildContext context, Widget child) {
return showDialog(
barrierDismissible: true,
context: context,
builder: (BuildContext context) => Dialog(
insetPadding: const EdgeInsets.all(0),
child: Material(
clipBehavior: Clip.hardEdge,
borderRadius: StyleString.mdRadius,
child: child,
)),
);
}

static Future<void> showCorner(BuildContext context, Widget child) {
return showDialog(
barrierDismissible: true,
context: context,
builder: (BuildContext context) => Align(
alignment: MediaQuery.of(context).orientation == Orientation.portrait
? Alignment.bottomRight
: Alignment.topRight,
child: Padding(
padding: const EdgeInsets.all(8.0), // 设置外边距
child: Material(
clipBehavior: Clip.hardEdge,
borderRadius: StyleString.mdRadius,
child: child,
)),
),
);
}
}
51 changes: 28 additions & 23 deletions lib/common/widgets/overlay_pop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class OverlayPop extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 8),
Stack(
children: [
NetworkImgLayer(
Expand Down Expand Up @@ -69,7 +70,7 @@ class OverlayPop extends StatelessWidget {
padding: const EdgeInsets.fromLTRB(12, 10, 8, 10),
child: Row(
children: [
if (videoItem.title is String) ...[
if (videoItem.title is String)
Expanded(
child: SelectableText(
videoItem.title ?? '',
Expand All @@ -82,8 +83,8 @@ class OverlayPop extends StatelessWidget {
),
// overflow: TextOverflow.ellipsis,
),
),
] else ...[
)
else
Expanded(
child: RichText(
overflow: TextOverflow.ellipsis,
Expand All @@ -110,29 +111,33 @@ class OverlayPop extends StatelessWidget {
),
),
),
],
if (videoItem.runtimeType.toString() != 'LiveItemModel')
IconButton(
tooltip: '稍后再看',
icon: Icon(MdiIcons.clockTimeEightOutline, size: 20),
onPressed: () async {
var res = await UserHttp.toViewLater(
bvid: videoItem.bvid as String);
SmartDialog.showToast(res['msg']);
},
SizedBox(
width: 30,
child: IconButton(
tooltip: '稍后再看',
icon: Icon(MdiIcons.clockTimeEightOutline, size: 20),
onPressed: () async {
var res = await UserHttp.toViewLater(
bvid: videoItem.bvid as String);
SmartDialog.showToast(res['msg']);
},
),
),
const SizedBox(width: 4),
IconButton(
tooltip: '保存封面图',
onPressed: () async {
await DownloadUtils.downloadImg(
context,
videoItem.pic ?? videoItem.cover ?? '',
);
// closeFn!();
},
icon: const Icon(Icons.download_outlined, size: 20),
)
SizedBox(
width: 30,
child: IconButton(
tooltip: '保存封面图',
onPressed: () async {
await DownloadUtils.downloadImg(
context,
videoItem.pic ?? videoItem.cover ?? '',
);
// closeFn!();
},
icon: const Icon(Icons.download_outlined, size: 20),
))
],
),
),
Expand Down
9 changes: 2 additions & 7 deletions lib/common/widgets/video_card_h.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import '../../http/search.dart';
import '../../utils/utils.dart';
import '../constants.dart';
import 'badge.dart';
import 'my_dialog.dart';
import 'network_img_layer.dart';
import 'overlay_pop.dart';
import 'stat/danmu.dart';
Expand Down Expand Up @@ -94,13 +95,7 @@ class VideoCardH extends StatelessWidget {
GestureDetector(
onLongPress: () {
// 弹窗显示封面
SmartDialog.show(
useSystem: true,
alignment: Alignment.center,
builder: (BuildContext context) {
return OverlayPop(videoItem: videoItem);
},
);
MyDialog.show(context, OverlayPop(videoItem: videoItem));
},
behavior: HitTestBehavior.translucent,
child: Hero(
Expand Down
10 changes: 3 additions & 7 deletions lib/common/widgets/video_card_v.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import '../../models/home/rcmd/result.dart';
import '../../models/model_rec_video_item.dart';
import 'my_dialog.dart';
import 'overlay_pop.dart';
import 'stat/danmu.dart';
import 'stat/view.dart';
Expand Down Expand Up @@ -170,13 +171,8 @@ class VideoCardV extends StatelessWidget {
GestureDetector(
onLongPress: () {
// 弹窗显示封面
SmartDialog.show(
useSystem: true,
alignment: Alignment.center,
builder: (BuildContext context) {
return OverlayPop(videoItem: videoItem);
},
);
MyDialog.show(
context, OverlayPop(videoItem: videoItem));
},
behavior: HitTestBehavior.translucent,
child: Hero(
Expand Down
1 change: 0 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ class MyApp extends StatelessWidget {
navigatorObservers: [
VideoDetailPage.routeObserver,
SearchPage.routeObserver,
FlutterSmartDialog.observer,
],
);
}),
Expand Down
10 changes: 3 additions & 7 deletions lib/pages/dynamics/widgets/video_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:PiliPalaX/common/widgets/badge.dart';
import 'package:PiliPalaX/common/widgets/network_img_layer.dart';
import 'package:PiliPalaX/utils/utils.dart';

import '../../../common/widgets/my_dialog.dart';
import '../../../common/widgets/overlay_pop.dart';
import 'rich_node_panel.dart';

Expand Down Expand Up @@ -91,13 +92,8 @@ Widget videoSeasonWidget(item, context, type, source, {floor = 1}) {
behavior: HitTestBehavior.translucent,
onLongPress: () {
// 弹窗显示封面
SmartDialog.show(
useSystem: true,
alignment: Alignment.center,
builder: (BuildContext context) {
return OverlayPop(videoItem: content);
},
);
MyDialog.show(
context, OverlayPop(videoItem: content));
},
child: Hero(
tag: content.bvid,
Expand Down
9 changes: 4 additions & 5 deletions lib/pages/follow/widgets/follow_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'package:PiliPalaX/pages/video/introduction/widgets/group_panel.dart';
import 'package:PiliPalaX/utils/feed_back.dart';
import 'package:PiliPalaX/utils/utils.dart';

import '../../../common/widgets/my_dialog.dart';

class FollowItem extends StatelessWidget {
final FollowItemModel item;
final FollowController? ctr;
Expand Down Expand Up @@ -46,11 +48,8 @@ class FollowItem extends StatelessWidget {
? SizedBox(
height: 34,
child: TextButton(
onPressed: () async {
await Get.bottomSheet(
GroupPanel(mid: item.mid!),
isScrollControlled: true,
);
onPressed: () {
MyDialog.show(context, GroupPanel(mid: item.mid!));
},
style: TextButton.styleFrom(
padding: const EdgeInsets.fromLTRB(15, 0, 15, 0),
Expand Down
10 changes: 3 additions & 7 deletions lib/pages/live/widgets/live_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:PiliPalaX/models/live/item.dart';
import 'package:PiliPalaX/utils/utils.dart';
import 'package:PiliPalaX/common/widgets/network_img_layer.dart';

import '../../../common/widgets/my_dialog.dart';
import '../../../common/widgets/overlay_pop.dart';

// 视频卡片 - 垂直布局
Expand Down Expand Up @@ -58,13 +59,8 @@ class LiveCardV extends StatelessWidget {
behavior: HitTestBehavior.translucent,
onLongPress: () {
// 弹窗显示封面
SmartDialog.show(
useSystem: true,
alignment: Alignment.center,
builder: (BuildContext context) {
return OverlayPop(videoItem: liveItem);
},
);
MyDialog.show(
context, OverlayPop(videoItem: liveItem));
},
child: Hero(
tag: heroTag,
Expand Down
Loading

0 comments on commit 27e40ae

Please sign in to comment.