Flutter 从入门到项目

Flutter-从入门到项目 06: 微信项目搭建

2021-02-22  本文已影响0人  Cooci_和谐学习_不急不躁

Flutter 专题目录汇总: 这个目录方便大家快速查询你要学习的内容!!!

前面几篇都是关于环境配置和基础语法学习. 在我个人认为学习一门新的语言(快速高效学习) 一定是通过实践,最好的就是带着项目实操,如果你能够仿写下一个项目那么基本就差不多了! 这里我就用微信项目作为本次案例仿写,希望大家喜欢!

Github 项目地址 欢迎大家点赞心心 谢谢

一: 微信项目搭建

① 主APP

这里主要是把主界面抽取出去 方便查阅和修改

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'WeChat',
      theme: ThemeData(
        highlightColor: Color.fromARGB(1, 0, 0, 0),
        splashColor: Color.fromARGB(1, 0, 0, 0),
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: KCRootPage(),
    );
  }
}

② 根控制器

根控制器的配置和基本iOS开发是一致的!
其中 class KCRootPage extends StatefulWidget 这样就能够动态调整也就所谓的状态管理

class KCRootPage extends StatefulWidget {
  @override
  _KCRootPageState createState() => _KCRootPageState();
}

class _KCRootPageState extends State<KCRootPage> {
  int _currentIndex = 0;
  List<Widget> _pages = [KCChatPage(),KCFriendsPage(),KCDiscoverPage(), KCMinePage()];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _pages[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        onTap: (index){
          setState(() {
            _currentIndex = index;
          });
        },
        selectedFontSize: 12.0,
        currentIndex: _currentIndex,
        fixedColor: Colors.green,
        type: BottomNavigationBarType.fixed,
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.chat),label: '微信'),
          BottomNavigationBarItem(icon: Icon(Icons.bookmark),label: '通讯录'),
          BottomNavigationBarItem(icon: Icon(Icons.history),label: '发现'),
          BottomNavigationBarItem(icon: Icon(Icons.person),label: '我'),
        ],
      ),
    );
  }
}

到这里我们看看页面样式,是不是非常简单? 😸 flutter 谁用谁知道

③ 启动页&图标设置

A: iOS 设置

B: Android 设置

   <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/launch_image" />
    </item>
  assets:
    - images/

下一篇: 微信项目发现页面

上一篇 下一篇

猜你喜欢

热点阅读