mbrush_convert 0.0.1 copy "mbrush_convert: ^0.0.1" to clipboard
mbrush_convert: ^0.0.1 copied to clipboard

A new Flutter plugin to mbrush file convert

example/lib/main.dart

import 'dart:ffi';
import 'dart:io';
import 'package:ffi/ffi.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

///转换
typedef CallBackResult = Void Function();
typedef NativeConvert = Void Function(Pointer<Int8>, Pointer<Int8>, Pointer<NativeFunction<CallBackResult>>);
typedef FfiConvert = void Function(Pointer<Int8>,Pointer<Int8>,Pointer<NativeFunction<CallBackResult>>);

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  DynamicLibrary nativeApi;

  static void callResult(){
    print('callResult');
  }


  ///调用C图片转换
  void callNativeConvert(String inputPath,String outputPath){
    Pointer<Int8> nativeInput = inputPath.toNativeUtf8().cast<Int8>();
    Pointer<Int8> nativeOutput = outputPath.toNativeUtf8().cast<Int8>();
    FfiConvert convertFunc = nativeApi.lookupFunction<NativeConvert, FfiConvert>("convertImg");
    convertFunc(nativeInput,nativeOutput,Pointer.fromFunction(callResult));
  }

  @override
  void initState() {
    super.initState();
    nativeApi = Platform.isAndroid
        ? DynamicLibrary.open("libmbrush_convert.so")
        : DynamicLibrary.open("mbrush_convert.framework/mbrush_convert");
  }



  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Container(),
      ),
    );
  }
}
0
likes
30
pub points
0%
popularity

Publisher

unverified uploader

A new Flutter plugin to mbrush file convert

Homepage

License

Apache-2.0 (LICENSE)

Dependencies

flutter

More

Packages that depend on mbrush_convert