dart_native 0.1.10

  • Readme
  • Changelog
  • Example
  • Installing
  • new46

dart_native #

Write native code using Dart. This package liberates you from native code and low performance channel.

Still under development!!!

pub package Build Status

Requirements #

Flutter 1.12.13 (Dart 2.7.0)

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 #

  • [ ] Generate Dart code from ObjectiveC/C++ Headers.
  • [ ] Unit test.
  • [ ] Documents.

Article #

0.1.10 #

  • Fix issue for "dart_native" channel.
  • Support stret for block.

0.1.9 #

  • Change plugin name to "dart_native".

0.1.8 #

  • Dart function can be observer for NSNotification.
  • Fix issue for automatic transfer of NSRange.

0.1.7 #

  • Update dependancy.

0.1.6 #

  • Update readme.
  • Delete useless code.

0.1.5 #

  • Delete code for banckmark.

0.1.4 #

  • Performance optimization.
  • Bug fix.

0.1.3 #

  • Support more structs: CGPoint, CGVector, CGSize, CGRect, CGAffineTransform, UIEdgeInsets, NSDirectionalEdgeInsets, UIOffset.
  • Support collections: NSArray, NSDictionary, NSSet.
  • Support box/unbox: NSValue, NSNumber.

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.

example/README.md

dart_native_example #

Demonstrates how to use the dart_native 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:


dependencies:
  dart_native: ^0.1.10

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support 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_native/dart_native.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
86
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
46
Learn more about scoring.

We analyzed this package on Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health suggestions

Fix lib/src/ios/runtime/functions.dart. (-5.36 points)

Analysis of lib/src/ios/runtime/functions.dart reported 11 hints, including:

line 6 col 45: Name non-constant identifiers using lowerCamelCase.

line 11 col 45: Name non-constant identifiers using lowerCamelCase.

line 16 col 45: Name non-constant identifiers using lowerCamelCase.

line 21 col 35: Name non-constant identifiers using lowerCamelCase.

line 25 col 45: Name non-constant identifiers using lowerCamelCase.

Fix lib/src/ios/foundation/nsvalue.dart. (-3.45 points)

Analysis of lib/src/ios/foundation/nsvalue.dart reported 7 hints, including:

line 72 col 15: Name non-constant identifiers using lowerCamelCase.

line 78 col 16: Name non-constant identifiers using lowerCamelCase.

line 84 col 14: Name non-constant identifiers using lowerCamelCase.

line 90 col 14: Name non-constant identifiers using lowerCamelCase.

line 96 col 25: Name non-constant identifiers using lowerCamelCase.

Fix lib/src/ios/common/precompile_macro.dart. (-1.99 points)

Analysis of lib/src/ios/common/precompile_macro.dart reported 4 hints:

line 5 col 22: Name non-constant identifiers using lowerCamelCase.

line 8 col 22: Name non-constant identifiers using lowerCamelCase.

line 12 col 6: Name non-constant identifiers using lowerCamelCase.

line 13 col 6: Name non-constant identifiers using lowerCamelCase.

Fix additional 4 files with analysis or formatting issues. (-3.49 points)

Additional issues in the following files:

  • lib/src/ios/foundation/gcd.dart (4 hints)
  • lib/src/ios/foundation/basic_type.dart (1 hint)
  • lib/src/ios/foundation/nsnumber.dart (1 hint)
  • lib/src/ios/runtime/id.dart (1 hint)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
ffi ^0.1.3 0.1.3
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test