Is there a way to rebuild the whole app include const widgets in flutter project?












0















In my Flutter project, to improve performance I created many const widgets, these widgets will not rebuild when their parent widgets rebuild.



But after the user changes language of the app, I need to rebuild the whole app to apply the text changes.



Is there a way to force the app to completely rebuild? Thanks, any advice would be appreciated.










share|improve this question

























  • There is, that is Inheritedwidget. Did you use Localization widget or made everything yourself? Because that widget provided by Flutter already handles everything

    – Rémi Rousselet
    Nov 23 '18 at 7:44











  • High is an adjective and cannot be used in the context: "to high performance". You should use "to improve performance" instead

    – 01leo
    Nov 23 '18 at 14:31











  • Thank you @RémiRousselet, I made everything by myself. Inheritedwidget looks like not working for my situation.

    – huuang
    Nov 24 '18 at 13:43













  • I am sorry for my poor English, thank you @01leo

    – huuang
    Nov 24 '18 at 13:45
















0















In my Flutter project, to improve performance I created many const widgets, these widgets will not rebuild when their parent widgets rebuild.



But after the user changes language of the app, I need to rebuild the whole app to apply the text changes.



Is there a way to force the app to completely rebuild? Thanks, any advice would be appreciated.










share|improve this question

























  • There is, that is Inheritedwidget. Did you use Localization widget or made everything yourself? Because that widget provided by Flutter already handles everything

    – Rémi Rousselet
    Nov 23 '18 at 7:44











  • High is an adjective and cannot be used in the context: "to high performance". You should use "to improve performance" instead

    – 01leo
    Nov 23 '18 at 14:31











  • Thank you @RémiRousselet, I made everything by myself. Inheritedwidget looks like not working for my situation.

    – huuang
    Nov 24 '18 at 13:43













  • I am sorry for my poor English, thank you @01leo

    – huuang
    Nov 24 '18 at 13:45














0












0








0


2






In my Flutter project, to improve performance I created many const widgets, these widgets will not rebuild when their parent widgets rebuild.



But after the user changes language of the app, I need to rebuild the whole app to apply the text changes.



Is there a way to force the app to completely rebuild? Thanks, any advice would be appreciated.










share|improve this question
















In my Flutter project, to improve performance I created many const widgets, these widgets will not rebuild when their parent widgets rebuild.



But after the user changes language of the app, I need to rebuild the whole app to apply the text changes.



Is there a way to force the app to completely rebuild? Thanks, any advice would be appreciated.







widget flutter const rebuild






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 15:35









01leo

526115




526115










asked Nov 23 '18 at 4:05









huuanghuuang

9211




9211













  • There is, that is Inheritedwidget. Did you use Localization widget or made everything yourself? Because that widget provided by Flutter already handles everything

    – Rémi Rousselet
    Nov 23 '18 at 7:44











  • High is an adjective and cannot be used in the context: "to high performance". You should use "to improve performance" instead

    – 01leo
    Nov 23 '18 at 14:31











  • Thank you @RémiRousselet, I made everything by myself. Inheritedwidget looks like not working for my situation.

    – huuang
    Nov 24 '18 at 13:43













  • I am sorry for my poor English, thank you @01leo

    – huuang
    Nov 24 '18 at 13:45



















  • There is, that is Inheritedwidget. Did you use Localization widget or made everything yourself? Because that widget provided by Flutter already handles everything

    – Rémi Rousselet
    Nov 23 '18 at 7:44











  • High is an adjective and cannot be used in the context: "to high performance". You should use "to improve performance" instead

    – 01leo
    Nov 23 '18 at 14:31











  • Thank you @RémiRousselet, I made everything by myself. Inheritedwidget looks like not working for my situation.

    – huuang
    Nov 24 '18 at 13:43













  • I am sorry for my poor English, thank you @01leo

    – huuang
    Nov 24 '18 at 13:45

















There is, that is Inheritedwidget. Did you use Localization widget or made everything yourself? Because that widget provided by Flutter already handles everything

– Rémi Rousselet
Nov 23 '18 at 7:44





There is, that is Inheritedwidget. Did you use Localization widget or made everything yourself? Because that widget provided by Flutter already handles everything

– Rémi Rousselet
Nov 23 '18 at 7:44













High is an adjective and cannot be used in the context: "to high performance". You should use "to improve performance" instead

– 01leo
Nov 23 '18 at 14:31





High is an adjective and cannot be used in the context: "to high performance". You should use "to improve performance" instead

– 01leo
Nov 23 '18 at 14:31













