Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(‘My Flutter App’),
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: 0, // this will be set when a new tab is tapped
items: [
BottomNavigationBarItem(
icon: new Icon(Icons.home),
title: new Text(‘Home’),
),
BottomNavigationBarItem(
icon: new Icon(Icons.mail),
title: new Text(‘Messages’),
),
BottomNavigationBarItem(
icon: Icon(Icons.person),
Title: Text(‘Profile’)
)
],
),
);
}
}
这里有很多内容,我们来逐一看看。在 _HomeState
类中,我们实现了 Home
widget 的 build 方法。我们从 build 方法返回的 widget 叫做 Scaffold
。这个 widget 有一些很棒的属性,可以帮助我们布置主屏幕,包括添加底部导航栏、滑动条和选项卡。我们现在只使用它的 appBar
和 bottomNavigationBar
属性。在我们的底部导航栏中,我们返回一个列表,其中列出了我们希望在底部栏中出现的项目。如您所见,我们有三个选项卡,分别是