Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The method 'globalToLocal' isn't defined for the type 'RenderObject'

How to fix this. Error message: The method ‘globalToLocal’ isn’t defined for the type ‘RenderObject’.
Try correcting the name to the name of an existing method, or defining a method named ‘globalToLocal’.

enter image description here

My Code

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@override
  Widget build(BuildContext context) {            
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: GestureDetector(
          onPanUpdate: (details) {            
            setState(() {
              RenderObject? renderBox = context.findRenderObject();
              points.add(TouchPoints(
                  points: renderBox?.globalToLocal(details.globalPosition),//ERROR

>Solution :

You have to cast the object like so:

@override
  Widget build(BuildContext context) {            
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: GestureDetector(
          onPanUpdate: (details) {            
            setState(() {

              //Here at the end and at the begining of the line
              RenderBox? renderBox = context.findRenderObject() as RenderBox; 

              points.add(TouchPoints(
                  points: renderBox?.globalToLocal(details.globalPosition),//ERROR
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading