mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +00:00
Move context menus out of experimental (#2134)
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>
This commit is contained in:
committed by
GitHub
parent
9b17f50671
commit
6c8d54a82b
94
context_menus/lib/email_button_page.dart
Normal file
94
context_menus/lib/email_button_page.dart
Normal file
@@ -0,0 +1,94 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import 'constants.dart';
|
||||
import 'is_valid_email.dart';
|
||||
import 'platform_selector.dart';
|
||||
|
||||
class EmailButtonPage extends StatelessWidget {
|
||||
EmailButtonPage({
|
||||
super.key,
|
||||
required this.onChangedPlatform,
|
||||
});
|
||||
|
||||
static const String route = 'email-button';
|
||||
static const String title = 'Email Button';
|
||||
static const String subtitle = 'A selection-aware email button';
|
||||
static const String url = '$kCodeUrl/email_button_page.dart';
|
||||
|
||||
final PlatformCallback onChangedPlatform;
|
||||
|
||||
final TextEditingController _controller = TextEditingController(
|
||||
text: 'Select the email address and open the menu: me@example.com',
|
||||
);
|
||||
|
||||
DialogRoute _showDialog(BuildContext context) {
|
||||
return DialogRoute<void>(
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
const AlertDialog(title: Text('You clicked send email!')),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text(EmailButtonPage.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: Center(
|
||||
child: SizedBox(
|
||||
width: 300.0,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
const SizedBox(height: 20.0),
|
||||
const Text(
|
||||
'This example shows how to add a special button to the context menu depending on the current selection.',
|
||||
),
|
||||
const SizedBox(height: 40.0),
|
||||
TextField(
|
||||
maxLines: 2,
|
||||
controller: _controller,
|
||||
contextMenuBuilder: (context, editableTextState) {
|
||||
final TextEditingValue value =
|
||||
editableTextState.textEditingValue;
|
||||
final List<ContextMenuButtonItem> buttonItems =
|
||||
editableTextState.contextMenuButtonItems;
|
||||
if (isValidEmail(value.selection.textInside(value.text))) {
|
||||
buttonItems.insert(
|
||||
0,
|
||||
ContextMenuButtonItem(
|
||||
label: 'Send email',
|
||||
onPressed: () {
|
||||
ContextMenuController.removeAny();
|
||||
Navigator.of(context).push(_showDialog(context));
|
||||
},
|
||||
));
|
||||
}
|
||||
return AdaptiveTextSelectionToolbar.buttonItems(
|
||||
anchors: editableTextState.contextMenuAnchors,
|
||||
buttonItems: buttonItems,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user