【发布时间】:2020-05-09 17:47:17
【问题描述】:
我是颤振和飞镖的真正初学者。 我在使用 [ youtube_player_flutter: ^6.1.1] 播放 youtube 视频时遇到问题 我创建了一个带有 youtube 链接的 Json 文件,我想将它与 [youtube_player_flutter: ^6.1.1] 链接。但它总是显示错误消息[在初始化程序中只能访问静态成员]
@override
Widget build(BuildContext context) {
// this function is called before the build so that
// the string assettoload is avialable to the DefaultAssetBuilder
setasset();
// and now we return the FutureBuilder to load and decode JSON
return FutureBuilder(
future:
DefaultAssetBundle.of(context).loadString(assettoload, cache: true),
builder: (context, snapshot) {
List mydata = json.decode(snapshot.data.toString());
if (mydata == null) {
return Scaffold(
body: Center(
child: Text(
"Loading",
),
),
);
} else {
return quizpage(mydata: mydata);
}
},
);
}
}
class quizpage extends StatefulWidget {
final dynamic mydata;
////////var youtubeUrl;
quizpage({Key key, @required this.mydata}) : super(key: key);
@override
_quizpageState createState() => _quizpageState(mydata);
}
class _quizpageState extends State<quizpage> {
var mydata;
_quizpageState(this.mydata);
int marks = 0;
int i = 1;
@override
void setState(fn) {
if (mounted) {
super.setState(fn);
}
}
YoutubePlayerController _controller;
@override
void initState() {
_controller = YoutubePlayerController(
initialVideoId: YoutubePlayer.convertUrlToId(mydata[4]["1"]));
super.initState();
}
void nextquestion() {
setState(() {
if (i < 10) {
i++;
} else {
Navigator.of(context).pushReplacement(MaterialPageRoute(
builder: (context) => resultpage(marks: marks),
));
}
问题是我想让 [String videoURL ] 播放我的 json 数据文件中的视频列表。
提前致谢。
【问题讨论】:
-
您两次声明了变量
mydata。第一个实例在状态对象中,第二个实例在有状态小部件@Montasser Mohamed -
你好,我这里没有看到任何错误,还有其他代码我们可以看看吗?
-
感谢您的关注。我更新了代码,如果你能帮我一把。