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:
committed by
GitHub
parent
708fe97f9e
commit
125543505d
@@ -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,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user