
Flutter-从入门到项目 06: 微信项目搭建
Flutter 专题目录汇总: 这个目录方便大家快速查询你要学习的内容!!!
前面几篇都是关于环境配置和基础语法学习. 在我个人认为学习一门新的语言(快速高效学习) 一定是通过实践,最好的就是带着项目实操,如果你能够仿写下一个项目那么基本就差不多了! 这里我就用微信项目作为本次案例仿写,希望大家喜欢!
Github 项目地址 欢迎大家点赞心心 谢谢
一: 微信项目搭建
① 主APP
这里主要是把主界面抽取出去 方便查阅和修改
void main() {runApp(MyApp());}class MyApp extends StatelessWidget {// This widget is the root of your application.@overrideWidget 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(),);}}
highlightColor: 高亮色设置splashColor: 长按颜色设置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()];@overrideWidget 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: '我'),],),);}}
- 通过
BottomNavigationBarItem设置了底部按钮:微信、通讯录、发现、我 List<Widget> _pages = [KCChatPage(),KCFriendsPage(),KCDiscoverPage(), KCMinePage()];设置一个数组来收集相应页面currentIndex: 跟踪当前点击的按钮,从而跳到相应的页面onTap: 作为用户的响应 -> 修改状态!
到这里我们看看页面样式,是不是非常简单? 😸 flutter 谁用谁知道

③ 启动页&图标设置
A: iOS 设置
- 打开iOS工程 ->
Runner-> 删掉原来Flutter的图标 Bundle name修改成微信

B: Android 设置
AndroidManifest.xml->android:label="微信"修改项目显示名称drawable->launch_background
<item><bitmapandroid:gravity="center"android:src="@mipmap/launch_image" /></item>复制代码
pubspec.yaml放开注释 方便后面工程里面的图标设置
assets:- images/
下一篇: 微信项目发现页面
资料推荐
如果你正在跳槽或者正准备跳槽不妨动动小手,添加一下咱们的交流群1012951431来获取一份详细的大厂面试资料为你的跳槽多添一份保障。

