Since dart:ffi is available from Dart 2.2.0-dev.2.0, I've been trying to use that library. The sample app works fine for me and I also tried to use it for my Flutter app but I couldn't call it with import "dart:ffi", although Flutter on my machine was HEAD of master that used Dart 2.3.0-dev.0.0.
I checked what happened, then I found that sky_engine didn't contain ffi.dart while it contained other libraries (e.g. "dart:core"). Also I noticed that the source files of those libraries were copied from $FLUTTER_ROOT/bin/cache/dart-sdk/lib to $FLUTTER_ROOT/bin/cache/pkg/sky_engine using BUILD.gn or _embedder.yaml and that seemed to be why I couldn't use the dart:ffi in my Flutter app.
However, in the first place, why does Flutter need sky_engine, which is "the interface between Dart and the Flutter Engine"? Why not calling them directly without this glue code?
Flutter has a good documentation for FFI to be able to call native C APIs. Adding import 'dart:ffi' as ffi; on the Flutter app works without issues as of my testing with Flutter 2.5. If you're able to provide a minimal repro of your issue, this will help folks to understand the question better.
As for the question on why sky_engine is used by Flutter, that's just simply because it's the "flutter_engine" - similar to what has been already mentioned in the comments.
Related
I am working on the dart_ping package and although it currently is tagged with iOS support, it does not actually support iOS. This is due to the way pub.dev detects supported platforms. I have filed an issue on dart-sdk repo.
Nonetheless, I would like to add iOS support while still preserving support for dart native. Right now, dart_ping works by calling the host OS's ping binary. The ping binary is available on Windows, macOS, Linux, and Android but not on iOS.
Current methods of performing a ping on iOS use native Objective-C code and call them via either method channels or ffi. Since method channels are a flutter feature rather than a dart feature, using them would require dart_ping to depend on the flutter sdk, which would prevent it from being used in a dart native application (perhaps server side).
Ffi on the other hand, is a dart native feature and is capable of doing what I want. However, I cannot seem to find a way to include the iOS framework/library/binary for ping in my dart_ping package in a way that instructs a flutter application to include it and link it to the iOS target/runner.
Is there any way to keep dart native support in my package while also supporting the edge case of iOS needing an extra non-dart framework? Even federated plugins depend on the flutter sdk. It seems to me that we need a pure dart equivalent to the federated plugin system.
TLDR: How do I add a pre-compiled iOS framework or binary to a dart package without depending on the flutter sdk and call it only when the package is used on iOS ?
For your specific case of adding iOS support only for Flutter users of your package but keeping the package as pure Dart without a dependency on the Flutter SDK should be possible by having a Flutter plugin package that depends on your Dart package.
In the pure Dart package you can have FFI calls to a native iOS library, but its actually the Flutter plugin package that supplies the native iOS library per the Flutter documentation for using FFI.
You would of course need to make it very clear in the documentation for your pure Dart package that for iOS, it should only be used via the "wrapper" plugin package.
Unfortunately this is a rather convoluted way to do it, but I don't know of a better way to achieve this as of now.
There is further discussion on this topic in the comments in this issue, which as of today is still open.
When I am trying to build my ios app in xcode, the build is failing due to lexical or preprocessor issue the error shows up like this
This was a problem specific to the react-native-device-info module.
For your specific case you may try v1.6.1 or higher (currently at 2.0 as of May 21, 2019) of the library and that should fix things for you.
For others interested more generally in the problem, this is a react-native library that uses native code, so it has an XCode project embedded within it for use in react-native after you run react-native link react-native-device-info. Unfortunately, the library was not including any directories in it's header search path, so it was of course unable to find the header files for the react-native objects it was using locally.
A library user proposed a change that fixed that problem for tvOS, and I extended the change to cover iOS as well, and now the library no longer generates errors like this for iOS or tvOS targets.
Perhaps someone with a similar issue may find the specific changes required for the fix useful in their projects
Is there any way to tell Flutter use more newer dart sdk version? I found it a bit tricky, because it checks some hashes in flutter/bin/cache/*.stamp. And when I'm trying to make a symbolic link to homebrew installed dart sdk it cannot build flutter_tool. To do that I've removed flutter_tool.stamp and flutter_tool.snapshot files. Something else needed?
I'm not actually sure if it is a need or not, but these tools are still in beta, for me it sounds logic to use edge versions.
Flutter ships with a customized Dart SDK (for example with the web parts stripped).
The Flutter SDK is tightly bound to a specific Dart SDK version and there is no reliable way to make Flutter work with any other Dart SDK than the one it is installed with.
I came across a websocket example that I would like to use. However it uses import 'dart:html';. When I introduce that in my Flutter project seems like its not being picked up. Do I need to add additional dependencies to the pubspec.yaml?
dart:html can't be used in Flutter.
It is for browser applications only.
dart:html also only comes with the regular Dart SDK, not with the Dart SDK shipped with Flutter.
I know this is an old question but let me drop this answer here.
I've searched for a web crawler/scraper for Flutter for a while now. I've tried to use FlutterWebview and also the HTML package but no way. Recently I've found a new package for this.
The advantage of this package is that it is really cross platform as explained:
Cross-platform dart:html that works in the browser, Dart VM, and Flutter.
Typical use cases are:
Cross-platform application development (e.g. Flutter mobile and web versions).
Web crawling and scraping
you can use universal_html for any scraping/crawling purpose
Since the merge of Flutter-web into the main Flutter repository, it's no longer possible to directly add imports for web libraries (e.g. dart:html) in a Flutter project on the main channel when targeting Web, Android and iOS.
Use the universal html package which provides extensive support for multiple platforms and web libraries.
From the root level of your project, command
1.
flutter pub add universal_html
2. import 'package:universal_html/html.dart' as html
This package isn't required to run some web files (e.g. dart:js). In my case, I just had to remove the import 'dart:js' import statement.
I've added a small feature that improves the UX of the <TextInput> component in React Native. The new code is in the native side so I had to make changes to several files inside official RCTText library.
Currently, I got this working locally by manually changing the code inside node_modules and rebuilding the project. I plan to make a PR to the official React Native project once I fix all the edge cases. I understand that sometimes features takes a while to make it into the official release(if at all) so in the meantime, I would like to release this improved <TextInput>as a library for other's that might be interested.
The goal is to release a library that once added to project will allow you to create a <MyTextInput> component which does everything the original <TextInput> does. And here is where I got a bit lost. Can someone please point me to the right direction on how to make a library out of this, or perhaps a link to a library that does a similar thing(augmenting an official RN component in native code)?
You can bootstrap a linkable library project using react-native-create-library and then copy your modified RCTText library project into it.
You'll want to rename the library, e.g. by giving it a prefix other than RCT to avoid collisions with the main RCTText component. Additionally, you'll need to rename all the references to the RCT* components in the source files.
Once you have created the library, you can publish it to NPM and install it to your React Native app with:
npm install your-text-component
react-native link your-text-component
I haven't tried this for built-in React components, but releasing a third-party native library for React Native should not really be any different, whether or not the original implementation is based on existing React Native component or not.