mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +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
96
context_menus/lib/custom_menu_page.dart
Normal file
96
context_menus/lib/custom_menu_page.dart
Normal file
@@ -0,0 +1,96 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import 'constants.dart';
|
||||
import 'platform_selector.dart';
|
||||
|
||||
class CustomMenuPage extends StatelessWidget {
|
||||
CustomMenuPage({
|
||||
super.key,
|
||||
required this.onChangedPlatform,
|
||||
});
|
||||
|
||||
static const String route = 'custom-menu';
|
||||
static const String title = 'Custom Menu';
|
||||
static const String subtitle =
|
||||
'A custom menu built from scratch, but using the default buttons.';
|
||||
|
||||
final PlatformCallback onChangedPlatform;
|
||||
|
||||
final TextEditingController _controller = TextEditingController(
|
||||
text: 'Show the menu to see a custom menu with the default buttons.',
|
||||
);
|
||||
|
||||
static const String url = '$kCodeUrl/custom_menu_page.dart';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text(CustomMenuPage.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: TextField(
|
||||
controller: _controller,
|
||||
maxLines: 4,
|
||||
minLines: 2,
|
||||
contextMenuBuilder: (context, editableTextState) {
|
||||
return _MyContextMenu(
|
||||
anchor: editableTextState.contextMenuAnchors.primaryAnchor,
|
||||
children: AdaptiveTextSelectionToolbar.getAdaptiveButtons(
|
||||
context,
|
||||
editableTextState.contextMenuButtonItems,
|
||||
).toList(),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _MyContextMenu extends StatelessWidget {
|
||||
const _MyContextMenu({
|
||||
required this.anchor,
|
||||
required this.children,
|
||||
});
|
||||
|
||||
final Offset anchor;
|
||||
final List<Widget> children;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Stack(
|
||||
children: <Widget>[
|
||||
Positioned(
|
||||
top: anchor.dy,
|
||||
left: anchor.dx,
|
||||
child: Container(
|
||||
width: 200.0,
|
||||
height: 200.0,
|
||||
color: Colors.amberAccent,
|
||||
child: Column(
|
||||
children: children,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user