本文介绍了Flutter Drawer Widget - 更改 Scaffold.body 内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 Flutter Scaffold.Drawer 时 - 是否可以让 Drawer 中的链接更改页面上的内容 (Scaffold.body)?
When using the Flutter Scaffold.Drawer - is it possible to have the links in the Drawer change the content (Scaffold.body) on the page?
类似于在导航抽屉中使用链接更改 Android 中的 Fragment.
Similarly to having links in the navigation drawer change a Fragment in Android.
推荐答案
您可以通过与您的 Drawer
项目交互,简单地更改您感兴趣的内容的 state
,例如这个:
You can simply change the state
of the content of your interest by interacting with your Drawer
items like this:
这是这个例子的相关代码:
Here is the relevant code for this example:
class TestPage extends StatefulWidget {
@override
_TestPageState createState() => new _TestPageState();
}
class _TestPageState extends State<TestPage> {
String text = "Initial Text";
@override
Widget build(BuildContext context) {
return new Scaffold(
drawer: new Drawer(
child: new ListView(
children: <Widget>[
new Container(child: new DrawerHeader(child: new Container())),
new Container (
child: new Column(
children: <Widget>[
new ListTile(leading: new Icon(Icons.info),
onTap:(){
setState((){
text = "info pressed";
});
}
),
new ListTile(leading: new Icon(Icons.save),
onTap:(){
setState((){
text = "save pressed";
});
}
),
new ListTile(leading: new Icon(Icons.settings),
onTap:(){
setState((){
text = "settings pressed";
});
}
),
]
),
)
],
),
),
appBar: new AppBar(title: new Text("Test Page"),),
body: new Center(child: new Text((text)),
));
}
}
这篇关于Flutter Drawer Widget - 更改 Scaffold.body 内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!