mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +00:00
* flutter create * Copied in from 'contextual-menu-examples' repo * Works again with the latest updates to the branch * Clean up anywhere example * Clean up other examples * Add to CI * Updated with release version of context menus, and added platform switcher * Generated files * Home icon on your original platform * Remove web_dashboard from ci, not sure why that change was there... * Add context_menu to beta channel, but commented out, for the future * +x permissions on the master script, which I may have accidentally changed before? * Actual bash comment * dart format * Natural default platform' * A working test, for the email page * Import order fix * Test some pages * More tests * dart format
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({
|
|
Key? key,
|
|
required this.onChangedPlatform,
|
|
}) : super(key: key);
|
|
|
|
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: (BuildContext 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: (BuildContext context, Offset 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.',
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|