Flutter 开发 Android 原生开发神器 flutter_api_stub

flutter_api_stub

  • 诞生的意义
  • flutter_api_stub
    • [It is used for developing Android native applications efficiently and quickly.](#It is used for developing Android native applications efficiently and quickly.)
  • Feature
  • [File structure](#File structure)
  • [How to use](#How to use)
  • Example

诞生的意义

相信很多做Flutter开发的小伙伴们都遇到过Flutter跨平台开发时Android原生端是不带IDE自动补全以及提示的,这对我们的开发非常不友好而且影响开发效率和速度,今天大家有福了!以后可以完全自由发挥这一块了,我把相关的 Flutter API 整理出来抽成了 Module Stub,也就是说后续我们开发只需要导入Module 就可以不需在 Flutter 项目中痛苦挣扎的写原生代码了,就跟平时写代码一样非常方便和效率,写好之后直接平替到你的 Flutter 项目就可以了,请仔细看完文章赶紧上手吧!

flutter_api_stub

It is used for developing Android native applications efficiently and quickly.

Feature

  • ✅ In a pure Android native project
  • ✅ Without introducing the Flutter SDK / without compiling Flutter
  • ✅ Related code such as FlutterPlugin, ActivityAware, and MethodChannel can be written normally
  • ✅ The IDE provides code completion and allows compilation
  • ✅ When integrating Flutter in the future, there will be zero or minimal changes

File structure

  • your-project/
  • ├── app/ ← Your android project
  • │ └── src/main/java/...
  • ├── flutter-api-stub/ ← Flutter API Stub
  • │ └── src/main/java/
  • │ └── io/flutter/...
  • ├── other module/flutter-plugin-impl/ ← Other module/Your flutter flugin impl
  • │ └── src/main/java/...
  • └── .../

How to use

  • 1.git clone https://github.com/Mr-Jiang/flutter_api_stub.git(Clone the repo to your computer)
  • 2.Select your target android native project and import it(remeber the type is module)
  • 3.Open your android studio ide "Project Structure" menu and click it
  • 4.Looking for the "Dependencies" menu item and then click
  • 5.Click your "app" module and then click the "+" button add the "flutter_api_stub" library, finally remember to check "apply".

Example

复制代码
package com.bluetooth.helper;

import androidx.annotation.NonNull;

import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;

public class BleConnectHelperPlugin implements FlutterPlugin, MethodChannel.MethodCallHandler {

    final String channelAction = "ble_connect_helper";

    private MethodChannel methodChannel;

    private BleConnectHelper helper;

    @Override
    public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
        helper = BleConnectHelper.getInstance(binding.getApplicationContext());
        methodChannel = new MethodChannel(binding.getBinaryMessenger(), channelAction);
        methodChannel.setMethodCallHandler(this);
    }

    @Override
    public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
        methodChannel = null;
    }

    @Override
    public void onMethodCall(MethodCall call, MethodChannel.Result result) {
        if (call.method.equals("connect")) {
            String address = call.argument("address");
            helper.connect(address);
        } else if (call.method.equals("disconnect")) {
            helper.disconnect();
        } else {
            result.notImplemented();
        }
    }

}
相关推荐
renke336437 分钟前
Flutter for OpenHarmony:构建一个 Flutter 色彩调和师游戏,RGB 空间探索、感知色差计算与视觉认知训练的工程实现
flutter·游戏
游戏开发爱好者840 分钟前
日常开发与测试的 App 测试方法、查看设备状态、实时日志、应用数据
android·ios·小程序·https·uni-app·iphone·webview
王码码20351 小时前
Flutter for OpenHarmony 实战之基础组件:第三十一篇 Chip 系列组件 — 灵活的标签化交互
android·flutter·交互·harmonyos
黑码哥1 小时前
ViewHolder设计模式深度剖析:iOS开发者掌握Android列表性能优化的实战指南
android·ios·性能优化·跨平台开发·viewholder
亓才孓1 小时前
[JDBC]元数据
android
独行soc1 小时前
2026年渗透测试面试题总结-17(题目+回答)
android·网络·安全·web安全·渗透测试·安全狮
金融RPA机器人丨实在智能2 小时前
Android Studio开发App项目进入AI深水区:实在智能Agent引领无代码交互革命
android·人工智能·ai·android studio
科技块儿2 小时前
利用IP查询在智慧城市交通信号系统中的应用探索
android·tcp/ip·智慧城市
独行soc2 小时前
2026年渗透测试面试题总结-18(题目+回答)
android·网络·安全·web安全·渗透测试·安全狮
ujainu2 小时前
Flutter + OpenHarmony 实现经典打砖块游戏开发实战—— 物理反弹、碰撞检测与关卡系统
flutter·游戏·openharmony·arkanoid·breakout