Is there a way to rebuild the whole app include const widgets in flutter project?
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
add a comment |
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
There is, that isInheritedwidget
. Did you useLocalization
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
add a comment |
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
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
widget flutter const rebuild
edited Nov 25 '18 at 15:35
01leo
526115
526115
asked Nov 23 '18 at 4:05
huuanghuuang
9211
9211
There is, that isInheritedwidget
. Did you useLocalization
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
add a comment |
There is, that isInheritedwidget
. Did you useLocalization
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
add a comment |
2 Answers
2
active
oldest
votes
'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
add a comment |
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 !
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 theconst
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
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%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
'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
add a comment |
'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
add a comment |
'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
'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
answered Nov 23 '18 at 7:50
Rémi RousseletRémi Rousselet
34.7k381106
34.7k381106
add a comment |
add a comment |
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 !
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 theconst
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
add a comment |
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 !
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 theconst
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
add a comment |
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 !
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 !
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 theconst
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
add a comment |
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 theconst
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
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.
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%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
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
There is, that is
Inheritedwidget
. Did you useLocalization
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