flutter - Flutter Web iFrame 奇怪的行为
问题描述
一个月前我的项目工作得很好,现在经过几次颤振更新,我的 iFrame 小部件在其所需的渲染框中居中是错误的。第一张图片是错误的行为,第二张是旧的工作版本。我正在使用一个插件,它可以防止分析器在使用platformViewRegistry时提示错误。下面是我的 iframe-widget 代码。有人知道如何解决这个问题吗?我不想降级到较旧的颤振版本。谢谢你的帮助!
PS:简单的 Center() 不起作用
我的 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;
}
}
使用 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),
],
),
),
);
}
}
解决方案
更新:问题在下一次颤振更新中得到解决
推荐阅读
- html - 如果使用 iTextsharp 第一页的某些内容和第二页的某些内容,想要将整个表格 tr 移动到下一页
- perl - 关于 perl 引用优先级的困惑
- python - 为 PyQtWebEngine 的隐身模式添加选项卡
- asp.net-mvc - 在 Linq 中使用 GroupBy 时如何通过用户 ID 获取内容
- javascript - 从给定的数字返回最大可能的数字?javascript
- c++ - int[8][8] 类型的参数变成 int(*)[8]
- python - 400 错误请求:浏览器(或代理)发送了此服务器无法理解的请求。KeyError:“名称搜索”
- python - 根据其他列 panda 的值创建新列
- gnuplot - 相对于 Gnuplot 中的行号绘图
- python - 当我更改所需的文本文件时,如何让 tkinter 应用程序更新?