I'm new in Flutter and i'm developing a little web page for learn. I wanna put a google map and facebook feed using two iframe.
I base my code on Wangoo's code here: https://medium.com/flutter-community/flutter-web-and-iframe-f26399aa1e2a
If i use only one iframe it works perfect but if i use a second one it has the first's source and the first one doesn't show anything. Like this: https://i.stack.imgur.com/irTyY.jpg
Already test some others packages but the most isn't web compatible or just can't use an iframe with link like those ones
This is my code:
import 'package:flutter/material.dart';
//ignore: avoid_web_libraries_in_flutter
import 'dart:html';
import 'dart:ui' as ui;
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String linkMaps = 'https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d10500.899078315058!2d2.29133003705264!3d48.853924135746475!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x47e6701f7e8337b5%3A0xa2cb58dd28914524!2sEiffel%20Tower%2C%20Par%C3%ADs%2C%20Francia!5e0!3m2!1ses-419!2smx!4v1597383453609!5m2!1ses-419!2smx';
String linkFB = 'https://www.facebook.com/plugins/page.php?href=https%3A%2F%2Fwww.facebook.com%2FTourEiffel&tabs=timeline&width=340&height=500&small_header=false&adapt_container_width=true&hide_cover=false&show_facepile=true&appId';
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(color: Colors.red, child: new IframeScreen(400, 400, linkMaps)),
Container(color: Colors.blue, child: new IframeScreen(340, 400, linkFB))
],
),
)
);
}
}
//--------------------------------------------------------------------------I
//Code based on: Aseem Wangoo (Mar-22) I
//https://medium.com/flutter-community/flutter-web-and-iframe-f26399aa1e2a I
//--------------------------------------------------------------------------I
// ignore: must_be_immutable
class IframeScreen extends StatefulWidget {
double w;
double h;
String src;
IframeScreen(double _w, double _h, String _src){
this.w = _w;
this.h = _h;
this.src = _src;
}
@override
_IframeScreenState createState() => _IframeScreenState(w, h, src);
}
class _IframeScreenState extends State<IframeScreen> {
Widget _iframeWidget;
final IFrameElement _iframeElement = IFrameElement();
double _width;
double _height;
String _source;
_IframeScreenState(double _w, double _h, String _src){
_width = _w;
_height = _h;
_source = _src;
}
@override
void initState() {
super.initState();
_iframeElement.src = _source;
_iframeElement.style.border = 'none';
// ignore: undefined_prefixed_name
ui.platformViewRegistry.registerViewFactory(
'iframeElement',
(int viewId) => _iframeElement,
);
_iframeWidget = HtmlElementView(
key: UniqueKey(),
viewType: 'iframeElement',
);
}
@override
Widget build(BuildContext context) {
return SizedBox(
height: _height,
width: _width,
child: _iframeWidget,
);
}
}
Thanks :)