Flutter - Hiding FloatingActionButton

前端 未结 7 1671
悲哀的现实
悲哀的现实 2020-12-13 18:18

Is there any built in way in Flutter to hide a FloatingActionButton on ListView scrolling down and then showing it on scrolling up?

7条回答
  •  不思量自难忘°
    2020-12-13 18:41

    There are many ways of handing it. Let me list few here.

    1. You can use Visibility to hide/show FAB.

      floatingActionButton: Visibility(
        child: FloatingActionButton(...),
        visible: false, // set it to false
      )
      
    2. With Dart 2.2, you can use if condition like this:

      floatingActionButton: Column(
        children: [
          if (shouldShow) FloatingActionButton(...), // visible if showShould is true
        ],
      )
      
    3. You can use Opacity widget.

      floatingActionButton: Opacity(
        opacity: shouldShow ? 1 : 0, // visible if showShould is true
        child: FloatingActionButton(...),
      )
      

提交回复
热议问题