Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- void main() => runApp(MyApp());
- class MyApp extends StatelessWidget {
- // This widget is the root of your application.
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'Flutter Demo',
- theme: ThemeData(
- primarySwatch: Colors.blue,
- ),
- home: MyHomePage(title: 'Context Menu'),
- );
- }
- }
- class MyHomePage extends StatefulWidget {
- MyHomePage({Key key, this.title}) : super(key: key);
- final String title;
- @override
- _MyHomePageState createState() => _MyHomePageState();
- }
- class _MyHomePageState extends State<MyHomePage> {
- final _controller = new TextEditingController();
- final _textfieldFocusNode = new FocusNode();
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text(widget.title),
- ),
- body: Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Padding(
- padding: EdgeInsets.all(20.0),
- child: GestureDetector(
- // intercept all pointer calls
- behavior: HitTestBehavior.opaque,
- onTap: () {
- FocusScope.of(context).requestFocus(_textfieldFocusNode);
- },
- onLongPress: () {
- showMenu(
- context: context,
- // TODO: Position dynamically based on cursor or textfield
- position: RelativeRect.fromLTRB(0.0, 400.0, 300.0, 0.0),
- items: [
- PopupMenuItem(
- child: Row(
- children: <Widget>[
- // TODO: Dynamic items / handle click
- PopupMenuItem(
- child: Text(
- "Paste",
- ),
- ),
- PopupMenuItem(
- child: Text("Paste All",
- style: TextStyle(color: Colors.blue)
- ),
- ),
- PopupMenuItem(
- // child: Icon(Icons.more_vert),
- child:Icon(Icons.play_circle_filled),
- ),
- ],
- ),
- ),
- ],
- );
- },
- child: IgnorePointer(
- // Prevent the menu due to tap on the textfield (so as to show the menu under GestureDetector)
- child: TextField(
- focusNode: _textfieldFocusNode,
- controller: _controller,
- ),
- ),
- ),
- )
- ],
- ),
- ),
- );
- }
- }
Add Comment
Please, Sign In to add comment