Flutter:FlexibleSpaceBar折叠时更改文本 [英] Flutter: Change text when FlexibleSpaceBar is collapsed

查看:1549
本文介绍了Flutter:FlexibleSpaceBar折叠时更改文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我浏览了Flutter文档,试图找到一个事件,回调或什至当FlexSpaceSpaceBar折叠或展开时可能挂入的状态.

I have looked through the Flutter documentation to try and find an event, callback or even a state that I could hook into when the FlexibleSpaceBar is collapsed or expanded.

return new FlexibleSpaceBar(
  title: new Column(
    crossAxisAlignment: CrossAxisAlignment.end,
    mainAxisAlignment: MainAxisAlignment.end,
    children: <Widget>[
        new Text(_name, style: textTheme.headline),
        new Text(_caption, style: textTheme.caption)
    ]),
  centerTitle: false,
  background: getImage());`

在捕捉(折叠)FlexibleSpaceBar时,我想隐藏 _标题文本,而只显示 _name 文本.完全展开后,我显然想同时显示 _name 和& _标题.

When the FlexibleSpaceBar is snapped in (collapsed), I want to hide the _caption text and only display the _name text. When it is expanded fully, I obviously want to display both _name & _caption.

我该怎么做?

我是新手,所以我对此有些迷茫.

Im new to flutter, so I am somewhat lost on this.

也在 https://github.com/flutter/flutter/issues/18567

推荐答案

FlexibleSpaceBar本身还不够.您需要将其包装到CustomScrollViewSliverAppBar中.这些窗口小部件必须由ScrollController进行控制,每当滚动偏移量更改时,该窗口小部件都会触发一个事件.基于它,您可以确定应用栏是否折叠或展开,并相应地更改内容. 在这里,您将找到一个有效的示例.

FlexibleSpaceBar per se won't be enough. You need to wrap it into CustomScrollView and SliverAppBar. These widgets must be controller by a ScrollController, which will fire an event whenever scroll offset changes. Based on it, you can find out if app bar is collapsed or expanded, and change the content accordingly. Here you will find a working example.

这篇关于Flutter:FlexibleSpaceBar折叠时更改文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