mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +00:00
Custom context menu example (#1463)
* 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
This commit is contained in:
committed by
GitHub
parent
070ce7303a
commit
41571eae07
111
experimental/context_menus/lib/default_values_page.dart
Normal file
111
experimental/context_menus/lib/default_values_page.dart
Normal file
@@ -0,0 +1,111 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import 'constants.dart';
|
||||
import 'platform_selector.dart';
|
||||
|
||||
class DefaultValuesPage extends StatelessWidget {
|
||||
DefaultValuesPage({
|
||||
Key? key,
|
||||
required this.onChangedPlatform,
|
||||
}) : super(key: key);
|
||||
|
||||
static const String route = 'default-values';
|
||||
static const String title = 'Default API Values Example';
|
||||
static const String subtitle =
|
||||
'Shows what happens when you pass various things into contextMenuBuilder.';
|
||||
|
||||
final PlatformCallback onChangedPlatform;
|
||||
|
||||
final TextEditingController _controllerNone = TextEditingController(
|
||||
text: "When contextMenuBuilder isn't given anything at all.",
|
||||
);
|
||||
|
||||
final TextEditingController _controllerNull = TextEditingController(
|
||||
text: "When contextMenuBuilder is explicitly given null.",
|
||||
);
|
||||
|
||||
final TextEditingController _controllerCustom = TextEditingController(
|
||||
text: "When something custom is passed to contextMenuBuilder.",
|
||||
);
|
||||
|
||||
static const String url = '$kCodeUrl/default_values_page.dart';
|
||||
|
||||
DialogRoute _showDialog(BuildContext context, String message) {
|
||||
return DialogRoute<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) => AlertDialog(title: Text(message)),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text(DefaultValuesPage.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: 400.0,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
const Text(
|
||||
'This example simply shows what happens when contextMenuBuilder is given null, a custom value, or omitted altogether.',
|
||||
),
|
||||
const SizedBox(
|
||||
height: 40.0,
|
||||
),
|
||||
TextField(
|
||||
maxLines: 2,
|
||||
minLines: 2,
|
||||
controller: _controllerNone,
|
||||
),
|
||||
TextField(
|
||||
maxLines: 2,
|
||||
minLines: 2,
|
||||
controller: _controllerNull,
|
||||
contextMenuBuilder: null,
|
||||
),
|
||||
TextField(
|
||||
maxLines: 2,
|
||||
minLines: 2,
|
||||
controller: _controllerCustom,
|
||||
contextMenuBuilder: (BuildContext context,
|
||||
EditableTextState editableTextState) {
|
||||
return AdaptiveTextSelectionToolbar.buttonItems(
|
||||
anchors: editableTextState.contextMenuAnchors,
|
||||
buttonItems: <ContextMenuButtonItem>[
|
||||
ContextMenuButtonItem(
|
||||
label: 'Custom button',
|
||||
onPressed: () {
|
||||
ContextMenuController.removeAny();
|
||||
Navigator.of(context).push(_showDialog(
|
||||
context, 'You clicked the custom button.'));
|
||||
},
|
||||
),
|
||||
...editableTextState.contextMenuButtonItems,
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user