flutter setstatus but screen didn't update










0















Flutter app create a Widget List (wList) and show screen properly. If user presses a button it will add a divider() to the wList and update the screen by setState(). However, the screen didn't update. I think I may not understand well the logic of setState. If I update the wList and call the setState() function, I think it should update the screen. But It didn't.



 @override
Widget build(BuildContext context)
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: Text('檯號: $widget.inputTableNumber'),
centerTitle: true,
backgroundColor: Colors.black,
actions: <Widget>[
IconButton(icon: Icon(Icons.edit), onPressed: () => _showButtons(), color: Colors.white,)
],
),
body: RepaintBoundary(
key: _renderInvoice,
child: Padding(
padding: EdgeInsets.all(15.0),
child: ListView(
children: wList,
),
)
)
);


_showButtons()
showModalBottomSheet<void>(
context: context,
builder: (BuildContext context)
return Container(
color: Colors.white54,
height: 500.0,
child: GridView.count(
primary: false,
padding: const EdgeInsets.all(20.0),
crossAxisSpacing: 30.0,
mainAxisSpacing: 30.0,
crossAxisCount: 3,
children: <Widget>[
FloatingActionButton(
onPressed: () _addPercentage(0.1);,
heroTag: null,
backgroundColor: Colors.purpleAccent,
child: Text('+10%', style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.w500)),
foregroundColor: Colors.black,
),

],
)
);
);


_addPercentage(double d)
Navigator.pop(context);
setState(()
wList.add(Divider(color: Colors.black,));
);



enter image description here



enter image description here










share|improve this question
























  • The food is too expensive :D

    – stt106
    Nov 15 '18 at 13:39















0















Flutter app create a Widget List (wList) and show screen properly. If user presses a button it will add a divider() to the wList and update the screen by setState(). However, the screen didn't update. I think I may not understand well the logic of setState. If I update the wList and call the setState() function, I think it should update the screen. But It didn't.



 @override
Widget build(BuildContext context)
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: Text('檯號: $widget.inputTableNumber'),
centerTitle: true,
backgroundColor: Colors.black,
actions: <Widget>[
IconButton(icon: Icon(Icons.edit), onPressed: () => _showButtons(), color: Colors.white,)
],
),
body: RepaintBoundary(
key: _renderInvoice,
child: Padding(
padding: EdgeInsets.all(15.0),
child: ListView(
children: wList,
),
)
)
);


_showButtons()
showModalBottomSheet<void>(
context: context,
builder: (BuildContext context)
return Container(
color: Colors.white54,
height: 500.0,
child: GridView.count(
primary: false,
padding: const EdgeInsets.all(20.0),
crossAxisSpacing: 30.0,
mainAxisSpacing: 30.0,
crossAxisCount: 3,
children: <Widget>[
FloatingActionButton(
onPressed: () _addPercentage(0.1);,
heroTag: null,
backgroundColor: Colors.purpleAccent,
child: Text('+10%', style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.w500)),
foregroundColor: Colors.black,
),

],
)
);
);


_addPercentage(double d)
Navigator.pop(context);
setState(()
wList.add(Divider(color: Colors.black,));
);



enter image description here



enter image description here










share|improve this question
























  • The food is too expensive :D

    – stt106
    Nov 15 '18 at 13:39













0












0








0








Flutter app create a Widget List (wList) and show screen properly. If user presses a button it will add a divider() to the wList and update the screen by setState(). However, the screen didn't update. I think I may not understand well the logic of setState. If I update the wList and call the setState() function, I think it should update the screen. But It didn't.



 @override
Widget build(BuildContext context)
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: Text('檯號: $widget.inputTableNumber'),
centerTitle: true,
backgroundColor: Colors.black,
actions: <Widget>[
IconButton(icon: Icon(Icons.edit), onPressed: () => _showButtons(), color: Colors.white,)
],
),
body: RepaintBoundary(
key: _renderInvoice,
child: Padding(
padding: EdgeInsets.all(15.0),
child: ListView(
children: wList,
),
)
)
);


_showButtons()
showModalBottomSheet<void>(
context: context,
builder: (BuildContext context)
return Container(
color: Colors.white54,
height: 500.0,
child: GridView.count(
primary: false,
padding: const EdgeInsets.all(20.0),
crossAxisSpacing: 30.0,
mainAxisSpacing: 30.0,
crossAxisCount: 3,
children: <Widget>[
FloatingActionButton(
onPressed: () _addPercentage(0.1);,
heroTag: null,
backgroundColor: Colors.purpleAccent,
child: Text('+10%', style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.w500)),
foregroundColor: Colors.black,
),

],
)
);
);


