SliverAppBar 滚动时 flexibleSpace 内的图标不隐藏

Icons inside flexibleSpace not hiding when SliverAppBar scrolled

我在 flexibleSpace 中有 'Next' 和 'Prev' 按钮,如下所示,'Next' 和 'Prev' 按钮的文本确实隐藏在滚动但向前和向后箭头不隐藏。我希望它们在滚动时隐藏。

这是我的代码,

            SliverAppBar(
              backgroundColor: selectedColor ?? Colors.blue,
              expandedHeight: 112,
              snap: true,
              pinned: false,
              floating: true,
              forceElevated: true,
              actions: <Widget>[
                IconButton(
                    icon: Icon(Icons.event),
                    onPressed: () {
                      DateTime now = DateTime.now();
                      _selectDate(context, now);
                    })
              ],
              flexibleSpace: selectedTitle != null ? SafeArea(
                child: Column(
                  children: <Widget>[
                    Container(
                      height: kToolbarHeight,
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          Text(
                            selectedTitle?.toUpperCase() ?? '',
                            style: Theme
                                .of(context)
                                .textTheme
                                .title
                                .copyWith(fontSize: 16, color: Colors.white),
                          ),
                          SizedBox(
                            height: 2,
                          ),
                          isWeekly
                              ? SizedBox(
                            height: 0,
                            width: 0,
                          )
                              : Text(
                            displayDate ?? '',
                            style: Theme
                                .of(context)
                                .textTheme
                                .caption
                                .copyWith(fontSize: 10, color: Colors.white),
                          ),
                          SizedBox(
                            height: 2,
                          ),
                          Text(
                            selectedParshaNodeModel?.parshaName ?? '',
                            style: Theme
                                .of(context)
                                .textTheme
                                .subtitle
                                .copyWith(fontSize: 14, color: Colors.white),
                          ),
                        ],
                      ),
                    ),
                    Expanded(
                      child: Container(
                        height: kToolbarHeight,
                        width: MediaQuery
                            .of(context)
                            .size
                            .width,
                        color: Colors.white,
                        child: Row(
                          children: <Widget>[
                            Expanded(
                                child:
                                FlatButton(
                                    onPressed: () {}
                                     ,
                                    child: Row(
                                      crossAxisAlignment:
                                      CrossAxisAlignment.center,
                                      mainAxisAlignment:
                                      MainAxisAlignment.spaceAround,
                                      children: <Widget>[
                                        Icon(Icons.arrow_back,
                                            color: Colors.grey),
                                        Text(
                                          'Prev',
                                          style: Theme
                                              .of(context)
                                              .textTheme
                                              .subhead
                                              .copyWith(color: Colors.grey),
                                        )
                                      ],
                                    ))),
                            Expanded(
                                child:
                                FlatButton(
                                    onPressed: (){},
                                    child: Row(
                                      mainAxisAlignment:
                                      MainAxisAlignment.spaceAround,
                                      crossAxisAlignment:
                                      CrossAxisAlignment.center,
                                      children: <Widget>[
                                        Text('Next',
                                            style: Theme
                                                .of(context)
                                                .textTheme
                                                .subhead
                                                .copyWith(color: Colors.grey)),
                                        Icon(
                                          Icons.arrow_forward,
                                          color: Colors.grey,
                                        ),
                                      ],
                                    )))
                          ],
                        ),
                      ),
                    )
                  ],
                ),
              ) : Container(),
            ),

发生这种情况是因为箭头超出了按钮的范围。添加 clipBehavior: Clip.hardEdge 应该可以解决您的问题:

child: FlatButton(
  clipBehavior: Clip.hardEdge,
  onPressed: () {},
  child: Row(
    ...Your Arrow and Text
  ),
),