如何在底部导航栏中快速显示gif动画?

时间:2019-01-09 02:19:57

标签: dart flutter

我使用底部导航栏中的gif图像替换了它随附的图标,但是单击后再次单击gif不会显示动画。

 class BottomNavigationBarHome extends StatefulWidget {
      @override
      State<StatefulWidget> createState() {
        // TODO: implement createState
        return _BottomNavigationBarHomeState();
      }
    }

class _BottomNavigationBarHomeState extends State<BottomNavigationBarHome>{
  int _currentIndex = 0;
  var bottomTitle = ['home','menu','message','person'];
  var bottomIcons = ['res/icon/home.png','res/icon/menu.png','res/icon/message.png','res/icon/person.png'];
  var bottomIconsGif = ['res/icon/home.gif','res/icon/menu.gif','res/icon/message.gif','res/icon/person.gif'];

  var pageList = [
      new home(),
      new location(),
      new message(),
      new person()
  ];

  var title = '';
  var iconGif = ['res/icon/home.png','res/icon/menu.png','res/icon/message.png','res/icon/person.png'];


  void _onTapHandler(int index){
    setState(() {
      _currentIndex = index;
      iconGif =  ['res/icon/home.png','res/icon/menu.png','res/icon/message.png','res/icon/person.png'];
      iconGif[index] = bottomIconsGif[index];
    });
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: new Scaffold(
        body: pageList[_currentIndex],
        bottomNavigationBar: new BottomNavigationBar(items: <BottomNavigationBarItem>[
          BottomNavigationBarItem(
              icon: new Image.asset(iconGif[0],height: 30.0,),
              title: Text(bottomTitle[0],style: new TextStyle(color: Colors.black)),
          ),
          BottomNavigationBarItem(
              icon: new Image.asset(iconGif[1],height: 30.0,),
              title: Text(bottomTitle[1],style: new TextStyle(color: Colors.black))
          ),
          BottomNavigationBarItem(
              icon: new Image.asset(iconGif[2],height: 30.0,gaplessPlayback: true,),
              title: Text(bottomTitle[2],style: new TextStyle(color: Colors.black))
          ),
          BottomNavigationBarItem(
              icon: new Image.asset(iconGif[3],height: 30.0,),
              title: Text(bottomTitle[3],style: new TextStyle(color: Colors.black),)
          ),
        ],
          currentIndex: _currentIndex,
          onTap: _onTapHandler,
        ),
      ),

    );

  }

}

使用flutter v1.0;我使用底部导航栏中的gif图像替换其随附的图标,但是单击它后再次单击gif将不会显示动画。

0 个答案:

没有答案