How to force Flutter to rebuild / redraw all widgets?

后端 未结 9 1599
攒了一身酷
攒了一身酷 2020-12-03 06:32

Is there a way to force Flutter to redraw all widgets (e.g. after locale change)?

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 07:05

    What might work for your use case is using the Navigator to reload the page. I do this when switching between "real" and "demo" mode in my app. Here's an example :

    Navigator.of(context).push(
        new MaterialPageRoute(
            builder: (BuildContext context){
              return new SplashPage();
            }
        )
    );
    

    You can replace "new SplashPage()" in the above code with whatever main widget (or screen) you would like to reload. This code can be called from anywhere you have access to a BuildContext (which is most places in the UI).

提交回复
热议问题