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










1















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?










share|improve this question
























  • 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
















1















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?










share|improve this question
























  • 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














1












1








1








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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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













1 Answer
1






active

oldest

votes


















0














This error means you are calling setState during the build phase, which you cannot do.






share|improve this answer






















    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%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









    0














    This error means you are calling setState during the build phase, which you cannot do.






    share|improve this answer



























      0














      This error means you are calling setState during the build phase, which you cannot do.






      share|improve this answer

























        0












        0








        0







        This error means you are calling setState during the build phase, which you cannot do.






        share|improve this answer













        This error means you are calling setState during the build phase, which you cannot do.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 7 at 8:16









        Hussein AbdallahHussein Abdallah

        1647




        1647





























            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%2f55038765%2fsetstate-or-markneedsbuild-called-when-widget-tree-was-locked-when-changi%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

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

            Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

            2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived