I am trying to use the BottomNavigationBar in Flutter. It's working good. There is no error. But when I press the button on bottom navigation bar, there is no response. And also notice there is no comment about the bottom navigation bar in the console.
import 'package:copy_ems/screen/more_screen.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../my_profile.dart';
class BottomNavBar extends StatefulWidget {
const BottomNavBar({Key? key}) : super(key: key);
@override
_BottomNavBarState createState() => _BottomNavBarState();
}
class _BottomNavBarState extends State<BottomNavBar> {
Widget child = Container();
int _currentIndex = 0;
@override
Widget build(BuildContext context) {
switch(_currentIndex) {
case 0:
child = const MoreScreen();
break;
case 1:
child = const MoreScreen();
break;
case 2:
child = const MyProfile();
break;
case 3:
child = const MoreScreen();
break;
}
return BottomNavigationBar(
currentIndex: _currentIndex,
backgroundColor: Colors.white,
selectedItemColor: Colors.green,
unselectedItemColor: Colors.black87.withOpacity(.60),
selectedFontSize: 14,
unselectedFontSize: 14,
onTap: (value) {
setState(() => _currentIndex = value,
);
},
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.archive_rounded),
label: 'My Feed',
),
BottomNavigationBarItem(
icon: Icon(Icons.card_travel),
label: 'Leave',
),
BottomNavigationBarItem(
icon: Icon(Icons.add_task),
label: 'Tasks',
),
BottomNavigationBarItem(
icon: Icon(Icons.more_horiz),
label: 'More',
),
],
);
}
}
What's the problem with this code. Can any one help me?