gpt4 book ai didi

flutter - 错误:在flutter中只能在初始化程序中访问静态成员

转载 作者:行者123 更新时间:2023-12-03 04:55:45 24 4
gpt4 key购买 nike

我试图解决此问题,但无法
我正在将数据传递给构造函数进行初始化并放入源中
有人能帮助我吗

插件:https://pub.dev/packages/flutter_ijkplayer

class FullScreen extends StatefulWidget {
String url_ , userAgent;
FullScreen(
this.url_,
this.userAgent,
) ;

@override
_FullScreenState createState() => _FullScreenState(this.url_, this.userAgent);
}

class _FullScreenState extends State<FullScreen> {
var controller = IjkMediaController();
String url , userAgent;


_FullScreenState(this.url, this.userAgent);
Orientation get orientation => MediaQuery.of(context).orientation;
DataSource source = DataSource.network(
widget.url_,------>ERROR : Error: Only static members can be accessed in initializers
headers: {
'User-Agent':widget.userAgent------>ERROR : Error: Only static members can be accessed in initializers
}
);


@override
initState() async {
controller.setDataSource(source, autoPlay: true);
super.initState();
}

最佳答案

您只能访问静态成员初始化。要使变量静态化,请在变量声明的前面使用static关键字。

static String url;



但是如果你。不想将其设为静态,则可以按以下方式在initistate中初始化该变量。
var controller;
Orientation get orientation => MediaQuery.of(context).orientation;
DataSource source;
@override
void initState() {
super.initState();
controller = IjkMediaController();
source =
DataSource.network(widget.url_, headers: {'User-Agent': widget.url_});
controller.setDataSource(source, autoPlay: true);
}

关于flutter - 错误:在flutter中只能在初始化程序中访问静态成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60628336/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com