简体   繁体   English

Flutter BottomNavigationBar 图标在点击时缩小并在释放时返回正常大小

[英]Flutter BottomNavigationBar icon reduce on tap and return back normal size on release

I have standard Bottom Navigation.我有标准的底部导航。 I already hide item titles and use type: BottomNavigationBarType.fixed to prevent default animation.我已经隐藏了项目标题并使用类型:BottomNavigationBarType.fixed 来防止默认的 animation。

What I want is: BottomNavigationBar item icons got smaller on click and return back to normal size animatedly.我想要的是:BottomNavigationBar 项目图标在单击时变小并动画返回正常大小。 Could anybody help me achieving this?有人可以帮我实现这一目标吗?

 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, ), ); }

You can use a你可以使用一个

AnimatedContainer动画容器

to achieve this.为达到这个。 Wrap every of your Icons in one and have the icon expand within them.将您的每个图标包装在一个中,并让图标在其中展开。 if you change the height of the Animated Container, it will be animated.如果您更改动画容器的高度,它将被动画化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM