Re: setState() don't refresh scaffold body ??

328 views
Skip to first unread message
Message has been deleted

Ian B

unread,
Dec 13, 2018, 4:36:52 AM12/13/18
to mach...@gmail.com, flutt...@googlegroups.com
I think you may need to include a bit more code, it's not obvious to me where/how mainscaffoldbody and selectedtab are used (maybe Stackoverflow is a slightly better medium for more code examples though). Also maybe add some debugging to _selectedTab & the setStates, see if it's being called exactly when you think it is.

On Thu, Dec 13, 2018 at 7:34 AM Julien P. <mach...@gmail.com> wrote:
Hi all,

here is a simple code :

class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
  Widget mainScaffoldBody;

  void _selectedTab(int index) async {
    switch (index) {
      case 0 : // Accueil
        setState(() {
          mainScaffoldBody = null;
        });
        break;
      case 1 : // Recherche
        Article article = new Article(null);
        List<Article> articles = await article.getArticles('', '');
        setState(() {
          mainScaffoldBody = new AfficheArticles(articles);
        });
        break;
      case 2 : // Catégorie favorite 1
        Article article = new Article(null);
        List<Article> articles = await article.getArticles('categorie=4', 'note DESC, date DESC');
        setState(() {
          mainScaffoldBody = new AfficheArticles(articles);
        });
        break;
      case 3 : // Catégorie favorite 2
        Article article = new Article(null);
        List<Article> articles = await article.getArticles('categorie=3', 'note DESC, date DESC');
        setState(() {
          mainScaffoldBody = new AfficheArticles(articles);
        });
        break;
    }

  }


// etc...

}




The _selectedTab() method is called from a ontabSelected event from a bottomNavigationBar widget.

When I switch from index=0 to index=1 my mainScaffoldBody Widget i refreshed but when I switch from 1 to 2 or 1 to 3, etc... nothing is refreshed in the app !
I systematically need to switch to mainScaffoldBody=null to view the screen being refreshed. Neither nothing move when I want to change my scaffold body... :-(

Can U help me ?

Thx guys.


--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages