mod: 无障碍自定义操作适配

This commit is contained in:
orz12
2024-09-08 20:58:20 +08:00
committed by bggRGjQaUbCoE
parent 33beafbf87
commit e4319dae2f
3 changed files with 266 additions and 292 deletions

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import '../../http/search.dart'; import '../../http/search.dart';
@@ -41,11 +42,17 @@ class VideoCardH extends StatelessWidget {
try { try {
type = videoItem.type; type = videoItem.type;
} catch (_) {} } catch (_) {}
List<VideoCustomAction> actions =
VideoCustomActions(videoItem, context).actions;
final String heroTag = Utils.makeHeroTag(aid); final String heroTag = Utils.makeHeroTag(aid);
return Stack(children: [ return Stack(children: [
Semantics( Semantics(
label: Utils.videoItemSemantics(videoItem), label: Utils.videoItemSemantics(videoItem),
excludeSemantics: true, excludeSemantics: true,
customSemanticsActions: <CustomSemanticsAction, void Function()>{
for (var item in actions)
CustomSemanticsAction(label: item.title): item.onTap!,
},
child: InkWell( child: InkWell(
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
onLongPress: () { onLongPress: () {
@@ -134,7 +141,7 @@ class VideoCardH extends StatelessWidget {
child: VideoPopupMenu( child: VideoPopupMenu(
size: 29, size: 29,
iconSize: 17, iconSize: 17,
videoItem: videoItem, actions: actions,
), ),
), ),
]); ]);

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import '../../models/model_rec_video_item.dart'; import '../../models/model_rec_video_item.dart';
@@ -127,10 +128,16 @@ class VideoCardV extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
String heroTag = Utils.makeHeroTag(videoItem.id); String heroTag = Utils.makeHeroTag(videoItem.id);
List<VideoCustomAction> actions =
VideoCustomActions(videoItem, context).actions;
return Stack(children: [ return Stack(children: [
Semantics( Semantics(
label: Utils.videoItemSemantics(videoItem), label: Utils.videoItemSemantics(videoItem),
excludeSemantics: true, excludeSemantics: true,
customSemanticsActions: <CustomSemanticsAction, void Function()>{
for (var item in actions)
CustomSemanticsAction(label: item.title): item.onTap!,
},
child: Card( child: Card(
clipBehavior: Clip.hardEdge, clipBehavior: Clip.hardEdge,
margin: EdgeInsets.zero, margin: EdgeInsets.zero,
@@ -185,7 +192,7 @@ class VideoCardV extends StatelessWidget {
child: VideoPopupMenu( child: VideoPopupMenu(
size: 29, size: 29,
iconSize: 17, iconSize: 17,
videoItem: videoItem, actions: actions,
)), )),
]); ]);
} }

View File

@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
@@ -10,71 +9,36 @@ import '../../models/home/rcmd/result.dart';
import '../../pages/mine/controller.dart'; import '../../pages/mine/controller.dart';
import '../../utils/storage.dart'; import '../../utils/storage.dart';
class VideoPopupMenu extends StatelessWidget { class VideoCustomAction {
final double? size; String title;
final double? iconSize; String value;
final dynamic videoItem; Icon icon;
final double menuItemHeight = 45; VoidCallback? onTap;
VideoCustomAction(this.title, this.value, this.icon, this.onTap);
}
const VideoPopupMenu({ class VideoCustomActions {
Key? key, dynamic videoItem;
required this.size, BuildContext context;
required this.iconSize, late List<VideoCustomAction> actions;
required this.videoItem, VideoCustomActions(this.videoItem, this.context) {
}) : super(key: key); actions = [
VideoCustomAction(
@override '稍后再看', 'pause', Icon(MdiIcons.clockTimeEightOutline, size: 16),
Widget build(BuildContext context) { () async {
return SizedBox( var res = await UserHttp.toViewLater(bvid: videoItem.bvid as String);
width: size,
height: size,
child: PopupMenuButton<String>(
padding: EdgeInsets.zero,
icon: Icon(
Icons.more_vert_outlined,
color: Theme.of(context).colorScheme.outline,
size: iconSize,
),
position: PopupMenuPosition.under,
onSelected: (String type) {},
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
PopupMenuItem<String>(
onTap: () async {
var res =
await UserHttp.toViewLater(bvid: videoItem.bvid as String);
SmartDialog.showToast(res['msg']); SmartDialog.showToast(res['msg']);
}, }),
value: 'pause', VideoCustomAction('访问:${videoItem.owner.name}', 'visit',
height: menuItemHeight, Icon(MdiIcons.accountCircleOutline, size: 16), () async {
child: Row(
children: [
Icon(MdiIcons.clockTimeEightOutline, size: 16),
const SizedBox(width: 6),
const Text('稍后再看', style: TextStyle(fontSize: 13))
],
),
),
PopupMenuItem<String>(
onTap: () async {
Get.toNamed('/member?mid=${videoItem.owner.mid}', arguments: { Get.toNamed('/member?mid=${videoItem.owner.mid}', arguments: {
// 'face': videoItem.owner.face, // 'face': videoItem.owner.face,
'heroTag': '${videoItem.owner.mid}', 'heroTag': '${videoItem.owner.mid}',
}); });
}, }),
value: 'visit', VideoCustomAction(
height: menuItemHeight, '不感兴趣', 'dislike', Icon(MdiIcons.thumbDownOutline, size: 16),
child: Row( () async {
children: [
Icon(MdiIcons.accountCircleOutline, size: 16),
const SizedBox(width: 6),
Text('访问:${videoItem.owner.name}',
style: const TextStyle(fontSize: 13))
],
),
),
// 不感兴趣
PopupMenuItem<String>(
onTap: () async {
String? accessKey = GStorage.localCache String? accessKey = GStorage.localCache
.get(LocalCacheKey.accessKey, defaultValue: {})['value']; .get(LocalCacheKey.accessKey, defaultValue: {})['value'];
if (accessKey == null || accessKey == "") { if (accessKey == null || accessKey == "") {
@@ -95,8 +59,8 @@ class VideoPopupMenu extends StatelessWidget {
Widget actionButton(DislikeReason? r, FeedbackReason? f) { Widget actionButton(DislikeReason? r, FeedbackReason? f) {
return ElevatedButton( return ElevatedButton(
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric( padding:
horizontal: 12.0, vertical: 0.0), const EdgeInsets.symmetric(horizontal: 12.0, vertical: 0.0),
), ),
onPressed: () async { onPressed: () async {
SmartDialog.showLoading(msg: '正在提交'); SmartDialog.showLoading(msg: '正在提交');
@@ -193,8 +157,7 @@ class VideoPopupMenu extends StatelessWidget {
onPressed: () async { onPressed: () async {
SmartDialog.showLoading(msg: '正在提交'); SmartDialog.showLoading(msg: '正在提交');
var res = await VideoHttp.dislikeVideo( var res = await VideoHttp.dislikeVideo(
bvid: videoItem.bvid as String, bvid: videoItem.bvid as String, type: true);
type: true);
SmartDialog.dismiss(); SmartDialog.dismiss();
SmartDialog.showToast( SmartDialog.showToast(
res['status'] ? "点踩成功" : res['msg']); res['status'] ? "点踩成功" : res['msg']);
@@ -206,8 +169,7 @@ class VideoPopupMenu extends StatelessWidget {
onPressed: () async { onPressed: () async {
SmartDialog.showLoading(msg: '正在提交'); SmartDialog.showLoading(msg: '正在提交');
var res = await VideoHttp.dislikeVideo( var res = await VideoHttp.dislikeVideo(
bvid: videoItem.bvid as String, bvid: videoItem.bvid as String, type: false);
type: false);
SmartDialog.dismiss(); SmartDialog.dismiss();
SmartDialog.showToast( SmartDialog.showToast(
res['status'] ? "取消踩" : res['msg']); res['status'] ? "取消踩" : res['msg']);
@@ -224,34 +186,24 @@ class VideoPopupMenu extends StatelessWidget {
}, },
); );
} }
}, }),
value: 'dislike', VideoCustomAction('拉黑:${videoItem.owner.name}', 'block',
height: menuItemHeight, Icon(MdiIcons.cancel, size: 16), () async {
child: Row(
children: [
Icon(MdiIcons.thumbDownOutline, size: 16),
const SizedBox(width: 6),
const Text('不感兴趣', style: TextStyle(fontSize: 13))
],
),
),
PopupMenuItem<String>(
onTap: () async {
await showDialog( await showDialog(
context: context, context: context,
builder: (context) { builder: (context) {
return AlertDialog( return AlertDialog(
title: const Text('提示'), title: const Text('提示'),
content: Text( content:
'确定拉黑:${videoItem.owner.name}(${videoItem.owner.mid})?' Text('确定拉黑:${videoItem.owner.name}(${videoItem.owner.mid})?'
'\n\n被拉黑的Up可以在隐私设置-黑名单管理中解除'), '\n\n被拉黑的Up可以在隐私设置-黑名单管理中解除'),
actions: [ actions: [
TextButton( TextButton(
onPressed: () => Get.back(), onPressed: () => Get.back(),
child: Text( child: Text(
'点错了', '点错了',
style: TextStyle( style:
color: Theme.of(context).colorScheme.outline), TextStyle(color: Theme.of(context).colorScheme.outline),
), ),
), ),
TextButton( TextButton(
@@ -262,8 +214,7 @@ class VideoPopupMenu extends StatelessWidget {
reSrc: 11, reSrc: 11,
); );
List<int> blackMidsList = GStorage.localCache List<int> blackMidsList = GStorage.localCache
.get(LocalCacheKey.blackMidsList, .get(LocalCacheKey.blackMidsList, defaultValue: [-1])
defaultValue: [-1])
.map<int>((i) => i as int) .map<int>((i) => i as int)
.toList(); .toList();
blackMidsList.insert(0, videoItem.owner.mid); blackMidsList.insert(0, videoItem.owner.mid);
@@ -278,55 +229,64 @@ class VideoPopupMenu extends StatelessWidget {
); );
}, },
); );
}, }),
value: 'block', VideoCustomAction(
height: menuItemHeight, "${MineController.anonymity ? '退出' : '进入'}无痕模式",
child: Row( 'anonymity',
children: [
Icon(MdiIcons.cancel, size: 16),
const SizedBox(width: 6),
Text('拉黑:${videoItem.owner.name}',
style: const TextStyle(fontSize: 13))
],
),
),
// PopupMenuItem<String>(
// onTap: () async {
// SmartDialog.showToast("还没做");
// },
// value: 'anonymize',
// height: menuItemHeight,
// child: const Row(
// children: [
// Icon(Icons.visibility_off_outlined, size: 16),
// SizedBox(width: 6),
// Text('无痕播放',
// style: TextStyle(fontSize: 13))
// ],
// ),
// ),
PopupMenuItem<String>(
onTap: () {
MineController.onChangeAnonymity(context);
},
value: 'anonymous',
height: menuItemHeight,
child: Row(
children: [
Icon( Icon(
MineController.anonymity MineController.anonymity
? MdiIcons.incognitoOff ? MdiIcons.incognitoOff
: MdiIcons.incognito, : MdiIcons.incognito,
size: 16, size: 16,
), ),
() => MineController.onChangeAnonymity(context))
];
}
}
class VideoPopupMenu extends StatelessWidget {
final double? size;
final double? iconSize;
final List<VideoCustomAction> actions;
final double menuItemHeight = 45;
const VideoPopupMenu({
super.key,
required this.size,
required this.iconSize,
required this.actions,
});
@override
Widget build(BuildContext context) {
return ExcludeSemantics(
child: SizedBox(
width: size,
height: size,
child: PopupMenuButton<String>(
padding: EdgeInsets.zero,
icon: Icon(
Icons.more_vert_outlined,
color: Theme.of(context).colorScheme.outline,
size: iconSize,
),
position: PopupMenuPosition.under,
onSelected: (String type) {},
itemBuilder: (BuildContext context) => actions.map((e) {
return PopupMenuItem<String>(
value: e.value,
height: menuItemHeight,
onTap: e.onTap,
child: Row(
children: [
e.icon,
const SizedBox(width: 6), const SizedBox(width: 6),
Text("${MineController.anonymity ? '退出' : '进入'}无痕模式", Text(e.title, style: const TextStyle(fontSize: 13))
style: const TextStyle(fontSize: 13))
],
),
),
], ],
), ),
); );
}).toList(),
),
));
} }
} }