dart - 在 TabBarView 中颤振 video_player
问题描述
谁能指出一些允许在 TabBarView 中显示视频的示例代码?到目前为止,当我尝试在选项卡中加载视频时,它会引发错误:
I/颤振(5591):══╡小部件库发现异常╞══════════════════════════════════════════ ═════════════════════════ I/flutter(5591):在最终确定小部件树时引发以下断言:I/flutter(5591): 'package:flutter/src/widgets/scroll_position.dart':断言失败:第 683 行 pos 12:'pixels != I/flutter (5591): null':不正确。...
解决方案
下面的代码在 TabBarVew 中显示了 youtube 视频播放器。您需要为 youtube 视频包更新 pubspec.yaml 文件,例如:
dependencies:
youtube_player: ^0.6.0
您的要求的示例代码是:
import 'package:flutter/material.dart';
import 'package:youtube_player/youtube_player.dart';
void main() {
runApp(StartPage());
}
class StartPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: "New Task",
debugShowCheckedModeBanner: false,
home: new HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> with SingleTickerProviderStateMixin{
TabController _tabController;
@override
void initState() {
_tabController = new TabController(length: 3, vsync: this);
super.initState();
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("GrubX"),
bottom: TabBar(
unselectedLabelColor: Colors.white,
labelColor: Colors.amber,
tabs: [
new Tab(icon: new Icon(Icons.call)),
new Tab(
icon: new Icon(Icons.chat),
),
new Tab(
icon: new Icon(Icons.notifications),
)
],
controller: _tabController,
indicatorColor: Colors.white,
indicatorSize: TabBarIndicatorSize.tab,),
bottomOpacity: 1,
),
body: TabBarView(
children: [
new YoutubePlayer(
source: "https://www.youtube.com/watch?v=Gb2xJ-GMKmo",
quality: YoutubeQuality.HD,
aspectRatio: 16/9,
showThumbnail: true,),
new YoutubePlayer(
source: "https://www.youtube.com/watch?v=Gb2xJ-GMKmo",
quality: YoutubeQuality.HD,
aspectRatio: 16/9,
showThumbnail: true,),
new YoutubePlayer(
source: "https://www.youtube.com/watch?v=Gb2xJ-GMKmo",
quality: YoutubeQuality.HD,
aspectRatio: 16/9,
showThumbnail: true,),
],
controller: _tabController,),
);
}
}
如果您想从手机播放视频,可以使用 video_player 包而不是 youtube_player。
推荐阅读
- parsing - “Lexeme”与“Token”术语
- vba - 运行时错误“462”
- python - Python - 使用 pandas 数据框中的 sqlalchemy 写入 SQL Server 数据库
- c# - WPF图像控制中的鼠标处理
- unity3d - (统一)最好多次复制组件或使其成为公共静态?
- mysql - 如何将日期格式更改为逗号分隔列?
- javascript - 网站功能自动启动和停止工作
- scala - Akka Actor 消息传递延迟
- javascript - Javascript按等级列表对数组进行排序
- javascript - 如何在 JavaScript 中的 switch 中测试正则表达式的结果