Issue
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'.
My Code
@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
Answered By - Felipe Morschel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.