Answers for "get coordinates of touch in flutter"

0

get coordinates of touch in flutter

//Use GestureDetector
 void onTapDown(BuildContext context, TapDownDetails details) {
    print('${details.globalPosition}');
    final RenderBox box = context.findRenderObject();
    final Offset localOffset = box.globalToLocal(details.globalPosition);
    setState(() {
      posx = localOffset.dx;
      posy = localOffset.dy;
    });
    _showPopupMenu();
  }

  _showPopupMenu() {
    showMenu<String>(
      context: context,
      position: RelativeRect.fromLTRB(0.0, posy, 0.0,
          0.0), //position where you want to show the menu on screen
      items: [
        PopupMenuItem<String>(
            child: Text(
              'Edit Details',
              style: Theme.of(context).textTheme.caption,
            ),
            value: '1'),
        PopupMenuItem<String>(
            child: Text(
              'Add/Edit Photo',
              style: Theme.of(context).textTheme.caption,
            ),
            value: '2'),
        PopupMenuItem<String>(
            child: Text(
              'Add/Edit QR code',
              style: Theme.of(context).textTheme.caption,
            ),
            value: '3'),
      ],
      elevation: 8.0,
    ).then<void>((String itemSelected) {
      if (itemSelected == null) return;

      if (itemSelected == "1") {
        //code here
      } else if (itemSelected == "2") {
        //code here
      } else {
        //scan and update QR Barcode code here
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (_) => UpdateMachineCode(),
          ),
        );
      }
    });
  }
Posted by: Guest on January-21-2021

Code answers related to "get coordinates of touch in flutter"

Code answers related to "Dart"

Browse Popular Code Answers by Language