Created
January 24, 2023 23:10
-
-
Save flutterdevrelgists/e438392a0bb3c1813b042fe83abf78b7 to your computer and use it in GitHub Desktop.
Adaptive UI Talk: Example of adding a custom button to a TextField's context menu on all platforms.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: const MyHomePage(title: 'Flutter Forward 2023'), | |
); | |
} | |
} | |
class MyHomePage extends StatelessWidget { | |
const MyHomePage({super.key, required this.title}); | |
final String title; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(title), | |
), | |
body: Center( | |
child: Padding( | |
padding: const EdgeInsets.all(12.0), | |
child: TextField( | |
contextMenuBuilder: (context, editableTextState) { | |
return AdaptiveTextSelectionToolbar.buttonItems( | |
anchors: editableTextState.contextMenuAnchors, | |
buttonItems: [ | |
...editableTextState.contextMenuButtonItems, | |
ContextMenuButtonItem( | |
label: 'Share', | |
onPressed: () { }, | |
), | |
], | |
); | |
}, | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment