Native ios context menu (#143002)

It's now possible to use the native-rendered text selection context menu on iOS. This sacrifices customizability in exchange for avoiding showing a notification when the user presses "Paste". It's off by default, but to enable, see the example system_context_menu.0.dart.
This commit is contained in:
Justin McCandless
2024-05-13 08:48:56 -07:00
committed by GitHub
parent 708fe97f9e
commit 125543505d
13 changed files with 1327 additions and 49 deletions

View File

@@ -0,0 +1,41 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [SystemContextMenu].
void main() => runApp(const SystemContextMenuExampleApp());
class SystemContextMenuExampleApp extends StatelessWidget {
const SystemContextMenuExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('SystemContextMenu Basic Example'),
),
body: Center(
child: TextField(
contextMenuBuilder: (BuildContext context, EditableTextState editableTextState) {
// If supported, show the system context menu.
if (SystemContextMenu.isSupported(context)) {
return SystemContextMenu.editableText(
editableTextState: editableTextState,
);
}
// Otherwise, show the flutter-rendered context menu for the current
// platform.
return AdaptiveTextSelectionToolbar.editableText(
editableTextState: editableTextState,
);
},
),
),
),
);
}
}