toPointer function

dynamic toPointer(
  1. dynamic data
)

Implementation

toPointer(data) {
  if (data is Float32List ||
      data.runtimeType.toString() == "List<double>" ||
      data.runtimeType.toString() == "List<num>" ||
      data.runtimeType.toString() == "_GrowableList<double>") {
    final ptr = calloc<Float>(data.length);
    ptr
        .asTypedList(data.length)
        .setAll(0, List<double>.from(data.map((e) => e.toDouble())));
    return ptr;
  } else if (data is Uint8List) {
    final ptr = calloc<Uint8>(data.length);
    ptr.asTypedList(data.length).setAll(0, data.map((e) => e));
    return ptr;
  } else if (data is List<int>) {
    final ptr = calloc<Uint32>(data.length);
    ptr.asTypedList(data.length).setAll(0, data.map((e) => e));
    return ptr;
  } else {
    throw (" flutter_gl OpenGLContextES.dart toPointer ${data.runtimeType} TODO ");
  }
}