flutter跨平台
In this short tutorial, we will learn how to quickly create a tabbed cross-platform (iOS and Android) application in Flutter.
在这个简短的教程中,我们将学习如何在Flutter中快速创建选项卡式跨平台(iOS和Android)应用程序。
The source code of the project is available at the bottom of the article.
该项目的源代码位于文章底部。
First, let’s create a brand new project and set up our MaterialApp and the HomePage widget:
首先,让我们创建一个全新的项目,并设置我们的MaterialApp和HomePage小部件:
Now, let’s update the _HomePageState class:
现在,让我们更新_HomePageState类:
We define the _selectedIndex property to track which tab is tapped. We also create the _navigationBarItems list of three items: Home, Search, and Profile.
我们定义_selectedIndex属性以跟踪哪个标签被点击。 我们还创建了三个项目的_navigationBarItems列表: Home , Search和Profile 。
Finally, we add this list to the widget tree inside the build method. Let’s now add individual screens for each BottomNavigationBarItem.
最后,我们将此列表添加到build方法内的小部件树中。 现在让我们为每个BottomNavigationBarItem添加单独的屏幕。
Let’s create a Scaffold widget with an AppBar inside it:
让我们创建一个内部带有AppBar的Scaffold小部件:
Similarly, we add another screen:
同样,我们添加另一个屏幕:
And lastly, we add the Profile widget:
最后,我们添加Profile小部件:
Now let’s display our created screens inside the app. Inside the home_page.dart, we should add a _currentWidget property and update the _onItemTapped method:
现在,让我们在应用程序中显示我们创建的屏幕。 在home_page.dart内部,我们应该添加_currentWidget属性并更新_onItemTapped方法:
And include the _currentWidget property inside the build method:
并将_currentWidget属性包含在build方法中:
We have successfully implemented a tabbed application using Flutter.
我们已经使用Flutter成功实现了选项卡式应用程序。
The source code of the project:
该项目的源代码:
Want to learn more about Dart and Flutter? Feel free to check out my other relevant pieces:
想更多地了解Dart和Flutter? 随时查看我的其他相关文章:
Thanks for reading!
谢谢阅读!
翻译自: https://medium.com/better-programming/create-a-cross-platform-tabbed-app-in-flutter-c728ca5e30f6
flutter跨平台
相关资源:闲鱼基于Flutter的移动端跨平台应用实践