mirror of
https://github.com/flutter/samples.git
synced 2026-04-15 03:22:59 +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
101
experimental/context_menus/lib/anywhere_page.dart
Normal file
101
experimental/context_menus/lib/anywhere_page.dart
Normal file
@@ -0,0 +1,101 @@
|
||||
import 'package:flutter/cupertino.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 AnywherePage extends StatelessWidget {
|
||||
AnywherePage({
|
||||
Key? key,
|
||||
required this.onChangedPlatform,
|
||||
}) : super(key: key);
|
||||
|
||||
static const String route = 'anywhere';
|
||||
static const String title = 'Context Menu Anywhere Example';
|
||||
static const String subtitle = 'A ContextMenu outside of a text field';
|
||||
|
||||
final PlatformCallback onChangedPlatform;
|
||||
|
||||
final TextEditingController _materialController = TextEditingController(
|
||||
text: 'TextField shows the default menu still.',
|
||||
);
|
||||
final TextEditingController _cupertinoController = TextEditingController(
|
||||
text: 'CupertinoTextField shows the default menu still.',
|
||||
);
|
||||
final TextEditingController _editableController = TextEditingController(
|
||||
text: 'EditableText has no default menu, so it shows the custom one.',
|
||||
);
|
||||
|
||||
static const String url = '$kCodeUrl/anywhere_page.dart';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text(AnywherePage.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: ContextMenuRegion(
|
||||
contextMenuBuilder: (BuildContext context, Offset primaryAnchor,
|
||||
[Offset? secondaryAnchor]) {
|
||||
return AdaptiveTextSelectionToolbar.buttonItems(
|
||||
anchors: TextSelectionToolbarAnchors(
|
||||
primaryAnchor: primaryAnchor,
|
||||
secondaryAnchor: secondaryAnchor,
|
||||
),
|
||||
buttonItems: <ContextMenuButtonItem>[
|
||||
ContextMenuButtonItem(
|
||||
onPressed: () {
|
||||
ContextMenuController.removeAny();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
label: 'Back',
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 64.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Container(height: 20.0),
|
||||
const Text(
|
||||
'Right click anywhere outside of a field to show a custom menu.',
|
||||
),
|
||||
Container(height: 140.0),
|
||||
CupertinoTextField(controller: _cupertinoController),
|
||||
Container(height: 40.0),
|
||||
TextField(controller: _materialController),
|
||||
Container(height: 40.0),
|
||||
Container(
|
||||
color: Colors.white,
|
||||
child: EditableText(
|
||||
controller: _editableController,
|
||||
focusNode: FocusNode(),
|
||||
style: Typography.material2021().black.displayMedium!,
|
||||
cursorColor: Colors.blue,
|
||||
backgroundCursorColor: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user