我正在使用android flutter框架。我想在我尝试过但没有得到的runApp();
内部调用两个类。
void main(){
runApp(new MaterialApp(
title: "Hello world",
home: new demo1(), //like this i want to call here demo2
));
}
class demo1 extends StatalessWidget {
//code here
}
class demo2 extends StatalessWidget {
//code here
}
有人可以建议我吗?我该怎么办?
答案 0 :(得分:0)
我不确定您打算做什么。我猜您想同时显示两个小部件demo1
和demo2
。在这种情况下,您可以使用Column
。
void main(){
runApp(new MaterialApp(
title: "Hello world",
home: new Column(
children: <Widget>[
demo1(),
demo2(),
],
),
));
}
还有许多其他布局屏幕的选项,请查看Layout Widgets部分。
答案 1 :(得分:0)
如果要竞争性地调用类,可以使用如下的Turnery运算符?
void main(){
bool condition = true;
runApp(new MaterialApp(
title: "Hello world",
home:condition? demo1():demo2(), //like this i want to call here demo2
));
}
class demo1 extends StatalessWidget {
//code here
}
class demo2 extends StatalessWidget {
//code here
}