微信交流群

# SliverLayoutBuilder

根据组件的约束条件提供子组件,比如当用户向下划动时,盒子显示红色,向上滑动时显示蓝色:

CustomScrollView(
  slivers: <Widget>[
    SliverLayoutBuilder(
      builder: (BuildContext context, SliverConstraints constraints) {
        print('${constraints.userScrollDirection}');
        var color = Colors.red;
        if (constraints.userScrollDirection == ScrollDirection.forward) {
          color = Colors.blue;
        }
        return SliverToBoxAdapter(
            child: Container(
          height: 100,
          color: color,
        ));
      },
    ),
  ],
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

SliverLayoutBuilder