_addPercentage(double d)
Navigator.pop(context);
setState(()
wList.add(Divider(color: Colors.black,));
);



enter image description here



enter image description here










share|improve this question
















Flutter app create a Widget List (wList) and show screen properly. If user presses a button it will add a divider() to the wList and update the screen by setState(). However, the screen didn't update. I think I may not understand well the logic of setState. If I update the wList and call the setState() function, I think it should update the screen. But It didn't.



 @override
Widget build(BuildContext context)
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: Text('檯號: $widget.inputTableNumber'),
centerTitle: true,
backgroundColor: Colors.black,
actions: <Widget>[
IconButton(icon: Icon(Icons.edit), onPressed: () => _showButtons(), color: Colors.white,)
],
),
body: RepaintBoundary(
key: _renderInvoice,
child: Padding(
padding: EdgeInsets.all(15.0),
child: ListView(
children: wList,
),
)
)
);


_showButtons()
showModalBottomSheet<void>(
context: context,
builder: (BuildContext context)
return Container(
color: Colors.white54,
height: 500.0,
child: GridView.count(
primary: false,
padding: const EdgeInsets.all(20.0),
crossAxisSpacing: 30.0,
mainAxisSpacing: 30.0,
crossAxisCount: 3,
children: <Widget>[
FloatingActionButton(
onPressed: () _addPercentage(0.1);,
heroTag: null,
backgroundColor: Colors.purpleAccent,
child: Text('+10%', style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.w500)),
foregroundColor: Colors.black,
),

],
)
);
);


_addPercentage(double d)
Navigator.pop(context);
setState(()
wList.add(Divider(color: Colors.black,));
);



enter image description here



enter image description here







flutter setstate






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 14:25









James Z

11.2k71936




11.2k71936










asked Nov 15 '18 at 13:12









GPHGPH

167116




167116












  • The food is too expensive :D

    – stt106
    Nov 15 '18 at 13:39

















  • The food is too expensive :D

    – stt106
    Nov 15 '18 at 13:39
















The food is too expensive :D

– stt106
Nov 15 '18 at 13:39





The food is too expensive :D

– stt106
Nov 15 '18 at 13:39












1 Answer
1






active

oldest

votes


















2














So the reason this fails is because the standard Listview constructor expects a const children parameter. Obviously, your wList is not a const value and changes when your button is pressed.



Instead, you should use Listview.builder like this:



ListView.builder(
itemCount: wList.length,
itemBuilder: (context, index)
return wList[index];

)





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%2f53320300%2fflutter-setstatus-but-screen-didnt-update%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









    2














    So the reason this fails is because the standard Listview constructor expects a const children parameter. Obviously, your wList is not a const value and changes when your button is pressed.



    Instead, you should use Listview.builder like this:



    ListView.builder(
    itemCount: wList.length,
    itemBuilder: (context, index)
    return wList[index];

    )





    share|improve this answer



























      2














      So the reason this fails is because the standard Listview constructor expects a const children parameter. Obviously, your wList is not a const value and changes when your button is pressed.



      Instead, you should use Listview.builder like this:



      ListView.builder(
      itemCount: wList.length,
      itemBuilder: (context, index)
      return wList[index];

      )





      share|improve this answer

























        2












        2








        2







        So the reason this fails is because the standard Listview constructor expects a const children parameter. Obviously, your wList is not a const value and changes when your button is pressed.



        Instead, you should use Listview.builder like this:



        ListView.builder(
        itemCount: wList.length,
        itemBuilder: (context, index)
        return wList[index];

        )





        share|improve this answer













        So the reason this fails is because the standard Listview constructor expects a const children parameter. Obviously, your wList is not a const value and changes when your button is pressed.



        Instead, you should use Listview.builder like this:



        ListView.builder(
        itemCount: wList.length,
        itemBuilder: (context, index)
        return wList[index];

        )






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 17:26









        RingilRingil

        3,81321227




        3,81321227





























            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%2f53320300%2fflutter-setstatus-but-screen-didnt-update%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







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3

            Museum of Modern and Contemporary Art of Trento and Rovereto