Flutter MVP 快速开发

Flutter MVP 快速开发

练习做的项目,来做一些学习笔记,具体框架的使用方法就不做记录,网上很多,这里只做 MVP 框架搭建,框架借鉴了其他大佬写的一些代码,然后按照自己又做了些调整

基础配置

先来看下依赖的库都有哪些,也不一定全部都用到了 ,看自己项目需要吧

dependencies:
  flutter:
    sdk: flutter
  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  # 路由
  fluro: ^1.5.1
  # 简单数据存储
  shared_preferences: ^0.5.3+4
  # 依赖注入
  get_it: ^3.0.1
  # 吐司
  fluttertoast: ^3.1.3
  # 尺寸适配
  flutter_screenutil: ^0.6.0
  # 二维码条形码扫描
  flutter_qr_reader: ^1.0.3
  # 权限申请
  permission_handler: ^3.0.0
  # 网络请求
  dio: ^2.0.1
  #	手机网络状态监听
  connectivity: ^0.4.3+7
  #	消息总线
  event_bus: ^1.1.0
  # 刷新 加载
  pull_to_refresh: ^1.5.4
  # Rx
  rxdart: ^0.21.0

在入口函数 main() 中进行部分框架的初始化:

void main() {
 Router router = Router();
 Routes.configureRoutes(router);
 Application.router = router;
 Application.setupLocator();
 runApp(MyApp());
}
  1. 1、2、3 行是用来配置项目中路由的(fluro 框架)
  2. Application.setupLocator() 初始化 get_it 依赖注入框架,相当于 Android 中 dagger2
  3. 其中在 Application 中还做了屏幕适配配置

看下 Application 中的代码吧:

class Application {
  static Router router;
  static GlobalKey<NavigatorState> globalKey = GlobalKey();
  static SharedPreferences sp;
  static double screenWidth;
  static double screenHeight;
  static d
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值