Flutter dart call super of super class method
Since no one answered, here is how I solved this. I think this is impossible to achieve. What I did is I moved the code and all the variables to a mixin
. Took like an hour or two to do so. I achieved my needs tho.
![cs guy](https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=256)
Comments
-
cs guy over 1 year
Here is my architecture, I have two statfull widgets:
ProfilePicture, RoundedProfilePicture
.ProfilePicture
is a statefull widget and it has complicated custom code which is very prone to error so I dont want to copy paste it, it utilizes variables fromPicture
abstract class. (ie. fetches server data and stores them inside variables ofPicture
). What I want to do is I want to extend from this widgets state so that I can create a new widgetRoundedProfilePicture
. This widgets state will basically utilize the complicated code fromProfilePicture
's state with inheritance and it will add small extra logic to it. So I thought inheritance is the best choice here. Here is what I tried so farclass ProfilePictureState extends State<ProfilePicture> implements Picture{ // SOME LONG COMPLICATED 500 LINE OF CODE } class RoundedProfilePictureState extends ProfilePictureState { @override void initState() { super.initState(); // this calls ProfilePictureState.initState() call. I want to call State<ProfilePicture>.initState() } }
My problem is void
initState()
inRoundedProfilePictureState
requires me to make asuper.initState()
call. This call makes aProfilePictureState.initState()
call. I want to callState<ProfilePicture>.initState()
because I want to add a different logic in my init state call. So the structure is:----abstract State class ---ProfilePictureState --RoundedProfilePictureState
How can I make a call to abstract State class's
initState
method fromRoundedProfilePictureState
? Is this possible?-
Randal Schwartz over 3 yearsIf you have to call super-super, the hierarchy is mis-designed. calling super means "I'm just like my parent class, except I add this additional behavior". If you ever need to ignore parent class, and skip to grandparent class, something is very wrong.
-
cs guy over 3 yearsAgreed. My hierarchy design was flawed
-