
先看效果图:

看代码:
import 'package:flutter/material.dart';void main() => runApp(MyApp());class MyApp extends StatelessWidget {const MyApp({Key? key}) : super(key: key);@overrideWidget build(BuildContext context) {return MaterialApp(debugShowCheckedModeBanner: false,home: MyAppHome(),);}
}class MyAppHome extends StatefulWidget {const MyAppHome({Key? key}) : super(key: key);@overrideState<MyAppHome> createState() => _MyAppHomeState();
}class _MyAppHomeState extends State<MyAppHome> {var index = 0;var text = ["home", "home1", "home2"];@overrideWidget build(BuildContext context) {return Scaffold(body: Center(child: Text("${text[index]}")),bottomNavigationBar: BottomNavigationBar(items: [BottomNavigationBarItem(icon: Icon(Icons.home),label: "home",),BottomNavigationBarItem(icon: Icon(Icons.home),label: "home1",),BottomNavigationBarItem(icon: Icon(Icons.home),label: "home2",),],currentIndex: index,onTap: (int indexs) {print("${indexs}");setState(() {index = indexs;});},),);}
}