我有标准的底部导航。我已经隐藏了项目标题并使用 type: BottomNavigationBarType.fixed 来防止默认动画。
我想要的是:BottomNavigationBar 项目图标在单击时变小并动画返回正常大小。有人可以帮我实现这一目标吗?
int _selectedIndex = 0;
static const TextStyle optionStyle = TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
static const List<Widget> _widgetOptions = <Widget>[
Text(
'Index 0: Home',
style: optionStyle,
),
Text(
'Index 1: Business',
style: optionStyle,
),
Text(
'Index 2: School',
style: optionStyle,
),
];
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('BottomNavigationBar Sample'),
),
body: Center(
child: _widgetOptions.elementAt(_selectedIndex),
),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: SizedBox.shrink(),
),
BottomNavigationBarItem(
icon: Icon(Icons.business),
title: SizedBox.shrink(),
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
title: SizedBox.shrink(),
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.amber[800],
onTap: _onItemTapped,
type: BottomNavigationBarType.fixed,
),
);
}