本文主要是介绍颤振稳定性叶瓣图_在屏幕之间导航—颤振,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
颤振稳定性叶瓣图
Hi everybody,
大家好,
In this post, we are going to show favorite elements selected from a list. This is a continuation of my previous post.
在这篇文章中,我们将显示从列表中选择的收藏夹元素。 这是我上一篇文章的延续。
We need to add a button of somewhere which go to new screen with favorite words selected. In this case, i’m going to use an IconButton
for this design.
我们需要在某处添加一个按钮,该按钮会转到新屏幕,并选择喜欢的单词。 在这种情况下,我将为此设计使用IconButton
。
AppBar
widget has a property called actions
which is a List<Widget>
, we just need to add one:
AppBar
小部件具有一个名为actions
的属性,它是一个List<Widget>
,我们只需要添加一个即可:
IconButton
represents an icon with a behaviour, the onPressed
function will be executed when user press this button. So, we need to create a new screen called FavoriteWordsRoute
.
IconButton
代表具有行为的图标,当用户按下此按钮时,将执行onPressed
函数。 因此,我们需要创建一个名为FavoriteWordsRoute
的新屏幕。
Terminology: In Flutter, screens and pages are called routes. The remainder of this recipe refers to routes.In Android, a route is equivalent to an Activity. In iOS, a route is equivalent to a ViewController. In Flutter, a route is just a widget.
术语 :在Flutter中, 屏幕和页面称为路线 。 本食谱的其余部分涉及路线。在Android中,路线等同于活动。 在iOS中,路由等效于ViewController。 在Flutter中,路线只是一个小部件。
In this case, our new route is StatelessWidget
which means this route is not mutable state. I mean, Stateless widget are useful when the part of the user interface you are describing does not depend on anything other than the configuration information provided it.
在这种情况下,我们的新路由是StatelessWidget
,这意味着该路由不是可变状态。 我的意思是,当您描述的用户界面部分不依赖于提供的配置信息以外的其他任何内容时, 无状态 小部件很有用。
On the other hand, we need to call Navigator
this way in order to create our new route:
另一方面,我们需要以这种方式调用Navigator
来创建新路线:
Navigator
is a widget that manages a set of child widgets with a stack discipline. Its means, when we press button to call new screen, it will put above first screen.
Navigator
是一个小部件,它使用堆栈规则管理一组子小部件。 它的意思是,当我们按下按钮来调用新屏幕时,它将放在第一个屏幕上方 。
We need to create a MaterialPageRoute
to replace current screen for new one. This widget manages screen with a platform-adaptive transition.
我们需要创建一个MaterialPageRoute
来替换当前屏幕。 此小部件通过平台自适应的过渡来管理屏幕。
Let’s see FavoriteWordsRoute
… is empty, right?. Now, we are going to design it. We want a design looks like similar to main list. But, we need to show words selected.
让我们看看FavoriteWordsRoute
…是空的,对吧? 现在,我们将对其进行设计。 我们希望设计看起来类似于主列表。 但是,我们需要显示选中的单词。
For that, when we create FavoriteWordsRoute
we need to pass selected items.
为此,当我们创建FavoriteWordsRoute
我们需要传递选定的项目。
By convention, widget constructors only use named arguments, in this case favoriteItems is a named arguments. Named arguments can be marked as required using @required
. Also by convention, the first argument is key, and the last argument is child, children, or the equivalent.
按照约定,小部件构造函数仅使用命名参数,在这种情况下,favouriteItems是命名参数。 可以使用@required
将命名参数标记为必需。 同样按照惯例,第一个参数是键,最后一个参数是child,children或等效参数。
FavoriteWordsRoute
looks like:
FavoriteWordsRoute
看起来像:
So far, so good. But its still do nothing!.
到目前为止,一切都很好。 但是它仍然无能为力!
Before we create to a new ListView.separated()
like main list, we need to add Scaffold
widget. This widget is really useful and important, it gives you many basic functionalities out of the box, like AppBar
(with icon which back to previous screen), BottomNavigationBar
, Drawer
, FloatingActionButton
, etc.
在创建像主列表这样的新ListView.separated()
之前,我们需要添加Scaffold
小部件。 这个小部件非常有用且重要,它为您提供了许多现成的基本功能,例如AppBar
(带有返回上一屏幕的图标), BottomNavigationBar
, Drawer
, FloatingActionButton
等。
So, we add Scaffold
and ListView.separated()
widgets to create our list of favorite words.
因此,我们添加了Scaffold
和ListView.separated()
小部件以创建我们喜欢的单词列表。
In this case, we show only title using ListTile
widget.
在这种情况下,我们仅使用ListTile
小部件显示标题。
CHALLENGE ALERT!
挑战警报!
When there are not selected some words and press button, next screen shows blank. This is not a good design for UI and for user experience.
当未选择某些单词并按按钮时,下一个屏幕将显示为空白。 对于UI和用户体验而言,这不是一个好的设计。
Well, I have a challenge for you: you could show a message using a Text
widget which has to show following text ‘No favorite words here!’.
好吧,我为您带来了一个挑战:您可以使用“ Text
小部件显示一条消息,该消息必须显示以下文本“ 此处没有喜欢的单词! '。
Remind, there is no one solution.
提醒一下,没有一种解决方案。
Do you accept the challenge?. Tell me in comments and we can talk solutions!.
您接受挑战吗? 在评论中告诉我,我们可以讨论解决方案!
In future post i’m going to code how to show the partial number when user are selecting words over button, like a Badge
.
在以后的文章中,我将编写代码,当用户在按钮上选择单词时,如何显示部分数字,例如Badge
。
Full code is available on Github.
完整的代码可以在Github上找到 。
If you want, you can read my previous Flutter articles!.
如果需要,可以阅读我以前的Flutter文章!
That all folks!Enjoy!
所有人!享受!
翻译自: https://medium.com/swlh/navigate-between-screens-flutter-9451be448d15
颤振稳定性叶瓣图
相关文章:
这篇关于颤振稳定性叶瓣图_在屏幕之间导航—颤振的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!