cupertino context menu
This commit is contained in:
@ -5,15 +5,11 @@ import 'package:flutter/services.dart';
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
||||||
import 'package:momo/lib/context_menu_region.dart';
|
|
||||||
import 'package:momo/models/image_list_resp.dart';
|
import 'package:momo/models/image_list_resp.dart';
|
||||||
import 'package:momo/models/image_resp.dart';
|
import 'package:momo/models/image_resp.dart';
|
||||||
import 'package:momo/provider/rerender.dart';
|
import 'package:momo/provider/rerender.dart';
|
||||||
import 'package:momo/request/http_client.dart';
|
import 'package:momo/request/http_client.dart';
|
||||||
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
/// A builder that includes an Offset to draw the context menu at.
|
|
||||||
// typedef ContextMenuBuilder = Widget Function(
|
|
||||||
// BuildContext context, Offset offset);
|
|
||||||
|
|
||||||
class Gallery extends ConsumerWidget {
|
class Gallery extends ConsumerWidget {
|
||||||
const Gallery({Key? key}) : super(key: key);
|
const Gallery({Key? key}) : super(key: key);
|
||||||
@ -93,111 +89,24 @@ class ImageItem extends ConsumerStatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ImageItemState extends ConsumerState<ImageItem> {
|
class _ImageItemState extends ConsumerState<ImageItem> {
|
||||||
// final ContextMenuController _contextMenuController = ContextMenuController();
|
Future<void> _launchInBrowser(Uri url) async {
|
||||||
|
if (!await launchUrl(
|
||||||
@override
|
url,
|
||||||
void dispose() {
|
mode: LaunchMode.externalApplication,
|
||||||
// TODO: implement dispose
|
)) {
|
||||||
// if (_contextMenuController.isShown) {
|
throw Exception('Could not launch $url');
|
||||||
// _contextMenuController.remove();
|
}
|
||||||
// }
|
|
||||||
super.dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// void _showContextMenu(Offset position) {
|
|
||||||
// _contextMenuController.show(
|
|
||||||
// context: context,
|
|
||||||
// contextMenuBuilder: (BuildContext context) {
|
|
||||||
// return AdaptiveTextSelectionToolbar.buttonItems(
|
|
||||||
// anchors: TextSelectionToolbarAnchors(
|
|
||||||
// primaryAnchor: position,
|
|
||||||
// ),
|
|
||||||
// buttonItems: <ContextMenuButtonItem>[
|
|
||||||
// ContextMenuButtonItem(
|
|
||||||
// onPressed: () {
|
|
||||||
// ContextMenuController.removeAny();
|
|
||||||
// showDialog(
|
|
||||||
// context: context,
|
|
||||||
// builder: (BuildContext context) =>
|
|
||||||
// AlertDialog(
|
|
||||||
// title: const Text('删除图片'),
|
|
||||||
// content: const Text("确认删除图片"),
|
|
||||||
// actions: [
|
|
||||||
// TextButton(
|
|
||||||
// onPressed: () => Navigator.pop(context, 'Cancel'),
|
|
||||||
// child: const Text('Cancel'),
|
|
||||||
// ),
|
|
||||||
// TextButton(
|
|
||||||
// onPressed: () {
|
|
||||||
// Navigator.pop(context, 'OK');
|
|
||||||
// dio
|
|
||||||
// .delete("/image/delete/${widget.image.id}")
|
|
||||||
// .then((resp) {
|
|
||||||
// ref
|
|
||||||
// .read(uniqueIdProvider.notifier)
|
|
||||||
// .updateId();
|
|
||||||
// // context.go("/");
|
|
||||||
// });
|
|
||||||
// },
|
|
||||||
// child: const Text('OK'),
|
|
||||||
// ),
|
|
||||||
// ],
|
|
||||||
// ));
|
|
||||||
// // _showDialog(context);
|
|
||||||
// },
|
|
||||||
// label: '删除',
|
|
||||||
// ),
|
|
||||||
// ContextMenuButtonItem(
|
|
||||||
// onPressed: () {
|
|
||||||
// ContextMenuController.removeAny();
|
|
||||||
// // _showDialog(context);
|
|
||||||
// Clipboard.setData(ClipboardData(
|
|
||||||
// text:
|
|
||||||
// "${dio.options.baseUrl}/image/${widget.image.file_path}"));
|
|
||||||
// ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
|
||||||
// content: Row(
|
|
||||||
// crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
// children: [
|
|
||||||
// Icon(
|
|
||||||
// Icons.check_circle,
|
|
||||||
// color: Colors.white,
|
|
||||||
// ),
|
|
||||||
// SizedBox(
|
|
||||||
// width: 10,
|
|
||||||
// ),
|
|
||||||
// Text("已拷贝到剪贴板")
|
|
||||||
// ],
|
|
||||||
// ),
|
|
||||||
// backgroundColor: Colors.lightGreen,
|
|
||||||
// ));
|
|
||||||
// },
|
|
||||||
// label: '复制链接',
|
|
||||||
// ),
|
|
||||||
// ContextMenuButtonItem(
|
|
||||||
// onPressed: () {
|
|
||||||
// ContextMenuController.removeAny();
|
|
||||||
// // _showDialog(context);
|
|
||||||
// },
|
|
||||||
// label: '查看详情',
|
|
||||||
// ),
|
|
||||||
// ],
|
|
||||||
// );
|
|
||||||
// },
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ContextMenuRegion(
|
return CupertinoContextMenu.builder(
|
||||||
contextMenuBuilder: (BuildContext context, Offset offset) {
|
enableHapticFeedback: true,
|
||||||
return AdaptiveTextSelectionToolbar.buttonItems(
|
actions: [
|
||||||
anchors: TextSelectionToolbarAnchors(
|
CupertinoContextMenuAction(
|
||||||
primaryAnchor: offset,
|
trailingIcon: CupertinoIcons.delete,
|
||||||
),
|
|
||||||
buttonItems: <ContextMenuButtonItem>[
|
|
||||||
ContextMenuButtonItem(
|
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
ContextMenuController.removeAny();
|
Navigator.of(context, rootNavigator: true).pop();
|
||||||
Clipboard.setData(ClipboardData(
|
Clipboard.setData(ClipboardData(
|
||||||
text:
|
text:
|
||||||
"https://raichi.hodokencho.com/api/image/${widget.image.file_path}"));
|
"https://raichi.hodokencho.com/api/image/${widget.image.file_path}"));
|
||||||
@ -218,16 +127,32 @@ class _ImageItemState extends ConsumerState<ImageItem> {
|
|||||||
backgroundColor: Colors.lightGreen,
|
backgroundColor: Colors.lightGreen,
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
label: '复制链接',
|
child: const Text('复制链接'),
|
||||||
|
),
|
||||||
|
CupertinoContextMenuAction(
|
||||||
|
trailingIcon: CupertinoIcons.search,
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context, rootNavigator: true).pop();
|
||||||
|
final imageUrl =
|
||||||
|
"https://raichi.hodokencho.com/api/image/${widget.image.file_path}";
|
||||||
|
final launchUrl =
|
||||||
|
"https://saucenao.com/search.php?url=${Uri.encodeComponent(imageUrl)}";
|
||||||
|
_launchInBrowser(Uri.parse(launchUrl));
|
||||||
|
},
|
||||||
|
child: const Text('在SauceNAO中搜索'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
builder: (BuildContext context, Animation<double> animation) {
|
||||||
},
|
return GestureDetector(
|
||||||
child: GestureDetector(
|
|
||||||
onTap: () {
|
onTap: () {
|
||||||
|
Navigator.of(
|
||||||
|
context,
|
||||||
|
).maybePop();
|
||||||
|
Future.delayed(const Duration(milliseconds: 120)).then((value) {
|
||||||
context.go(Uri(
|
context.go(Uri(
|
||||||
path: "/detail",
|
path: "/detail",
|
||||||
queryParameters: {"id": "${widget.image.id}"}).toString());
|
queryParameters: {"id": "${widget.image.id}"}).toString());
|
||||||
|
});
|
||||||
},
|
},
|
||||||
child: Image.network(
|
child: Image.network(
|
||||||
kIsWeb
|
kIsWeb
|
||||||
@ -238,6 +163,8 @@ class _ImageItemState extends ConsumerState<ImageItem> {
|
|||||||
return const Icon(Icons.error_outline);
|
return const Icon(Icons.error_outline);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
));
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user