mirror of
https://github.com/flutter/samples.git
synced 2025-11-09 14:28:51 +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
82 lines
2.6 KiB
Dart
82 lines
2.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
import 'constants.dart';
|
|
import 'platform_selector.dart';
|
|
|
|
class GlobalSelectionPage extends StatelessWidget {
|
|
GlobalSelectionPage({
|
|
Key? key,
|
|
required this.onChangedPlatform,
|
|
}) : super(key: key);
|
|
|
|
static const String route = 'global-selection';
|
|
static const String title = 'Global Selection Example';
|
|
static const String subtitle = 'Context menus in and out of global selection';
|
|
static const String url = '$kCodeUrl/global_selection_page.dart';
|
|
|
|
final PlatformCallback onChangedPlatform;
|
|
|
|
final TextEditingController _controller = TextEditingController(
|
|
text: 'TextFields still show their specific context menu.',
|
|
);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SelectionArea(
|
|
contextMenuBuilder:
|
|
(BuildContext context, SelectableRegionState selectableRegionState) {
|
|
return AdaptiveTextSelectionToolbar.buttonItems(
|
|
anchors: selectableRegionState.contextMenuAnchors,
|
|
buttonItems: <ContextMenuButtonItem>[
|
|
...selectableRegionState.contextMenuButtonItems,
|
|
ContextMenuButtonItem(
|
|
onPressed: () {
|
|
ContextMenuController.removeAny();
|
|
Navigator.of(context).pop();
|
|
},
|
|
label: 'Back',
|
|
),
|
|
],
|
|
);
|
|
},
|
|
child: Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text(GlobalSelectionPage.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: ListView(
|
|
children: <Widget>[
|
|
const SizedBox(height: 20.0),
|
|
const Text(
|
|
'This entire page is wrapped in a SelectionArea with a custom context menu. Clicking on any of the plain text, including the AppBar title, will show the custom menu.',
|
|
),
|
|
const SizedBox(height: 40.0),
|
|
TextField(controller: _controller),
|
|
const SizedBox(height: 40.0),
|
|
const SelectableText(
|
|
'SelectableText also shows its own separate context menu.'),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|