Flutter仿微信(一)项目搭建和资源配置

2021-11-11  本文已影响0人  木扬音

有状态和无状态

项目搭建

class RootPage extends StatefulWidget {
  @override
  _RootPageState createState() => _RootPageState();
}

class _RootPageState extends State <RootPage>{
  int _currentIndex = 0;
  final PageController _pageController = PageController();
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      body: PageView(
        controller: _pageController,
        children: _vcList,
      ),
      bottomNavigationBar: BottomNavigationBar(
          onTap:(index){
            setState(() {
              _currentIndex = index;
              _pageController.jumpToPage(_currentIndex);//切换
            });
          },
          selectedFontSize: 12.0,//选中字体
          type:BottomNavigationBarType.fixed ,//items>3时必须设置
          currentIndex: _currentIndex,
          items:_itemList,
      )
    );
  }
}

final List<Widget> _vcList = [ChatPage(),FriendsPage(),DiscoveryPage(),MinePage()];

final List<BottomNavigationBarItem> _itemList = [
   BottomNavigationBarItem(
       icon: Image.asset(
          'images/tabbar_chat.png',
          height: 20,
          width: 20,
      ),
      activeIcon: Image.asset(
        'images/tabbar_chat_hl.png',
        height: 20,
        width: 20,
    ),
      label: '微信'
  ),
   BottomNavigationBarItem(
       icon: Image.asset(
         'images/tabbar_friends.png',
         height: 20,
         width: 20,
       ),
       activeIcon: Image.asset(
         'images/tabbar_friends_hl.png',
         height: 20,
         width: 20,
       ),
       label: '通讯录'
  ),
   BottomNavigationBarItem(
      icon: Image.asset(
        'images/tabbar_discover.png',
        height: 20,
        width: 20,
      ),
      activeIcon: Image.asset(
        'images/tabbar_discover_hl.png',
        height: 20,
        width: 20,
      ),
      label: '发现'
  ),
   BottomNavigationBarItem(
      icon: Image.asset(
        'images/tabbar_mine.png',
        height: 20,
        width: 20,
      ),
      activeIcon: Image.asset(
        'images/tabbar_mine_hl.png',
        height: 20,
        width: 20,
      ),
      label: '我'
  ),
];

安卓配置

找到AndroidManifest.xml,配置包名等,类似iOS中的info.plist
![image.png](https://img.haomeiwen.com/i16490557/28fad314d384a662.png?imageMogr2/auto-[图片上传中...(image.png-9d5077-1636354529650-0)]
orient/strip%7CimageView2/2/w/1240)

iocn配置

图片名字不能驼峰命名

image.png

启动图配置

image.png

项目配置

pubspec.yaml文件中进行配置,注意配置时的空格要对齐

image.png

项目地址

上一篇 下一篇

猜你喜欢

热点阅读