【发布时间】:2020-04-16 16:13:31
【问题描述】:
我想在同一页面上的一列中单击按钮返回一个新的小部件。 因此,当单击按钮时,我试图在与列中的一个子项相同的页面上返回一个容器。
这是我的示例代码:
Column(
children: <Widget>[
// here I want to return my container in the show function
Text(
"This is a sample text",
style: TextStyle(fontSize: 40),
),
RaisedButton(
child: Text("click"),
onPressed: () {
debugPrint("clicked");
show();
},
)
],
);
show() {
return SampleContainer();
}
class SampleContainer extends StatefulWidget {
@override
_SampleContainerState createState() => _SampleContainerState();
}
class _SampleContainerState extends State<SampleContainer> {
@override
Widget build(BuildContext context) {
return Container(
child: Text("hi"),
);
}
}
【问题讨论】: