Flutter dart call super of super class method

Viewed 692

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 from Picture abstract class. (ie. fetches server data and stores them inside variables of Picture). What I want to do is I want to extend from this widgets state so that I can create a new widget RoundedProfilePicture. This widgets state will basically utilize the complicated code from ProfilePicture'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 far

class 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() in RoundedProfilePictureState requires me to make a super.initState() call. This call makes a ProfilePictureState.initState() call. I want to call State<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 from RoundedProfilePictureState? Is this possible?

1 Answers

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.

Related