[英]Flutter Web iFrame weird behavior
My Project was working totally fine a month ago, and now after several flutter updates , my iFrame widget is false centered in its desired renderbox.一个月前我的项目工作得很好,现在经过几次 flutter 更新,我的 iFrame 小部件在其所需的渲染框中居中是错误的。 First picture is the wrong behavior, second is the old working version.
第一张图片是错误的行为,第二张是旧的工作版本。 I'm using a plugin which prevents the analyzer from prompting errors when using platformViewRegistry .
我正在使用一个插件,它可以防止分析器在使用platformViewRegistry时提示错误。 Below is my code for the iframe-widget.
下面是我的 iframe-widget 代码。 Does someone know how to fix this?
有人知道如何解决这个问题吗? I don't want to downgrade to older flutter versions.
我不想降级到较旧的 flutter 版本。 Thanks for any help!
谢谢你的帮助!
PS: Simple Center() did not work PS:简单的 Center() 不起作用
My IFrame Widget我的 IFrame 小部件
// ignore: avoid_web_libraries_in_flutter
import 'dart:html';
// ignore: undefined_prefixed_name
import 'package:universal_ui/universal_ui.dart';
import 'package:flutter/material.dart';
class Iframe extends StatefulWidget {
final String source;
final Size size;
Iframe(this.source, {this.size});
@override
_IframeState createState() => _IframeState();
}
class _IframeState extends State<Iframe> {
Widget _iframeWidget;
String source;
@override
void initState() {
newFrame();
super.initState();
}
void newFrame() async {
print(widget.size);
final String id = widget.source.hashCode.toString();
final IFrameElement _iframeElement = IFrameElement();
_iframeElement.height = widget.size?.height?.toString() ?? '500';
_iframeElement.width = widget.size?.width?.toString() ?? '500';
source = widget.source;
_iframeElement.src = widget.source;
_iframeElement.style.border = 'none';
ui.platformViewRegistry
.registerViewFactory(id, (int viewID) => _iframeElement);
_iframeWidget = HtmlElementView(
key: UniqueKey(),
viewType: id,
);
}
@override
Widget build(BuildContext context) {
if (source != widget.source) newFrame();
return _iframeWidget;
}
}
Using IFrame Widget使用 IFrame 小部件
class ChatClientAnon extends StatelessWidget {
@override
Widget build(BuildContext context) {
return StreamCacheBuilder<Package>(
stream: Database().streamPackage(),
builder: (data) => Container(
child: Row(
children: [
Expanded(child: SmartphoneClient('Anonym', isAnon: true), flex: 2),
Expanded(
child: LayoutBuilder(
builder: (_, c) =>
Iframe(data.source, size: c.biggest)),
flex: 8),
],
),
),
);
}
}
Update: issue got fixed with next flutter update更新:下一个 flutter 更新解决了问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.