flutter 底部导航BottomNavigationBar,案例

import 'package:flutter/material.dart';

class BottomNav extends StatefulWidget {
  const BottomNav({super.key});

  @override
  State<BottomNav> createState() => _BottomNavState();
}

class _BottomNavState extends State<BottomNav> {
  final _BottomColor = Colors.blue;
  late int currentIndex = 2;
  @override
  void initState() {
    super.initState();
    currentIndex = 0;
  }

  @override
  Widget build(BuildContext context) {
    //return const Placeholder();
    return Scaffold(
      bottomNavigationBar: BottomNavigationBar(
        selectedItemColor: Colors.red,
        currentIndex: currentIndex,
        type: BottomNavigationBarType.fixed,
        onTap: (value) => {
          setState(() {
            currentIndex = value;
          })
        },
        items: [
          BottomNavigationBarItem(
            icon: Icon(
              Icons.home,
            ),
            label: "Home",
          ),
          BottomNavigationBarItem(
            icon: Icon(
              Icons.email,
            ),
            label: "Email",
          ),
          BottomNavigationBarItem(
            icon: Icon(IconData(0xe600, fontFamily: 'iconfont')
                //Icons.airplay,
                ),
            label: "Airplay",
          ),
          BottomNavigationBarItem(
            icon: Icon(
              Icons.pages,
            ),
            label: "Pages",
          ),
        ],
      ),
    );
  }
}

 

https://blog.csdn.net/juer2017/article/details/131707666

 

posted @ 2023-08-26 09:48  小小强学习网  阅读(53)  评论(0)    收藏  举报