-
Notifications
You must be signed in to change notification settings - Fork 0
/
sliver_appbar_delegate.dart
60 lines (46 loc) · 1.64 KB
/
sliver_appbar_delegate.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import 'dart:math' as math;
import 'package:flutter/material.dart';
/// [SliverAppBarDelegate] is an implementation of [SliverPersistentHeaderDelegate] with a [PreferredSize] child.
class SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
const SliverAppBarDelegate({
@required this.child,
}) : assert(child != null);
final PreferredSize child;
@override
double get minExtent => child.preferredSize.height;
@override
double get maxExtent => child.preferredSize.height;
@override
Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
return child;
}
@override
bool shouldRebuild(SliverAppBarDelegate oldDelegate) {
return child != oldDelegate.child;
}
}
/// [SliverAppBarSizedDelegate] is an implementation of [SliverPersistentHeaderDelegate] with size setting and a child.
class SliverAppBarSizedDelegate extends SliverPersistentHeaderDelegate {
const SliverAppBarSizedDelegate({
@required this.minHeight,
@required this.maxHeight,
@required this.child,
}) : assert(minHeight != null),
assert(maxHeight != null),
assert(child != null);
final double minHeight;
final double maxHeight;
final Widget child;
@override
double get minExtent => minHeight;
@override
double get maxExtent => math.max(maxHeight, minHeight);
@override
Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
return SizedBox.expand(child: child);
}
@override
bool shouldRebuild(SliverAppBarSizedDelegate oldDelegate) {
return maxHeight != oldDelegate.maxHeight || minHeight != oldDelegate.minHeight || child != oldDelegate.child;
}
}