[英]Flutter - Send value to class
I'm trying to send a variable from a class to another class in flutter. 我正在尝试将变量从一个类发送到另一个类。 I don't use buttons so i need to send directly.
我不使用按钮,所以我需要直接发送。 I have something like this
我有这样的东西
final Elements elemento; <-- MODEL
final List<Widget> pages = [
new ParcelasDetailsChartPage(elemento: widget.elemento),
new Container(
color: Colors.red,
),
new Container(
color: Colors.blue,
)
];
In ParcelasDetailsChartPage 在ParcelasDetailsChartPage中
final Elements elemento;
ParcelasDetailsChartPage({Key key, this.elemento}) : super(key: key);
Return 返回
Only static members can be accessed in initializers.
在初始化器中只能访问静态成员。
What is the proper way to do this? 正确的方法是什么?
Based on your code: https://gist.github.com/ElHombreSinNombre/4a9dfcbe98a751e87f705748ae1ca3a5 根据您的代码: https : //gist.github.com/ElHombreSinNombre/4a9dfcbe98a751e87f705748ae1ca3a5
That's because you can't access to widget until the build context is ready. 这是因为在构建上下文准备就绪之前,您无法访问窗口小部件。
Change this : 改变这个:
class ParcelasDetailsPageState extends State<ParcelasDetailsPage> {
static final GlobalKey<ScaffoldState> scaffoldKey =
GlobalKey<ScaffoldState>();
int index = 0;
final List<Widget> pages = [
new ParcelasDetailsChartPage(elemento: widget.element),
new Container(
color: Colors.red,
),
new Container(
color: Colors.blue,
)
];
void initState() {
super.initState();
Future.delayed(Duration(seconds: 1)).then((_) => showSnackbar);
}
To this: 对此:
class ParcelasDetailsPageState extends State<ParcelasDetailsPage> {
static final GlobalKey<ScaffoldState> scaffoldKey =
GlobalKey<ScaffoldState>();
int index = 0;
List<Widget> pages = List();
void initState() {
super.initState();
pages = [
new ParcelasDetailsChartPage(elemento: widget.element),
new Container(
color: Colors.red,
),
new Container(
color: Colors.blue,
)
];
Future.delayed(Duration(seconds: 1)).then((_) => showSnackbar);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.