usage of generics in flutter dart












1














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(...);
}
}









share|improve this question






















  • Check this post, it's perfect to understand what you need: medium.com/flutter-community/…
    – diegoveloper
    Nov 18 '18 at 20:31
















1














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(...);
}
}









share|improve this question






















  • Check this post, it's perfect to understand what you need: medium.com/flutter-community/…
    – diegoveloper
    Nov 18 '18 at 20:31














1












1








1







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(...);
}
}









share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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


















  • 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












3 Answers
3






active

oldest

votes


















0














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.






share|improve this answer





























    0














    <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.






    share|improve this answer





























      0














      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 ..






      share|improve this answer























        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
        });


        }
        });














        draft saved

        draft discarded


















        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









        0














        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.






        share|improve this answer


























          0














          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.






          share|improve this answer
























            0












            0








            0






            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.






            share|improve this answer












            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.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 18 '18 at 21:16









            jamesdlinjamesdlin

            26.2k65992




            26.2k65992

























                0














                <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.






                share|improve this answer


























                  0














                  <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.






                  share|improve this answer
























                    0












                    0








                    0






                    <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.






                    share|improve this answer












                    <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.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 18 '18 at 21:18









                    stt106stt106

                    1,2191024




                    1,2191024























                        0














                        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 ..






                        share|improve this answer




























                          0














                          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 ..






                          share|improve this answer


























                            0












                            0








                            0






                            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 ..






                            share|improve this answer














                            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 ..







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Nov 18 '18 at 22:36

























                            answered Nov 18 '18 at 22:02









                            Saed NabilSaed Nabil

                            1,17828




                            1,17828






























                                draft saved

                                draft discarded




















































                                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.




                                draft saved


                                draft discarded














                                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





















































                                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







                                Popular posts from this blog

                                How to change which sound is reproduced for terminal bell?

                                Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

                                Can I use Tabulator js library in my java Spring + Thymeleaf project?