Repository navigation
no object passed when an event occur in any flutter widget #50634
Description
Activity
- addedframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.c: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutter
on Feb 12, 2020 Not sure why you need it, but you could just call another function from the onPressed handler and pass it the current widget state (
this):Container( padding: EdgeInsets.all(0), child: IconButton( icon: (_isFavorited ? Icon(Icons.star) : Icon(Icons.star_border)), color: Colors.red[500], onPressed: (){ yourFunction(this); // <-- } ), ),
Does that work for you? What more would you need? And for what use case?
- addedwaiting for responseThe Flutter team cannot make further progress on this issue until the original reporter respondsThe Flutter team cannot make further progress on this issue until the original reporter responds
on Feb 12, 2020 thx for the response , i try that but the
thisreturn the parent object ofContainerwhich is in our case
_FavoriteWidgetState;- removedwaiting for responseThe Flutter team cannot make further progress on this issue until the original reporter respondsThe Flutter team cannot make further progress on this issue until the original reporter responds
on Feb 13, 2020 You can pass whatever you want in there. It doesn't have to be
this.Also, why do you need this? What is the use case?
- addedwaiting for responseThe Flutter team cannot make further progress on this issue until the original reporter respondsThe Flutter team cannot make further progress on this issue until the original reporter responds
on Feb 14, 2020 You can pass whatever you want in there. It doesn't have to be
this.
the problem is notthis, what i realy want is some thing similar to this:onPressed: (IconButton object){ //some code }why do you need this? What is the use case?
this example is not my case i just copy it from flutter documentation for demonstration
my case is the folowingContainer( padding: EdgeInsets.all(32), child: Column( children: <Widget>[ for (Category i in allCategories ) SwitchListTile( key: Key(i.id.toString()), activeColor: Colors.amber, activeTrackColor: Colors.red, inactiveTrackColor: Colors.blueAccent, title: Text(i.titre,style: TextStyle(color: Colors.white),), value: _value, onChanged:(bool value){ // some code }, ), ], ), )i generate a dynamic widget list base on a object List (allCategories), and each widget in the widget List has a key which i need it to do my logic in the onChanged method , what i want is some thing similar to this .
onChanged:(SwitchListTile value){ // some code },- removedwaiting for responseThe Flutter team cannot make further progress on this issue until the original reporter respondsThe Flutter team cannot make further progress on this issue until the original reporter responds
on Feb 14, 2020 Thanks for your question lionviskame , I have the same problem ..
- addedc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capability
on Jul 31, 2020 - changed the title
[-]missing important feature[/-][+]no object passed when an event occur in any flutter widget [/+]on Jul 31, 2020 I am going to close this as there are ways around this as described in my previous comments.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.- locked as resolved and limited conversation to collaborators
on Oct 18, 2022
i have noticed that there is no object (widget in current state) passed when an event occur in any flutter widget .
if we take this example
we notice "onPressed" within "IconButton" widget doesn't have a function signature that allow the object(widget in the current state) to be passed as argument like java(native android app) or c#(winforms) did , that would be hell for dynamic widget generation or some generic logic. it would be very nice if you take this as a new feature or fix . thx