Thank you @RémiRousselet, I made everything by myself. Inheritedwidget looks like not working for my situation.

– huuang
Nov 24 '18 at 13:43







Thank you @RémiRousselet, I made everything by myself. Inheritedwidget looks like not working for my situation.

– huuang
Nov 24 '18 at 13:43















I am sorry for my poor English, thank you @01leo

– huuang
Nov 24 '18 at 13:45





I am sorry for my poor English, thank you @01leo

– huuang
Nov 24 '18 at 13:45












2 Answers
2






active

oldest

votes


















2














'Inheritedwidget` is a solution to redraw any widget when the passed value change. Even stateless and const widgets.



For translations for example, flutter already provides an InheritedWidget, which you can bind to using Localizations.of method






share|improve this answer































    1














    yes there is a way to do it. you have to do full restart (now it's called Hot Restart) in the code, the way to do it is to put your App inside a static widget(why static? because it'll be created once just to avoid the null or anything like that). and when you want to do full restart, just perform a hot-reload in that widget, after that it'll restart your app. you can use it from everywhere



    here is the way :



    1- first in main.dart, put the your App inside the Restart widget :



    import 'package:flutter/material.dart';
    import 'home.dart';

    void main() {
    runApp(new HotRestartController(
    child: new MyApp()
    ));
    }


    2- write your hotRestartController inside the file :



    class HotRestartController extends StatefulWidget {
    final Widget child;

    HotRestartController({this.child});

    static performHotRestart(BuildContext context) {
    final _HotRestartControllerState state = context.ancestorStateOfType(const TypeMatcher<_HotRestartControllerState>());
    state.performHotRestart();
    }

    @override
    _HotRestartControllerState createState() => new _HotRestartControllerState();
    }

    class _HotRestartControllerState extends State<HotRestartController> {
    Key key = new UniqueKey();

    void performHotRestart() {
    this.setState(() {
    key = new UniqueKey();
    });
    }

    @override
    Widget build(BuildContext context) {
    return new Container(
    key: key,
    child: widget.child,
    );
    }
    }


    3- anytime, anywhere you can import the main.dart, and call "performHotRestart" using:



    HotRestartController.restartApp(context)


    have fun !






    share|improve this answer
























    • That's not what the OP is asking for

      – Rémi Rousselet
      Nov 23 '18 at 7:44











    • he is asking for "a way to force to rebuild the whole app", this is the way 😅

      – Yousuf AL-Mawali
      Nov 23 '18 at 7:52











    • He's asking for a way to update all the const widget that depends on translations, not to hard reset everything. Or else this is a duplicate question and I'll close it.

      – Rémi Rousselet
      Nov 23 '18 at 8:02











    • The answer you provided already exists here stackoverflow.com/questions/50115311/…. It's literally the same code

      – Rémi Rousselet
      Nov 23 '18 at 8:04













    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%2f53440528%2fis-there-a-way-to-rebuild-the-whole-app-include-const-widgets-in-flutter-project%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    'Inheritedwidget` is a solution to redraw any widget when the passed value change. Even stateless and const widgets.



    For translations for example, flutter already provides an InheritedWidget, which you can bind to using Localizations.of method






    share|improve this answer




























      2














      'Inheritedwidget` is a solution to redraw any widget when the passed value change. Even stateless and const widgets.



      For translations for example, flutter already provides an InheritedWidget, which you can bind to using Localizations.of method






      share|improve this answer


























        2












        2








        2







        'Inheritedwidget` is a solution to redraw any widget when the passed value change. Even stateless and const widgets.



        For translations for example, flutter already provides an InheritedWidget, which you can bind to using Localizations.of method






        share|improve this answer













        'Inheritedwidget` is a solution to redraw any widget when the passed value change. Even stateless and const widgets.



        For translations for example, flutter already provides an InheritedWidget, which you can bind to using Localizations.of method







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 7:50









        Rémi RousseletRémi Rousselet

        34.7k381106




        34.7k381106

























            1














            yes there is a way to do it. you have to do full restart (now it's called Hot Restart) in the code, the way to do it is to put your App inside a static widget(why static? because it'll be created once just to avoid the null or anything like that). and when you want to do full restart, just perform a hot-reload in that widget, after that it'll restart your app. you can use it from everywhere



            here is the way :



            1- first in main.dart, put the your App inside the Restart widget :



            import 'package:flutter/material.dart';
            import 'home.dart';

            void main() {
            runApp(new HotRestartController(
            child: new MyApp()
            ));
            }


            2- write your hotRestartController inside the file :



            class HotRestartController extends StatefulWidget {
            final Widget child;

            HotRestartController({this.child});

            static performHotRestart(BuildContext context) {
            final _HotRestartControllerState state = context.ancestorStateOfType(const TypeMatcher<_HotRestartControllerState>());
            state.performHotRestart();
            }

            @override
            _HotRestartControllerState createState() => new _HotRestartControllerState();
            }

            class _HotRestartControllerState extends State<HotRestartController> {
            Key key = new UniqueKey();

            void performHotRestart() {
            this.setState(() {
            key = new UniqueKey();
            });
            }

            @override
            Widget build(BuildContext context) {
            return new Container(
            key: key,
            child: widget.child,
            );
            }
            }


            3- anytime, anywhere you can import the main.dart, and call "performHotRestart" using:



            HotRestartController.restartApp(context)


            have fun !






            share|improve this answer
























            • That's not what the OP is asking for

              – Rémi Rousselet
              Nov 23 '18 at 7:44











            • he is asking for "a way to force to rebuild the whole app", this is the way 😅

              – Yousuf AL-Mawali
              Nov 23 '18 at 7:52











            • He's asking for a way to update all the const widget that depends on translations, not to hard reset everything. Or else this is a duplicate question and I'll close it.

              – Rémi Rousselet
              Nov 23 '18 at 8:02











            • The answer you provided already exists here stackoverflow.com/questions/50115311/…. It's literally the same code

              – Rémi Rousselet
              Nov 23 '18 at 8:04


















            1














            yes there is a way to do it. you have to do full restart (now it's called Hot Restart) in the code, the way to do it is to put your App inside a static widget(why static? because it'll be created once just to avoid the null or anything like that). and when you want to do full restart, just perform a hot-reload in that widget, after that it'll restart your app. you can use it from everywhere



            here is the way :



            1- first in main.dart, put the your App inside the Restart widget :



            import 'package:flutter/material.dart';
            import 'home.dart';

            void main() {
            runApp(new HotRestartController(
            child: new MyApp()
            ));
            }


            2- write your hotRestartController inside the file :



            class HotRestartController extends StatefulWidget {
            final Widget child;

            HotRestartController({this.child});

            static performHotRestart(BuildContext context) {
            final _HotRestartControllerState state = context.ancestorStateOfType(const TypeMatcher<_HotRestartControllerState>());
            state.performHotRestart();
            }

            @override
            _HotRestartControllerState createState() => new _HotRestartControllerState();
            }

            class _HotRestartControllerState extends State<HotRestartController> {
            Key key = new UniqueKey();

            void performHotRestart() {
            this.setState(() {
            key = new UniqueKey();
            });
            }

            @override
            Widget build(BuildContext context) {
            return new Container(
            key: key,
            child: widget.child,
            );
            }
            }


            3- anytime, anywhere you can import the main.dart, and call "performHotRestart" using:



            HotRestartController.restartApp(context)


            have fun !






            share|improve this answer
























            • That's not what the OP is asking for

              – Rémi Rousselet
              Nov 23 '18 at 7:44











            • he is asking for "a way to force to rebuild the whole app", this is the way 😅

              – Yousuf AL-Mawali
              Nov 23 '18 at 7:52











            • He's asking for a way to update all the const widget that depends on translations, not to hard reset everything. Or else this is a duplicate question and I'll close it.

              – Rémi Rousselet
              Nov 23 '18 at 8:02











            • The answer you provided already exists here stackoverflow.com/questions/50115311/…. It's literally the same code

              – Rémi Rousselet
              Nov 23 '18 at 8:04
















            1












            1








            1







            yes there is a way to do it. you have to do full restart (now it's called Hot Restart) in the code, the way to do it is to put your App inside a static widget(why static? because it'll be created once just to avoid the null or anything like that). and when you want to do full restart, just perform a hot-reload in that widget, after that it'll restart your app. you can use it from everywhere



            here is the way :



            1- first in main.dart, put the your App inside the Restart widget :



            import 'package:flutter/material.dart';
            import 'home.dart';

            void main() {
            runApp(new HotRestartController(
            child: new MyApp()
            ));
            }


            2- write your hotRestartController inside the file :



            class HotRestartController extends StatefulWidget {
            final Widget child;

            HotRestartController({this.child});

            static performHotRestart(BuildContext context) {
            final _HotRestartControllerState state = context.ancestorStateOfType(const TypeMatcher<_HotRestartControllerState>());
            state.performHotRestart();
            }

            @override
            _HotRestartControllerState createState() => new _HotRestartControllerState();
            }

            class _HotRestartControllerState extends State<HotRestartController> {
            Key key = new UniqueKey();

            void performHotRestart() {
            this.setState(() {
            key = new UniqueKey();
            });
            }

            @override
            Widget build(BuildContext context) {
            return new Container(
            key: key,
            child: widget.child,
            );
            }
            }


            3- anytime, anywhere you can import the main.dart, and call "performHotRestart" using:



            HotRestartController.restartApp(context)


            have fun !






            share|improve this answer













            yes there is a way to do it. you have to do full restart (now it's called Hot Restart) in the code, the way to do it is to put your App inside a static widget(why static? because it'll be created once just to avoid the null or anything like that). and when you want to do full restart, just perform a hot-reload in that widget, after that it'll restart your app. you can use it from everywhere



            here is the way :



            1- first in main.dart, put the your App inside the Restart widget :



            import 'package:flutter/material.dart';
            import 'home.dart';

            void main() {
            runApp(new HotRestartController(
            child: new MyApp()
            ));
            }


            2- write your hotRestartController inside the file :



            class HotRestartController extends StatefulWidget {
            final Widget child;

            HotRestartController({this.child});

            static performHotRestart(BuildContext context) {
            final _HotRestartControllerState state = context.ancestorStateOfType(const TypeMatcher<_HotRestartControllerState>());
            state.performHotRestart();
            }

            @override
            _HotRestartControllerState createState() => new _HotRestartControllerState();
            }

            class _HotRestartControllerState extends State<HotRestartController> {
            Key key = new UniqueKey();

            void performHotRestart() {
            this.setState(() {
            key = new UniqueKey();
            });
            }

            @override
            Widget build(BuildContext context) {
            return new Container(
            key: key,
            child: widget.child,
            );
            }
            }


            3- anytime, anywhere you can import the main.dart, and call "performHotRestart" using:



            HotRestartController.restartApp(context)


            have fun !







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 23 '18 at 6:22









            Yousuf AL-MawaliYousuf AL-Mawali

            786




            786













            • That's not what the OP is asking for

              – Rémi Rousselet
              Nov 23 '18 at 7:44











            • he is asking for "a way to force to rebuild the whole app", this is the way 😅

              – Yousuf AL-Mawali
              Nov 23 '18 at 7:52











            • He's asking for a way to update all the const widget that depends on translations, not to hard reset everything. Or else this is a duplicate question and I'll close it.

              – Rémi Rousselet
              Nov 23 '18 at 8:02











            • The answer you provided already exists here stackoverflow.com/questions/50115311/…. It's literally the same code

              – Rémi Rousselet
              Nov 23 '18 at 8:04





















            • That's not what the OP is asking for

              – Rémi Rousselet
              Nov 23 '18 at 7:44











            • he is asking for "a way to force to rebuild the whole app", this is the way 😅

              – Yousuf AL-Mawali
              Nov 23 '18 at 7:52











            • He's asking for a way to update all the const widget that depends on translations, not to hard reset everything. Or else this is a duplicate question and I'll close it.

              – Rémi Rousselet
              Nov 23 '18 at 8:02











            • The answer you provided already exists here stackoverflow.com/questions/50115311/…. It's literally the same code

              – Rémi Rousselet
              Nov 23 '18 at 8:04



















            That's not what the OP is asking for

            – Rémi Rousselet
            Nov 23 '18 at 7:44





            That's not what the OP is asking for

            – Rémi Rousselet
            Nov 23 '18 at 7:44













            he is asking for "a way to force to rebuild the whole app", this is the way 😅

            – Yousuf AL-Mawali
            Nov 23 '18 at 7:52





            he is asking for "a way to force to rebuild the whole app", this is the way 😅

            – Yousuf AL-Mawali
            Nov 23 '18 at 7:52













            He's asking for a way to update all the const widget that depends on translations, not to hard reset everything. Or else this is a duplicate question and I'll close it.

            – Rémi Rousselet
            Nov 23 '18 at 8:02





            He's asking for a way to update all the const widget that depends on translations, not to hard reset everything. Or else this is a duplicate question and I'll close it.

            – Rémi Rousselet
            Nov 23 '18 at 8:02













            The answer you provided already exists here stackoverflow.com/questions/50115311/…. It's literally the same code

            – Rémi Rousselet
            Nov 23 '18 at 8:04







            The answer you provided already exists here stackoverflow.com/questions/50115311/…. It's literally the same code

            – Rémi Rousselet
            Nov 23 '18 at 8:04




















            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440528%2fis-there-a-way-to-rebuild-the-whole-app-include-const-widgets-in-flutter-project%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

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            RAC Tourist Trophy