I am reading this doc page: https://docs.flutter.io/flutter/painting/TextSpan/recognizer.html.
The example included in this page is a StatefulWidget and the doc says The code that owns the GestureRecognizer object must call GestureRecognizer.dispose when the TextSpan object is no longer used..
I am wondering if I can use the recognizer of TextSpan in a StatelessWidget?
If so, do I need to call dispose somewhere? I have no idea where to call it.
You cannot do that in a StatelessWidget. You will have to convert it into a StatefulWidget and override the dispose method of State:
class Foo extends StatefulWidget {
@override
_FooState createState() => _FooState();
}
class _FooState extends State<Foo> {
GestureRecognizer gestureRecognizer;
@override
void dispose() {
gestureRecognizer?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Container();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With