Skip to content
Write Objective-C Code using Dart. This package liberates you from native code and low performance channel.
C Dart Objective-C Objective-C++ Ruby Kotlin
Branch: master
Clone or download
Latest commit 146b9e7 Nov 11, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea update plugin name Oct 10, 2019
.vscode Fix block memory leaks. Nov 2, 2019
android update plugin name Oct 10, 2019
example
ios Perform method on main queue. Nov 11, 2019
lib
test
.gitignore
.metadata
CHANGELOG.md
LICENSE
README.md update readme Nov 7, 2019
dart_objc.iml update plugin name Oct 10, 2019
pubspec.yaml 0.1.2 Nov 11, 2019

README.md

dart_objc

Write Objective-C Code using Dart. This package liberates you from native code and low performance channel.

Still under development!!!

Requirements

Flutter 1.10.15 (channel dev, using 2.6.0-dev.8.2)

Getting Started

Dart code:

// new Objective-C object.
RuntimeStub stub = RuntimeStub();

// Define Dart function according to Objective-C BarBlock signature.
Function testFunc = (NSObject a) {
    print('hello block! ${a.toString()}');
    return 101;
};

// Dart function will be converted to Objective-C block.
Block block = stub.fooBlock(testFunc);
// invoke Objective-C block.
int result = block.invoke([stub]);
print(result); 

// support built-in structs.
CGRect rect = stub.fooCGRect(CGRect(4, 3, 2, 1));
print(rect);

Objective-C code:

@interface RuntimeStub ()
@end
@implementation RuntimeStub
- (CGRect)fooCGRect:(CGRect)rect
{
    NSLog(@"%s %f, %f, %f, %f", __func__, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
    return (CGRect){1, 2, 3, 4};
}

typedef int(^BarBlock)(NSObject *a);

- (BarBlock)fooBlock:(BarBlock)block
{
    dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{
        int result = block([NSObject new]);
        NSLog(@"---result: %d", result);
    });
    BarBlock bar = ^(NSObject *a) {
        NSLog(@"bar block arg: %@", a);
        return 404;
    };
    return bar;
}
@end

TODO List

  • Type support:Block
  • Type support:Struct
  • Delegate callback
  • Memory management
  • Main Thread Check
  • Generate Dart code from ObjectiveC/C++ Headers.
  • Unit test.
  • Documents.

Article

You can’t perform that action at this time.