I am new to flutter, I wonder why we extend Statefull or stateless classes to create our own widgets, why not creating the objects of the instead. Now many others might say it has build function that needs to be overridden but I guess it can also be done inside the object. Please give me an explanation.
CodePudding user response:
flutter has lifecycle, widget will appear after build https://i.stack.imgur.com/94idE.png
CodePudding user response:
Both Stateful and Stateless classes are abstracts.
So that, to use methods such as initState in Stateful or "build" in both kind of widgets you need extend either Stateful or Stateless (exactly "extends" keyword, if you use "implements" keyword, you will be forced to implement all of the methods described in abstract).
More about: