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();
        }
    }

}
相关推荐
dalancon1 小时前
SurfaceControl 的事务提交给 SurfaceFlinger,以及 SurfaceFlinger 如何将这些数据设置到对应 Layer 的完整流程
android
dalancon1 小时前
SurfaceFlinger Layer 到 HWC 通信流程详解
android
cccccc语言我来了1 小时前
Linux(9)操作系统
android·java·linux
yige452 小时前
【MySQL】MySQL内置函数--日期函数字符串函数数学函数其他相关函数
android·mysql·adb
洞见前行2 小时前
AI 当逆向工程师:Claude Code 自主分析 APK 和 so 文件,解决 Unity 插件化启动崩溃
android·人工智能
王码码20352 小时前
Flutter 组件 inappwebview_cookie_manager 适配 鸿蒙Harmony 实战 - 驾驭核心大 Web 容器缓存隧道、构建金融级政企应用绝对防串号跨域大隔离基座
flutter·harmonyos·鸿蒙·openharmony·inappwebview_cookie_manager
左手厨刀右手茼蒿2 小时前
Flutter 组件 ews 的适配 鸿蒙Harmony 实战 - 驾驭企业级 Exchange Web Services 协议、实现鸿蒙端政企办公同步与高安通讯隔离方案
flutter·harmonyos·鸿蒙·openharmony
努力进修2 小时前
旧安卓手机别扔!用KSWEB搭个人博客,搭配外网访问超香
android·智能手机·cpolar
钛态2 小时前
Flutter 三方库 react 泛前端核心范式框架鸿蒙原生层生态级双向超能适配:跨时空重塑响应式单向数据流拓扑与高度精密生命周期树引擎解耦视图渲染控制中枢(适配鸿蒙 HarmonyOS ohos)
前端·flutter·react.js
键盘鼓手苏苏2 小时前
Flutter 组件 spry 适配鸿蒙 HarmonyOS 实战:轻量化 Web 框架,构建高性能端侧微服务与 Middleware 治理架构
flutter·harmonyos·鸿蒙·openharmony