📘 Flutter 通道实战
MethodChannel · EventChannel
🌟 30 章完整目录
1
MethodChannel与EventChannel概述
Platform Channel概念 · 为什么需要 · 区别与适用场景
2
Flutter端MethodChannel基础
创建实例 · 通道命名规范 · invokeMethod详解
3
Android端MethodChannel实现
MainActivity注册 · 处理方法调用 · 返回结果
4
iOS端MethodChannel实现
AppDelegate注册 · 处理方法调用 · 返回结果
5
MethodChannel数据类型映射
自动映射 · 自定义编解码 StandardMethodCodec
6
MethodChannel异步处理
Handler/协程 · GCD/NSOperation · 回调结果
7
MethodChannel错误处理
PlatformException · 抛出异常 · FlutterError · 自定义错误码
8
实战:获取设备电量
BatteryManager · UIDevice · Flutter调用
9
实战:获取设备信息
Build类 · UIDevice · 平台信息
10
实战:文件读写操作
getFilesDir · NSFileManager · 原生文件
11
实战:启动原生Activity/VC
Intent · presentViewController
12
实战:调用原生Toast/Snackbar
Toast · UIAlertController
13
实战:调用原生相机/相册
Intent · UIImagePickerController
14
实战:原生传感器
SensorManager · CMMotionManager
15
EventChannel基础
创建实例 · 事件流名称 · StreamBuilder/Subscription
16
Android端EventChannel实现
StreamHandler · onListen/onCancel · 发送事件
17
iOS端EventChannel实现
FlutterEventChannel · FlutterStreamHandler
18
EventChannel数据流管理
单次/多次订阅 · 资源清理 · 背压处理
19
实战:监听网络状态
ConnectivityManager · NWPathMonitor
20
实战:监听GPS位置
FusedLocationProvider · CLLocationManager
21
实战:监听耳机插拔
IntentFilter · AVAudioSession
22
实战:屏幕旋转/方向
OrientationEventListener · UIDevice
23
实战:监听剪贴板变化
ClipboardManager · UIPasteboard
24
实战:系统音量变化
AudioManager · MPVolumeView
25
MethodChannel与EventChannel混合使用
同一通道 · 设计模式与架构建议
26
通道安全与数据校验
验证来源 · 加密传输 · 防止恶意调用
27
通道性能优化
减少跨线程开销 · 批量传输 · Background Isolate
28
通道调试与日志
Logcat · NSLog · Flutter DevTools
29
通道单元测试与集成测试
Flutter测试 · Android/iOS测试
30
综合实战:原生相机应用
MethodChannel调用相机 · EventChannel监听拍照 · 保存展示