-1

I am successfully able to make a reusable stateful widget and added text but don't know about how to make reusable gesture detector

class HomeScreen extends StatefulWidget {
  final String collectionName;

  HomeScreen(this.collectionName);

  @override
  _HomeScreenState createState() => _HomeScreenState();
}

Text(widget.collectionName)

How to use a gesture detector like TEXT ????

Chirag Chopra
  • 132
  • 1
  • 7

2 Answers2

1

I think what you want to do is add GestureDetector to your text and pass the function via HomeScreen. If that's what you are looking for then

class HomeScreen extends StatefulWidget {
  final String collectionName;
  final VoidCallBack onTap;

  HomeScreen(this.collectionName,this.onTap);

  @override
 _HomeScreenState createState() => _HomeScreenState();
}

Your Text widget will be updated as

GestureDetector(
  onTap:widget.onTap,
  child:Text(widget.collectionName)
);
Shubham Gupta
  • 1,917
  • 1
  • 10
  • 16
0

Example of how you can do this...

Make this..

Widget gestureDetectorforText(dynamic theText){
  return GestureDetector(
    onTap: your function here..
    child: Text(theText)
  );
 }

So using that code means that you need to pass your widget.collectionName into it..

So whenever you call the widget gestureDetector()

You pass the widget.collection name into it like this..

gesturedetector(widget.collectionName);

Shubham Gupta
  • 1,917
  • 1
  • 10
  • 16
Jesus Loves You
  • 261
  • 5
  • 17