dart-native / dart_native

Write iOS&macOS&Android Code using Dart. This package liberates you from redundant glue code and low performance of Flutter Channel.
BSD 3-Clause "New" or "Revised" License
952 stars 78 forks source link

请问可以在原生的主线程调用原生函数吗? #85

Open ruiq opened 2 years ago

ruiq commented 2 years ago

大佬好。 我在调用iOS的方法时,方法内部使用了一些UIView,但是报错了,说是不在主线程。 所以想问一下,dart -> native,默认会在非主线程调用吗?怎么样可以让这个调用发生在主线程呢?

yulingtianxia commented 2 years ago

默认是同步调用到 Native,那么此时是在 flutter-ui 线程,并不是 iOS 的主线程。所以 DartNative 也支持切线程(GCD),比如这个例子:https://github.com/dart-native/dart_native/blob/dc99cfd6f8cbff47763f9fc98b3710fba4edc13f/dart_native/example/lib/ios/unit_test.dart#L175