小编Osm*_*ğan的帖子

带有 PageView 的 Flutter 底部导航栏

我想用页面浏览量构建底部导航栏。它将是 3 页,您可以向左或向右过渡。我可以滑动,但我的导航栏选择的项目颜色不会改变。你能帮助我吗?

class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int _selectedIndex = 0;
final PageController _pageController = PageController();

@override
Widget build(BuildContext context) {
return Scaffold(
  bottomNavigationBar: BottomNavigationBar(
    items: [
      BottomNavigationBarItem(
          icon: Icon(Icons.portrait), title: Text('Profile')),
      BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('Home')),
      BottomNavigationBarItem(
          icon: Icon(Icons.shopping_cart), title: Text('Shop'))
    ],
    onTap: _onTappedBar,
    selectedItemColor: Colors.orange,
    currentIndex: _selectedIndex,
  ),
  body: PageView(
    controller: _pageController,
    children: <Widget>[
      ProfilePage(),
      HomeTables(),
      ShoppingPage(),
    ],
  ),
);
}

void _onTappedBar(int value) {
setState(() { …
Run Code Online (Sandbox Code Playgroud)

mobile flutter bottomnavigationview

6
推荐指数
1
解决办法
5096
查看次数

标签 统计

bottomnavigationview ×1

flutter ×1

mobile ×1