Calling Native Libraries in Flutter with Dart FFI | Kodeco

In this tutorial, you’ll learn how to use Dart FFI to access native libraries that support C-interoperability.


This is a companion discussion topic for the original entry at https://www.kodeco.com/21512310-calling-native-libraries-in-flutter-with-dart-ffi

hi,
Good example for FFI call.
But your code has a bug:

forecast_m = malloc(strlen(forecast) + 1); // should be malloc by len + 1

Thanks!

Yep, you’re right - strlen() returns the size of the string without the NULL terminator, but strcpy() copies the string including NULL, so the destination buffer won’t be large enough unless you had 1 byte for NULL. I don’t actually write much C, but this is exactly why we shouldn’t use strcpy/strlen. Thanks!