int Fl_Cairo_Window_Wrapper::handle(int event) {
  Dart_Handle args[1] = { Dart_NewInteger((int64_t)event) };
  Dart_Handle ret = HandleError(Dart_Invoke(_ref, Dart_NewStringFromCString("doHandle"), 1, args));
  int64_t returnValue;
  Dart_IntegerToInt64(ret, &returnValue);
  return returnValue;
}
void Fl_Cairo_Window_Wrapper::draw_cb(Fl_Cairo_Window *self, cairo_t *ctx) {
  Dart_PersistentHandle *ref = (Dart_PersistentHandle*)self -> user_data();

  // Create instance of CairoContext.
  Dart_Handle dartCairoContextType = HandleError(Dart_GetType(
                                       Dart_LookupLibrary(
                                         Dart_NewStringFromCString("package:fltk/fltk.dart")),
                                       Dart_NewStringFromCString("CairoContext"), 0, {}));
  Dart_Handle dartCairoContext = Dart_New(
                                   dartCairoContextType, Dart_EmptyString(), 0, {});

  // Link cairo context to CairoContext.
  Dart_SetNativeInstanceField(dartCairoContext, 0, (intptr_t)ctx);

  Dart_Handle args[1] = { dartCairoContext };
  HandleError(Dart_Invoke(*ref, Dart_NewStringFromCString("runDrawCb"), 1, args));
}
void Fl_Cairo_Window_Wrapper::resize(int x, int y, int w, int h) {
  Fl_Cairo_Window::resize(x, y, w, h);
  Dart_Handle args[4] = {
    Dart_NewInteger((int64_t)x),
    Dart_NewInteger((int64_t)y),
    Dart_NewInteger((int64_t)w),
    Dart_NewInteger((int64_t)h)
  };
  HandleError(Dart_Invoke(_ref, Dart_NewStringFromCString("resize"), 4, args));
}
gboolean _gdart_marshaller_check_argument_flags(
  GdartBridgeContext *self,
  Dart_Handle element,
    gpointer type,
    const EnumInfoKlass *type_klass,
  Dart_Handle *dart_error_out,
  GError **error)
{
  Dart_Handle base_object_class, temp_result, inner_container, name_handle;
  bool is_proper_type;
  int64_t raw_result;
  base_object_class = gdart_bridge_context_get_base_enum_class(self, dart_error_out, error);
  if (base_object_class == NULL) {
    return false;
  }
  temp_result = Dart_ObjectIsType(element, base_object_class, &is_proper_type);
  if (Dart_IsError(temp_result)) {
    *dart_error_out = temp_result;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    goto error;
  }
  if (!is_proper_type) {
    *dart_error_out = gdart_bridge_context_create_error_handle(self,
                      "%s: received an unexpected base info type", G_STRFUNC);
    g_set_error(error, GDART_ERROR, 1,
                "%s: received an unexpected base info type", G_STRFUNC);
    goto error;
  }
  name_handle = Dart_NewStringFromCString("index");
  if (Dart_IsError(name_handle)) {
    *dart_error_out = name_handle;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    return FALSE;
  }
  inner_container = Dart_GetField(element, name_handle);
  if (Dart_IsError(inner_container)) {
    *dart_error_out = inner_container;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    return FALSE;
  }
  temp_result = Dart_IntegerToInt64(inner_container, &raw_result);
  if (Dart_IsError(temp_result)) {
    *dart_error_out = temp_result;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    return FALSE;
  }
  return TRUE;
error:
  return FALSE;
}
gboolean _gdart_marshaller_check_argument_object(
  GdartBridgeContext *self,
  Dart_Handle element,
    gpointer type,
    const ObjectInfoKlass *type_klass,
  Dart_Handle *dart_error_out,
  GError **error)
{
  Dart_Handle base_object_class, temp_result, inner_container, name_handle;
  bool is_proper_type;
  RawPointerContainer* raw_pointer;
  GdartBridgeContextWrappedObject* object_info;
  GObject* object;
  GType gtype;
  GIInfoType object_info_type;
  
  base_object_class = gdart_bridge_context_get_base_object_class(self, dart_error_out, error);
  if (base_object_class == NULL) {
    return false;
  }
  if (Dart_IsNull(element)) {
    return TRUE;
  }
  temp_result = Dart_ObjectIsType(element, base_object_class, &is_proper_type);
  if (Dart_IsError(temp_result)) {
    *dart_error_out = temp_result;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    goto error;
  }
  if (!is_proper_type) {
    *dart_error_out = gdart_bridge_context_create_error_handle(self,
                      "%s: received an unexpected base info type", G_STRFUNC);
    g_set_error(error, GDART_ERROR, 1,
                "%s: received an unexpected base info type", G_STRFUNC);
    goto error;
  }
  name_handle = Dart_NewStringFromCString("_internal");
  if (Dart_IsError(name_handle)) {
    *dart_error_out = name_handle;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    return FALSE;
  }
  inner_container = Dart_GetField(element, name_handle);
  if (Dart_IsError(inner_container)) {
    *dart_error_out = inner_container;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    return FALSE;
  }
  temp_result = Dart_GetNativeInstanceField(inner_container, 0, (intptr_t*) &raw_pointer);
  if (Dart_IsError(temp_result)) {
    *dart_error_out = temp_result;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    return FALSE;
  }
  object_info = (GdartBridgeContextWrappedObject*) raw_pointer->raw_pointer;
  if (!object_info->object_info_klass.get_type(object_info->object_info,
                                               self,
					       &object_info_type,
					       dart_error_out,
					       error))
    return FALSE;
  if (object_info_type != GI_INFO_TYPE_OBJECT) {
    *dart_error_out = gdart_bridge_context_create_error_handle(self,
                      "%s: expected an object but got a struct", G_STRFUNC);
    g_set_error(error, GDART_ERROR, 1,
                "%s: expected an object but got a struct", G_STRFUNC);
    goto error;
  }
  object = (GObject*) object_info->object;
  if (!type_klass->get_gtype(type,
                             self,
			     &gtype,
			     dart_error_out,
			     error))
    return FALSE;
  if (!g_type_is_a(G_OBJECT_TYPE(object), gtype)) {
    *dart_error_out = gdart_bridge_context_create_error_handle(self,
                      "%s: expected an object of one type but got another", G_STRFUNC);
    g_set_error(error, GDART_ERROR, 1,
                "%s: expected an object of one type but got another", G_STRFUNC);
    goto error;
  }
  return TRUE;
error:
  return FALSE;
}
gboolean _gdart_marshaller_check_argument_struct_from_gtype(
  GdartBridgeContext *self,
  Dart_Handle element,
  GType type,
  Dart_Handle *dart_error_out,
  GError **error)
{
  Dart_Handle base_object_class, temp_result, inner_container, name_handle;
  bool is_proper_type;
  RawPointerContainer* raw_pointer;
  GdartBridgeContextWrappedObject* object_info;
  base_object_class = gdart_bridge_context_get_base_object_class(self, dart_error_out, error);
  if (base_object_class == NULL) {
    return false;
  }
  if (Dart_IsNull(element)) {
    return TRUE;
  }
  temp_result = Dart_ObjectIsType(element, base_object_class, &is_proper_type);
  if (Dart_IsError(temp_result)) {
    *dart_error_out = temp_result;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    goto error;
  }
  if (!is_proper_type) {
    *dart_error_out = gdart_bridge_context_create_error_handle(self,
                      "%s: received an unexpected base info type", G_STRFUNC);
    g_set_error(error, GDART_ERROR, 1,
                "%s: received an unexpected base info type", G_STRFUNC);
    goto error;
  }
  name_handle = Dart_NewStringFromCString("_internal");
  if (Dart_IsError(name_handle)) {
    *dart_error_out = name_handle;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    return FALSE;
  }
  inner_container = Dart_GetField(element, name_handle);
  if (Dart_IsError(inner_container)) {
    *dart_error_out = inner_container;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    return FALSE;
  }
  temp_result = Dart_GetNativeInstanceField(inner_container, 0, (intptr_t*) &raw_pointer);
  if (Dart_IsError(temp_result)) {
    *dart_error_out = temp_result;
    g_set_error(error, GDART_ERROR, 1, "Error from Dart operation.");
    return FALSE;
  }
  object_info = (GdartBridgeContextWrappedObject*) raw_pointer->raw_pointer;
  /* TODO: This is super-unreliable because there is no way to trust the gtype
   * given.
   * 
  if (object_info->type != type) {
    *dart_error_out = gdart_bridge_context_create_error_handle(self,
                      "%s: got an argument of the wrong type. This might be due to a problem in the GIR file", G_STRFUNC);
    g_set_error(error, GDART_ERROR, 1,
                "%s: got an argument of the wrong type. This might be due to a problem in the GIR file", G_STRFUNC);
    goto error;
  }
  */
  return TRUE;
error:
  return FALSE;
}