我完全不知道自己应该做什么。我使用 youtube_player_iframe 中的示例代码来播放单个 YouTube 视频。我唯一改变的是 videoID。 这是我的代码:
import 'package:flutter/material.dart';
import 'package:youtube_player_iframe/youtube_player_iframe.dart';
class Project extends StatelessWidget{
final String title;
final String details;
final String url;
const Project(this.title,this.details,this.url,{super.key});
@override
Widget build(BuildContext context){
YoutubePlayerController _controller = YoutubePlayerController.fromVideoId(
videoId: 'TYX3wGsKpwI',
autoPlay: false,
params: YoutubePlayerParams(showFullscreenButton: true),
);
return Container(
height:400,
child: YoutubePlayer(
controller: _controller,
aspectRatio: 16 / 9,
),
);
}
}
这是我热重新加载页面时遇到的错误:
The following assertion was thrown building Project(dirty):
Assertion failed:
file:///C:/Users/Emma%20Ude/AppData/Local/Pub/Cache/hosted/pub.dev/webview_flutter_platform_interface-2.10.0/lib/src/platform_navigation_delegate.dart:47:7
WebViewPlatform.instance != null
"A platform implementation for `webview_flutter` has not been set. Please ensure that an
implementation of `WebViewPlatform` has been set to `WebViewPlatform.instance` before use. For unit
testing, `WebViewPlatform.instance` can be set with your own test implementation."
The relevant error-causing widget was:
Project
Project:file:///C:/Users/Emma%20Ude/Desktop/My%20Website/flutter_website/lib/widgets/portfolio_content/projects_list.dart:15:9
我正在创建一个 flutter 网站,而不是一个应用程序,所以我只需要担心它作为一个网站的工作。我尝试将 webview_flutter 添加到 pubspec.yaml 中的依赖项中,看看这是否有帮助,但什么也没发生。
youtube_player_iframe: ^5.1.2
webview_flutter: ^4.7.0
我找出了问题所在。有人评论说要重建该项目,所以我也重新启动了我的计算机。现在可以了!