usage of generics in 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(...);
}
}
dart flutter
add a comment |
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(...);
}
}
dart flutter
Check this post, it's perfect to understand what you need: medium.com/flutter-community/…
– diegoveloper
Nov 18 '18 at 20:31
add a comment |
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(...);
}
}
dart flutter
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(...);
}
}
dart flutter
dart flutter
asked Nov 18 '18 at 20:19
danial dezfoulidanial dezfouli
61
61
Check this post, it's perfect to understand what you need: medium.com/flutter-community/…
– diegoveloper
Nov 18 '18 at 20:31
add a comment |
Check this post, it's perfect to understand what you need: medium.com/flutter-community/…
– diegoveloper
Nov 18 '18 at 20:31
Check this post, it's perfect to understand what you need: medium.com/flutter-community/…
– diegoveloper
Nov 18 '18 at 20:31
Check this post, it's perfect to understand what you need: medium.com/flutter-community/…
– diegoveloper
Nov 18 '18 at 20:31
add a comment |
3 Answers
3
active
oldest
votes
State<MyApp>
is a State
class that is specialized for the MyApp
class. This allows it to have inheritable methods and properties that operate on or involve a MyApp
widget.
For example, it allows MyAppState.widget
to return the corresponding widget specifically as a MyApp
widget instead of as a generic StatefulWidget
. This is important if you then wanted to call MyApp
-specific properties or methods on the returned widget.
Note that this is necessary because Flutter uses type-safe Dart and tries to do as much static type-checking as possible to minimize the cost of doing type-checking at runtime.
add a comment |
<MyApp>
is a type parameter of generic type State<T>
. Not sure whether php has generics, but essentially generics allows you to reuse 'generic' code over a range of different types and in the meantime it provides more type safety e.g. generics prevents you accidentally adding a double
to a list of int
(List<int>
) for example. A native example, again, would be generic list List<T>
where the same operation like add
item to a list can be applied to a list of int (List<int>
) or a list of people or a list of anything.
Maybe check out this for generics in dart specifically.
add a comment |
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 ..
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53365051%2fusage-of-generics-in-flutter-dart%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
State<MyApp>
is a State
class that is specialized for the MyApp
class. This allows it to have inheritable methods and properties that operate on or involve a MyApp
widget.
For example, it allows MyAppState.widget
to return the corresponding widget specifically as a MyApp
widget instead of as a generic StatefulWidget
. This is important if you then wanted to call MyApp
-specific properties or methods on the returned widget.
Note that this is necessary because Flutter uses type-safe Dart and tries to do as much static type-checking as possible to minimize the cost of doing type-checking at runtime.
add a comment |
State<MyApp>
is a State
class that is specialized for the MyApp
class. This allows it to have inheritable methods and properties that operate on or involve a MyApp
widget.
For example, it allows MyAppState.widget
to return the corresponding widget specifically as a MyApp
widget instead of as a generic StatefulWidget
. This is important if you then wanted to call MyApp
-specific properties or methods on the returned widget.
Note that this is necessary because Flutter uses type-safe Dart and tries to do as much static type-checking as possible to minimize the cost of doing type-checking at runtime.
add a comment |
State<MyApp>
is a State
class that is specialized for the MyApp
class. This allows it to have inheritable methods and properties that operate on or involve a MyApp
widget.
For example, it allows MyAppState.widget
to return the corresponding widget specifically as a MyApp
widget instead of as a generic StatefulWidget
. This is important if you then wanted to call MyApp
-specific properties or methods on the returned widget.
Note that this is necessary because Flutter uses type-safe Dart and tries to do as much static type-checking as possible to minimize the cost of doing type-checking at runtime.
State<MyApp>
is a State
class that is specialized for the MyApp
class. This allows it to have inheritable methods and properties that operate on or involve a MyApp
widget.
For example, it allows MyAppState.widget
to return the corresponding widget specifically as a MyApp
widget instead of as a generic StatefulWidget
. This is important if you then wanted to call MyApp
-specific properties or methods on the returned widget.
Note that this is necessary because Flutter uses type-safe Dart and tries to do as much static type-checking as possible to minimize the cost of doing type-checking at runtime.
answered Nov 18 '18 at 21:16
jamesdlinjamesdlin
26.2k65992
26.2k65992
add a comment |
add a comment |
<MyApp>
is a type parameter of generic type State<T>
. Not sure whether php has generics, but essentially generics allows you to reuse 'generic' code over a range of different types and in the meantime it provides more type safety e.g. generics prevents you accidentally adding a double
to a list of int
(List<int>
) for example. A native example, again, would be generic list List<T>
where the same operation like add
item to a list can be applied to a list of int (List<int>
) or a list of people or a list of anything.
Maybe check out this for generics in dart specifically.
add a comment |
<MyApp>
is a type parameter of generic type State<T>
. Not sure whether php has generics, but essentially generics allows you to reuse 'generic' code over a range of different types and in the meantime it provides more type safety e.g. generics prevents you accidentally adding a double
to a list of int
(List<int>
) for example. A native example, again, would be generic list List<T>
where the same operation like add
item to a list can be applied to a list of int (List<int>
) or a list of people or a list of anything.
Maybe check out this for generics in dart specifically.
add a comment |
<MyApp>
is a type parameter of generic type State<T>
. Not sure whether php has generics, but essentially generics allows you to reuse 'generic' code over a range of different types and in the meantime it provides more type safety e.g. generics prevents you accidentally adding a double
to a list of int
(List<int>
) for example. A native example, again, would be generic list List<T>
where the same operation like add
item to a list can be applied to a list of int (List<int>
) or a list of people or a list of anything.
Maybe check out this for generics in dart specifically.
<MyApp>
is a type parameter of generic type State<T>
. Not sure whether php has generics, but essentially generics allows you to reuse 'generic' code over a range of different types and in the meantime it provides more type safety e.g. generics prevents you accidentally adding a double
to a list of int
(List<int>
) for example. A native example, again, would be generic list List<T>
where the same operation like add
item to a list can be applied to a list of int (List<int>
) or a list of people or a list of anything.
Maybe check out this for generics in dart specifically.
answered Nov 18 '18 at 21:18
stt106stt106
1,2191024
1,2191024
add a comment |
add a comment |
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 ..
add a comment |
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 ..
add a comment |
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 ..
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 ..
edited Nov 18 '18 at 22:36
answered Nov 18 '18 at 22:02
Saed NabilSaed Nabil
1,17828
1,17828
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53365051%2fusage-of-generics-in-flutter-dart%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Check this post, it's perfect to understand what you need: medium.com/flutter-community/…
– diegoveloper
Nov 18 '18 at 20:31