setState() or markNeedsBuild() called > when widget tree was locked. when changing state2019 Community Moderator ElectionFlutter setState() or markNeedsBuild() called when widget tree was lockedFlutter - Implementing a Navigation drawer with a TabBarView widget with dynamic Tab viewsetState() or markNeedsBuild called during buildHow to offset a scaffold widget in Flutter?Flutter: setState() or markNeedsBuild() called when widget tree was locked… during orientation changeFlutter : Bad state: Stream has already been listened toText widget not displaying in ListTile flutterI got stuck with a problem in Flutter: The following assertion was thrown building TextField, it flesh me a stranger problemsetstate vs normal assignment in a stateful widgetpropagate state of stateful widget to its child widget
How do I deal with a powergamer in a game full of beginners in a school club?
Solving "Resistance between two nodes on a grid" problem in Mathematica
Make a transparent 448*448 image
Do Bugbears' arms literally get longer when it's their turn?
PTIJ: Why can't I eat anything?
infinitive telling the purpose
Unreachable code, but reachable with exception
Offered promotion but I'm leaving. Should I tell?
They call me Inspector Morse
Peter's Strange Word
Good for you! in Russian
Should I tell my boss the work he did was worthless
Why would a jet engine that runs at temps excess of 2000°C burn when it crashes?
Algorithm to convert a fixed-length string to the smallest possible collision-free representation?
How does airport security verify that you can carry a battery bank over 100 Wh?
A three room house but a three headED dog
Is Gradient Descent central to every optimizer?
What is the chance of making a successful appeal to dismissal decision from a PhD program after failing the qualifying exam in the 2nd attempt?
How are such low op-amp input currents possible?
Could you please stop shuffling the deck and play already?
Grey hair or white hair
Are there historical instances of the capital of a colonising country being temporarily or permanently shifted to one of its colonies?
Accountant/ lawyer will not return my call
Rejected in 4th interview round citing insufficient years of experience
setState() or markNeedsBuild() called > when widget tree was locked. when changing state
2019 Community Moderator ElectionFlutter setState() or markNeedsBuild() called when widget tree was lockedFlutter - Implementing a Navigation drawer with a TabBarView widget with dynamic Tab viewsetState() or markNeedsBuild called during buildHow to offset a scaffold widget in Flutter?Flutter: setState() or markNeedsBuild() called when widget tree was locked… during orientation changeFlutter : Bad state: Stream has already been listened toText widget not displaying in ListTile flutterI got stuck with a problem in Flutter: The following assertion was thrown building TextField, it flesh me a stranger problemsetstate vs normal assignment in a stateful widgetpropagate state of stateful widget to its child widget
Please look at my code:
class HomePageState extends State<HomePage>
bool _isLoading = false;
.....
@override
Widget build(BuildContext context)
var drawerOptions = <Widget>[];
......
drawerOptions.add(new ListTile(
leading: new Icon(Icons.account_balance),
title: new Text(Strings.menu_change_city),
onTap: () => createDialog()
));
if(_isLoading) return buildBusyForm();
return Scaffold( .... //window content
So I have navigation drawer. One item ("Select city") does not close navigation drawer, it shows select city dialog:
createDialog()
setState(() _isLoading = true;);
fetchCities().then((response)
setState(() _isLoading = false;);
showDialog(
context: context,
builder: (context) => CityChoiceDialog<City>(
title: Text(Strings.menu_change_city),
items: response,
initialValue: response.firstWhere((c) => c.id == globals.cityId, orElse: () => new City()),
itemBuilder: (City city) => Text(city.name),
onSelected: _onSelected,
onSubmitted: _onSubmitted));
);
So, basically it's intended to show busy form, load cities, then hide busy form and show cities list dialog. As it seems to work, I'm getting exception:
I/flutter (10662): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY
╞═══════════════════════════════════════════════════════════ I/flutter
(10662): The following assertion was thrown while finalizing the
widget tree: I/flutter (10662): setState() or markNeedsBuild() called
when widget tree was locked. I/flutter (10662): This
_ModalScope widget cannot be marked as needing to build because the framework is I/flutter (10662): locked. I/flutter (10662):
The widget on which setState() or markNeedsBuild() was called was:
I/flutter (10662):
_ModalScope-[LabeledGlobalKey<_ModalScopeState>#1f222](state:
I/flutter (10662): _ModalScopeState#6c40b)
How to do what I want correctly?
exception dart flutter state
add a comment |
Please look at my code:
class HomePageState extends State<HomePage>
bool _isLoading = false;
.....
@override
Widget build(BuildContext context)
var drawerOptions = <Widget>[];
......
drawerOptions.add(new ListTile(
leading: new Icon(Icons.account_balance),
title: new Text(Strings.menu_change_city),
onTap: () => createDialog()
));
if(_isLoading) return buildBusyForm();
return Scaffold( .... //window content
So I have navigation drawer. One item ("Select city") does not close navigation drawer, it shows select city dialog:
createDialog()
setState(() _isLoading = true;);
fetchCities().then((response)
setState(() _isLoading = false;);
showDialog(
context: context,
builder: (context) => CityChoiceDialog<City>(
title: Text(Strings.menu_change_city),
items: response,
initialValue: response.firstWhere((c) => c.id == globals.cityId, orElse: () => new City()),
itemBuilder: (City city) => Text(city.name),
onSelected: _onSelected,
onSubmitted: _onSubmitted));
);
So, basically it's intended to show busy form, load cities, then hide busy form and show cities list dialog. As it seems to work, I'm getting exception:
I/flutter (10662): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY
╞═══════════════════════════════════════════════════════════ I/flutter
(10662): The following assertion was thrown while finalizing the
widget tree: I/flutter (10662): setState() or markNeedsBuild() called
when widget tree was locked. I/flutter (10662): This
_ModalScope widget cannot be marked as needing to build because the framework is I/flutter (10662): locked. I/flutter (10662):
The widget on which setState() or markNeedsBuild() was called was:
I/flutter (10662):
_ModalScope-[LabeledGlobalKey<_ModalScopeState>#1f222](state:
I/flutter (10662): _ModalScopeState#6c40b)
How to do what I want correctly?
exception dart flutter state
how exactly are you closing your drawer ?
– Mazin Ibrahim
Mar 7 at 8:27
I noticed problem can be solved if I close drawer before attempting to change state. If drawer is still open and I want to change state, I'm getting this exception.
– user1209216
Mar 7 at 12:15
this kind of exception is noticed in the debugger only, but when you run this app on an actual device it won't have any noticeable effects.I tried that.
– Mazin Ibrahim
Mar 7 at 12:19
add a comment |
Please look at my code:
class HomePageState extends State<HomePage>
bool _isLoading = false;
.....
@override
Widget build(BuildContext context)
var drawerOptions = <Widget>[];
......
drawerOptions.add(new ListTile(
leading: new Icon(Icons.account_balance),
title: new Text(Strings.menu_change_city),
onTap: () => createDialog()
));
if(_isLoading) return buildBusyForm();
return Scaffold( .... //window content
So I have navigation drawer. One item ("Select city") does not close navigation drawer, it shows select city dialog:
createDialog()
setState(() _isLoading = true;);
fetchCities().then((response)
setState(() _isLoading = false;);
showDialog(
context: context,
builder: (context) => CityChoiceDialog<City>(
title: Text(Strings.menu_change_city),
items: response,
initialValue: response.firstWhere((c) => c.id == globals.cityId, orElse: () => new City()),
itemBuilder: (City city) => Text(city.name),
onSelected: _onSelected,
onSubmitted: _onSubmitted));
);
So, basically it's intended to show busy form, load cities, then hide busy form and show cities list dialog. As it seems to work, I'm getting exception:
I/flutter (10662): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY
╞═══════════════════════════════════════════════════════════ I/flutter
(10662): The following assertion was thrown while finalizing the
widget tree: I/flutter (10662): setState() or markNeedsBuild() called
when widget tree was locked. I/flutter (10662): This
_ModalScope widget cannot be marked as needing to build because the framework is I/flutter (10662): locked. I/flutter (10662):
The widget on which setState() or markNeedsBuild() was called was:
I/flutter (10662):
_ModalScope-[LabeledGlobalKey<_ModalScopeState>#1f222](state:
I/flutter (10662): _ModalScopeState#6c40b)
How to do what I want correctly?
exception dart flutter state
Please look at my code:
class HomePageState extends State<HomePage>
bool _isLoading = false;
.....
@override
Widget build(BuildContext context)
var drawerOptions = <Widget>[];
......
drawerOptions.add(new ListTile(
leading: new Icon(Icons.account_balance),
title: new Text(Strings.menu_change_city),
onTap: () => createDialog()
));
if(_isLoading) return buildBusyForm();
return Scaffold( .... //window content
So I have navigation drawer. One item ("Select city") does not close navigation drawer, it shows select city dialog:
createDialog()
setState(() _isLoading = true;);
fetchCities().then((response)
setState(() _isLoading = false;);
showDialog(
context: context,
builder: (context) => CityChoiceDialog<City>(
title: Text(Strings.menu_change_city),
items: response,
initialValue: response.firstWhere((c) => c.id == globals.cityId, orElse: () => new City()),
itemBuilder: (City city) => Text(city.name),
onSelected: _onSelected,
onSubmitted: _onSubmitted));
);
So, basically it's intended to show busy form, load cities, then hide busy form and show cities list dialog. As it seems to work, I'm getting exception:
I/flutter (10662): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY
╞═══════════════════════════════════════════════════════════ I/flutter
(10662): The following assertion was thrown while finalizing the
widget tree: I/flutter (10662): setState() or markNeedsBuild() called
when widget tree was locked. I/flutter (10662): This
_ModalScope widget cannot be marked as needing to build because the framework is I/flutter (10662): locked. I/flutter (10662):
The widget on which setState() or markNeedsBuild() was called was:
I/flutter (10662):
_ModalScope-[LabeledGlobalKey<_ModalScopeState>#1f222](state:
I/flutter (10662): _ModalScopeState#6c40b)
How to do what I want correctly?
exception dart flutter state
exception dart flutter state
edited Mar 7 at 12:55
user1209216
asked Mar 7 at 8:00
user1209216user1209216
1,83042363
1,83042363
how exactly are you closing your drawer ?
– Mazin Ibrahim
Mar 7 at 8:27
I noticed problem can be solved if I close drawer before attempting to change state. If drawer is still open and I want to change state, I'm getting this exception.
– user1209216
Mar 7 at 12:15
this kind of exception is noticed in the debugger only, but when you run this app on an actual device it won't have any noticeable effects.I tried that.
– Mazin Ibrahim
Mar 7 at 12:19
add a comment |
how exactly are you closing your drawer ?
– Mazin Ibrahim
Mar 7 at 8:27
I noticed problem can be solved if I close drawer before attempting to change state. If drawer is still open and I want to change state, I'm getting this exception.
– user1209216
Mar 7 at 12:15
this kind of exception is noticed in the debugger only, but when you run this app on an actual device it won't have any noticeable effects.I tried that.
– Mazin Ibrahim
Mar 7 at 12:19
how exactly are you closing your drawer ?
– Mazin Ibrahim
Mar 7 at 8:27
how exactly are you closing your drawer ?
– Mazin Ibrahim
Mar 7 at 8:27
I noticed problem can be solved if I close drawer before attempting to change state. If drawer is still open and I want to change state, I'm getting this exception.
– user1209216
Mar 7 at 12:15
I noticed problem can be solved if I close drawer before attempting to change state. If drawer is still open and I want to change state, I'm getting this exception.
– user1209216
Mar 7 at 12:15
this kind of exception is noticed in the debugger only, but when you run this app on an actual device it won't have any noticeable effects.I tried that.
– Mazin Ibrahim
Mar 7 at 12:19
this kind of exception is noticed in the debugger only, but when you run this app on an actual device it won't have any noticeable effects.I tried that.
– Mazin Ibrahim
Mar 7 at 12:19
add a comment |
1 Answer
1
active
oldest
votes
This error means you are calling setState during the build phase, which you cannot do.
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%2f55038765%2fsetstate-or-markneedsbuild-called-when-widget-tree-was-locked-when-changi%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This error means you are calling setState during the build phase, which you cannot do.
add a comment |
This error means you are calling setState during the build phase, which you cannot do.
add a comment |
This error means you are calling setState during the build phase, which you cannot do.
This error means you are calling setState during the build phase, which you cannot do.
answered Mar 7 at 8:16
Hussein AbdallahHussein Abdallah
1647
1647
add a comment |
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%2f55038765%2fsetstate-or-markneedsbuild-called-when-widget-tree-was-locked-when-changi%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
how exactly are you closing your drawer ?
– Mazin Ibrahim
Mar 7 at 8:27
I noticed problem can be solved if I close drawer before attempting to change state. If drawer is still open and I want to change state, I'm getting this exception.
– user1209216
Mar 7 at 12:15
this kind of exception is noticed in the debugger only, but when you run this app on an actual device it won't have any noticeable effects.I tried that.
– Mazin Ibrahim
Mar 7 at 12:19