我正在回答我自己的问题,因为我在搜索此问题时没有找到任何可以解决此问题的方法。
所以,我尝试了define the controller in initState()
它并且它起作用了,现在它是working in v7.0.0+7
. 这是我的代码:
class AboutTopic extends StatefulWidget {
final String videoLink;
AboutTopic({this.videoLink});
@override
_AboutTopicState createState() => _AboutTopicState();
}
class _AboutTopicState extends State<AboutTopic> {
YoutubePlayerController _controller;
@override
void initState() {
_controller = YoutubePlayerController(
initialVideoId:
YoutubePlayer.convertUrlToId(widget.videoLink),
flags: YoutubePlayerFlags(
mute: false,
autoPlay: true,
disableDragSeek: true,
loop: false,
enableCaption: false),
);
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('About'),
centerTitle: true,
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
Navigator.of(context).pop();
},
)
),
body: YoutubePlayer(
controller: _controller,
showVideoProgressIndicator: true,
bottomActions: <Widget>[
const SizedBox(width: 14.0),
CurrentPosition(),
const SizedBox(width: 8.0),
ProgressBar(isExpanded: true),
RemainingDuration(),
],
aspectRatio: 4 / 3,
progressIndicatorColor: Colors.white,
onReady: () {
print('Player is ready.');
},
),
);
}
}