I am trying to embed a form from https://convertkit.com/ending-a-business-relationship onto my flutter Webpage. This has been super difficult and I can't seem to figure out why there isn't some easy system like with flutter apps.
So far I have set it up like this:
import 'package:flutter/material.dart';
import 'package:mygamedevpal/shared/appbar_desktop.dart';
import 'dart:js' as js;
import 'dart:html' as html;
import 'dart:ui' as ui;
class MyDesktopBody extends StatelessWidget {
const MyDesktopBody({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final currentWidth = MediaQuery.of(context).size.width;
return Scaffold(
appBar: AppBarDesktop(),
body: Center(
child: Iframe(),
// child: Text(
// "COMING SOON!",
// style: Theme.of(context).textTheme.bodyLarge,
// textAlign: TextAlign.center,
),
);
}
}
class Iframe extends StatelessWidget {
Iframe() {
// ignore: undefined_prefixed_name
ui.platformViewRegistry.registerViewFactory('iframe', (int viewId) {
var iframe = html.IFrameElement();
iframe.src = 'https://app.convertkit.com/forms/3425056/subscriptions';
return iframe;
});
}
@override
Widget build(BuildContext context) {
return Container(
width: 800, height: 600, child: HtmlElementView(viewType: 'iframe'));
}
}
However this gives me the following error:
Refused to display 'https://app.convertkit.com/' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
I read people saying to add embed to it however this just leads to a 404 from the website. Is there really no simple way to embed a form from another site using js for flutter websites?
Thanks in advance!
When using Flutter, you should probably use a webview widget such as webviewx instead of using dart:html and friends!
But that will probably not solve the actual error message, because it means that Convertkit forbids you to embed that URL in an <iframe>! You need to check with Convertkit how to embed correctly.
SAMEORIGIN
The page can only be displayed in a frame on the same origin as the page itself.
Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options