dart_objc 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • new14

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]);

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

Objective-C code:

@interface RuntimeStub ()
@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;

TODO List #

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

Article #

0.1.2 #

  • Perform method on main/global queue.

0.1.1 #

  • Fix issue for block and delegate callback when returning an object.

0.1.0 #

  • Fix CString and Struct memory issue.

0.1.0-dev.1 #

  • Update SDK constraint to 2.6.0-dev.8.2

0.0.6 #

  • Convert Bool Automatically.

0.0.5 #

  • Fix memory leak.

0.0.4 #

  • Support NSString.
  • Fix some memory issue.

0.0.3 #

  • Support delegate callback.

0.0.2 #

  • Format code.

0.0.1 #

  • Initial release.


dart_objc_example #

Demonstrates how to use the dart_objc plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  dart_objc: ^0.1.2

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:dart_objc/dart_objc.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Nov 15, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6


Detected platforms:

Error(s) prevent platform classification:

Make sure flutter format successfully runs on your package's source files.

Analysis issues and suggestions

Make sure flutter format successfully runs on your package's source files.

Running flutter format failed with the following output:

Exception: dartfmt on lib/ failed with exit code 65
Could not format because the source could not be parsed:

line 35, column 1 of lib/src/foundation/nsstring.dart: This requires the 'extension-methods' experiment to be enabled.
35 │ extension ConvertToNSString on String {
   │ ^^^^^^^^^
line 35, column 32 of lib/src/foundation/nsstring.dart: Functions must have an explicit list of parameters.

Fix dependencies in pubspec.yaml.

Running flutter pub upgrade failed with the following output:

ERR: The current Dart SDK version is 2.5.0.
 Because dart_objc requires SDK version >=2.6.0-dev.8.2 <3.0.0, version solving failed.

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

Error(s) prevent platform classification:

Make sure flutter format successfully runs on your package's source files.

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0-dev.8.2 <3.0.0