简体   繁体   中英

Preload a Tab in TabBarView

I have my flutter app with 3 tabs. When the app loads, I want it to load all 3 pages and not only the one it will show. My problem is, that when swiping to my other tab, it takes a second to load the content and then it animates. What is the proper way to preload a tab for this case? Or is it done by saving the widget into a variable?

I use it like this, it won't take any second to load the tab page.

@override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 3, //The number of tabs
      child: Scaffold(
        appBar: AppBar(
          title: Text('Your tabs page title'),
          bottom: TabBar(
            tabs: <Widget>[
              Tab(
                icon: Icon(Icons.someIcone),
                text: 'Page-1',
              ),
              Tab(
                icon: Icon(Icons.list),
                text: 'Page-2',
              ),
              Tab(
                icon: Icon(Icons.list),
                text: 'Page-3',
              ),

            ],
          ),
        ),
        body: TabBarView(
          children: <Widget>[
            PageOne(),
            PageTwo(),
            PageThree(),
          ],
        ),
      ),
    );
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM