小编Fox*_*nut的帖子

Flutter Web (3.7.5) - 平台视图类型的高度/宽度 - youtube_player_iframe

我一直在我的网络项目中使用youtube_player_iframe包,并一直在尝试理解和修复以下问题:

Height of Platform View type: [youtube-0] may not be set. Defaulting to `height: 100%`.
Set `style.height` to any appropriate value to stop this message.
Width of Platform View type: [youtube-0] may not be set. Defaulting to `width: 100%`.
Set `style.width` to any appropriate value to stop this message.
Run Code Online (Sandbox Code Playgroud)

一切似乎都按原样工作正常,但看到这条消息出现却很麻烦。这么说,我确实想确定并解决根本原因。在 Flutter 2.5 版本中,平台处理调整大小和定位视图的方式发生了变化。可以在此处找到更改的文档和迁移指南。不过,即使有指南,我似乎也缺乏利用它的能力。

以下是 Flutter 页面的迁移代码:

ui.platformViewRegistry.registerViewFactory(viewType, (int viewId) {
  final html.Element htmlElement = html.DivElement()
    // ..other props
    ..style.width = '100%'
    ..style.height = '100%';
  // ... …
Run Code Online (Sandbox Code Playgroud)

youtube-iframe-api flutter youtube-player-flutter

5
推荐指数
0
解决办法
1098
查看次数

Dart/Flutter List.isNotEmpty() 不正确?

我正在尝试访问一个列表,但前提是它不为空。在收到一些奇怪的路径后,我发现 List.isNotEmpty 返回的长度为 0,并且它不为空。当然,除非我所认为的“空”是错误的心态?

这是我运行的测试,我在其中创建了一个“空”列表。然后,我测试了一下,看看测试 isNotEmpty 时返回了什么。

List<String> myKeywords = [];
if(myKeywords.isNotEmpty){
  print("Keywords is not empty..?");
  print("Keywords length = ${myKeywords.length}");
  print("Keyword: \"${myKeywords.first}\"");
}
Run Code Online (Sandbox Code Playgroud)

// 输出

Keywords is not empty..?
Keywords length = 0
// Error: Bad state: No element
Run Code Online (Sandbox Code Playgroud)

这与字符串的工作方式不同:

String myString = "";
if(myString.isNotEmpty){
  print("myString is not empty..?");
  print("myString length = ${myString.length}");
}
else{
  print("myString is empty");
}
Run Code Online (Sandbox Code Playgroud)

输出:

myString is empty
Run Code Online (Sandbox Code Playgroud)

查看文档,List.isNotEmpty 声明如下:

Whether this collection has at least one element.
May be computed by checking if iterator.moveNext() …
Run Code Online (Sandbox Code Playgroud)

dart flutter

0
推荐指数
1
解决办法
278
查看次数