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

}
相关推荐
传奇开心果编程2 小时前
【Jetpack Compose进阶学与练】第14课:系列收尾复习总结;Compose项目常见坑点汇总;学习路线与后续学习方向
android·学习·ui·kotlin·android jetpack
李游Leo4 小时前
《HarmonyOS 7 精准碰一碰跨设备协作开发实战》07:异常恢复、状态机与CrossDrop工程收尾【鸿蒙心迹】
android·harmonyos
m0_738185826 小时前
Flutter 鸿蒙化实战:flutter_app_minimizer_plus 适配 OpenHarmony,一键最小化应用
flutter·华为·harmonyos·鸿蒙
动物园猫7 小时前
Flutter 鸿蒙实战:用 webview_flutter 三方库在 鸿蒙 中内嵌真实网页
flutter·华为·harmonyos
方白羽7 小时前
Android APK安全防护
android·安全·apk
小黄人软件7 小时前
AndroidStudio老项目 macOS运行BlueTooth蓝牙串口助手(Android+Studio源码).rar
android·macos
00后程序员张7 小时前
苹果App Store上架指南:费用、原理与步骤详解
android·ios·小程序·https·uni-app·iphone·webview
天神哥哥啊7 小时前
cocos联调注意事项-安卓
android
TDengine (老段)7 小时前
TDengine TSDB 实战排障四(升级与兼容)
android·java·大数据·数据库·物联网·时序数据库·tdengine
蓝速科技8 小时前
政务自助终端信创选型与无人值守落地方案
android·大数据·数据库·人工智能·科技·技术分享·政务