Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

usage of generics in flutter dart

Tags:

flutter

dart

Can somebody explain the usage of <MyApp> ?

MyAppState is extended of State class , but what is MyApp?

I know OOP in php but can't understand this one.

class MyApp extends StatefulWidget{
  @override
  MyAppState createState() => new MyAppState();
}


class MyAppState extends State<MyApp>{
  @override
  Widget build(BuildContext context) {
    return new Scaffold(...);
  }
}
like image 740
Daniel Dez Avatar asked Nov 18 '18 20:11

Daniel Dez


1 Answers

Always remember that State<T> class is implemented as a generic class

when you extend any generic class you have to specify the type for it which happen to be your statful widget concrete implementation and its name is MyApp

for every concrete implementation for the StatfulWidget class you need to define another concrete implementation of a class extending State<MyApp> and its name is MyAppState because State<T> is a generic class we code it as State<MyApp>

so as answer to your question

MyApp is the name of the concrete implementation of the class StatefulWidget

StatefulWidget -----> class not generic

MyApp -------------> concrete implementation for StatefulWidget class

State -----------> generic class of

MyAppState --> concrete implementation for State

Hope that help ..

like image 116
Saed Nabil Avatar answered Sep 17 '22 13:09

Saed Nabil