Может ли кто-нибудь указать мне пример кода, который позволяет отображать видео в TabBarView? До сих пор он выдает ошибку, когда я пытаюсь загрузить видео во вкладке:
I/flutter ( 5591): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ I/flutter ( 5591): The following assertion was thrown while finalizing the widget tree: I/flutter ( 5591): 'package:flutter/src/widgets/scroll_position.dart': Failed assertion: line 683 pos 12: 'pixels != I/flutter ( 5591): null': is not true. ...
В приведенном ниже коде показан видеопроигрыватель YouTube в TabBarVew. Вам необходимо обновить файл pubspec.yaml для видеопакета YouTube, например:
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://thewikihow.com/video_Gb2xJ-GMKmo",
quality: YoutubeQuality.HD,
aspectRatio: 16/9,
showThumbnail: true,),
new YoutubePlayer(
source: "https://thewikihow.com/video_Gb2xJ-GMKmo",
quality: YoutubeQuality.HD,
aspectRatio: 16/9,
showThumbnail: true,),
new YoutubePlayer(
source: "https://thewikihow.com/video_Gb2xJ-GMKmo",
quality: YoutubeQuality.HD,
aspectRatio: 16/9,
showThumbnail: true,),
],
controller: _tabController,),
);
}
}
Вы можете использовать пакет video_player вместо youtube_player, если хотите воспроизводить видео со своего телефона.