import 'dart:convert'; import 'dart:ffi'; import 'package:ffi/ffi.dart'; Pointer stringToCString(String s) { List units = Utf8Encoder().convert(s); Pointer str = allocate(count: units.length + 1); for (var i = 0; i < units.length; ++i) { str.elementAt(i).value = units[i]; } str.elementAt(units.length).value = 0; return str.cast(); }