How to force Flutter to rebuild / redraw all widgets?

后端 未结 9 1608
攒了一身酷
攒了一身酷 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:12

    I explain how to create a custom 'AppBuilder' widget in this post.

    https://hillelcoren.com/2018/08/15/flutter-how-to-rebuild-the-entire-app-to-change-the-theme-or-locale/

    You can use the widget by wrapping your MaterialApp with it, for example:

    Widget build(BuildContext context) {
      return AppBuilder(builder: (context) {
        return MaterialApp(
          ...
        );
      });
    }
    

    You can tell the app to rebuild using:

    AppBuilder.of(context).rebuild();
    

提交回复
热议问题