mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
Now that the context menu code is on stable, move the sample out of experimental. Fixes https://github.com/flutter/samples/issues/2110 ## Pre-launch Checklist - [x] I read the [Flutter Style Guide] _recently_, and have followed its advice. - [x] I signed the [CLA]. - [x] I read the [Contributors Guide]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] All existing and new tests are passing. --------- Co-authored-by: Brett Morgan <brett.morgan@gmail.com>
84 lines
2.4 KiB
Dart
84 lines
2.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
import 'constants.dart';
|
|
import 'context_menu_region.dart';
|
|
import 'platform_selector.dart';
|
|
|
|
class ImagePage extends StatelessWidget {
|
|
const ImagePage({
|
|
super.key,
|
|
required this.onChangedPlatform,
|
|
});
|
|
|
|
static const String route = 'image';
|
|
static const String title = 'ContextMenu on an Image';
|
|
static const String subtitle =
|
|
'A ContextMenu the displays on an Image widget';
|
|
static const String url = '$kCodeUrl/image_page.dart';
|
|
|
|
final PlatformCallback onChangedPlatform;
|
|
|
|
DialogRoute _showDialog(BuildContext context) {
|
|
return DialogRoute<void>(
|
|
context: context,
|
|
builder: (context) =>
|
|
const AlertDialog(title: Text('Image saved! (not really though)')),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text(ImagePage.title),
|
|
actions: <Widget>[
|
|
PlatformSelector(
|
|
onChangedPlatform: onChangedPlatform,
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.code),
|
|
onPressed: () async {
|
|
if (!await launchUrl(Uri.parse(url))) {
|
|
throw 'Could not launch $url';
|
|
}
|
|
},
|
|
),
|
|
],
|
|
),
|
|
body: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
ContextMenuRegion(
|
|
contextMenuBuilder: (context, offset) {
|
|
return AdaptiveTextSelectionToolbar.buttonItems(
|
|
anchors: TextSelectionToolbarAnchors(
|
|
primaryAnchor: offset,
|
|
),
|
|
buttonItems: <ContextMenuButtonItem>[
|
|
ContextMenuButtonItem(
|
|
onPressed: () {
|
|
ContextMenuController.removeAny();
|
|
Navigator.of(context).push(_showDialog(context));
|
|
},
|
|
label: 'Save',
|
|
),
|
|
],
|
|
);
|
|
},
|
|
child: const SizedBox(
|
|
width: 200.0,
|
|
height: 200.0,
|
|
child: FlutterLogo(),
|
|
),
|
|
),
|
|
Container(height: 20.0),
|
|
const Text(
|
|
'Right click or long press on the image to see a special menu.',
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|