mcSukhi

61998560

May 28th, 2020
841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() => runApp(MyApp());
  4.  
  5. class MyApp extends StatelessWidget {
  6. // This widget is the root of your application.
  7. @override
  8. Widget build(BuildContext context) {
  9. return MaterialApp(
  10. title: 'Flutter Demo',
  11. theme: ThemeData(
  12. primarySwatch: Colors.blue,
  13. ),
  14. home: MyHomePage(title: 'Context Menu'),
  15. );
  16. }
  17. }
  18.  
  19. class MyHomePage extends StatefulWidget {
  20. MyHomePage({Key key, this.title}) : super(key: key);
  21.  
  22. final String title;
  23.  
  24. @override
  25. _MyHomePageState createState() => _MyHomePageState();
  26. }
  27.  
  28. class _MyHomePageState extends State<MyHomePage> {
  29. final _controller = new TextEditingController();
  30. final _textfieldFocusNode = new FocusNode();
  31.  
  32. @override
  33. Widget build(BuildContext context) {
  34. return Scaffold(
  35. appBar: AppBar(
  36. title: Text(widget.title),
  37. ),
  38. body: Center(
  39. child: Column(
  40. mainAxisAlignment: MainAxisAlignment.center,
  41. children: <Widget>[
  42. Padding(
  43. padding: EdgeInsets.all(20.0),
  44. child: GestureDetector(
  45. // intercept all pointer calls
  46. behavior: HitTestBehavior.opaque,
  47. onTap: () {
  48. FocusScope.of(context).requestFocus(_textfieldFocusNode);
  49. },
  50. onLongPress: () {
  51. showMenu(
  52. context: context,
  53. // TODO: Position dynamically based on cursor or textfield
  54. position: RelativeRect.fromLTRB(0.0, 400.0, 300.0, 0.0),
  55. items: [
  56. PopupMenuItem(
  57. child: Row(
  58. children: <Widget>[
  59. // TODO: Dynamic items / handle click
  60. PopupMenuItem(
  61. child: Text(
  62. "Paste",
  63. ),
  64. ),
  65. PopupMenuItem(
  66. child: Text("Paste All",
  67. style: TextStyle(color: Colors.blue)
  68. ),
  69. ),
  70. PopupMenuItem(
  71. // child: Icon(Icons.more_vert),
  72. child:Icon(Icons.play_circle_filled),
  73. ),
  74. ],
  75. ),
  76. ),
  77. ],
  78. );
  79. },
  80. child: IgnorePointer(
  81. // Prevent the menu due to tap on the textfield (so as to show the menu under GestureDetector)
  82. child: TextField(
  83. focusNode: _textfieldFocusNode,
  84. controller: _controller,
  85. ),
  86. ),
  87. ),
  88. )
  89. ],
  90. ),
  91. ),
  92. );
  93. }
  94. }
Add Comment
Please, Sign In to add comment