我建议删除IndexedStack 并制作小部件列表并根据索引呈现数据。
List<Widget> _pages = [Home(), Business(),School()];
在底部导航容器小部件上创建 Provider/Bloc 实例
return MultiProvider(
providers [
Provider<Something>(create: (_) => Something()),
],
child :Scaffold(
appBar: AppBar(
title: const Text('BottomNavigationBar Sample'),
),
body: _pages[_selectedIndex],
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.business),
label: 'Business',
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
label: 'School',
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.amber[800],
onTap: _onItemTapped,
)
)
在每个页面绑定provider的consumer,调用你provider中的api