mirror of https://github.com/flutter/samples.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
3.2 KiB
101 lines
3.2 KiB
2 years ago
|
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({
|
||
2 years ago
|
super.key,
|
||
2 years ago
|
required this.onChangedPlatform,
|
||
2 years ago
|
});
|
||
2 years ago
|
|
||
|
static const String route = 'anywhere';
|
||
|
static const String title = 'Context Menu Anywhere Example';
|
||
2 years ago
|
static const String subtitle = 'A context menu outside of a text field';
|
||
2 years ago
|
|
||
|
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(
|
||
2 years ago
|
contextMenuBuilder: (context, primaryAnchor, [secondaryAnchor]) {
|
||
2 years ago
|
return AdaptiveTextSelectionToolbar.buttonItems(
|
||
|
anchors: TextSelectionToolbarAnchors(
|
||
|
primaryAnchor: primaryAnchor,
|
||
2 years ago
|
secondaryAnchor: secondaryAnchor as Offset?,
|
||
2 years ago
|
),
|
||
|
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,
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|