build method

  1. @override
Widget build(
  1. BuildContext context,
  2. double shrinkOffset,
  3. bool overlapsContent
)
override

The widget to place inside the SliverPersistentHeader.

The context is the BuildContext of the sliver.

The shrinkOffset is a distance from maxExtent towards minExtent representing the current amount by which the sliver has been shrunk. When the shrinkOffset is zero, the contents will be rendered with a dimension of maxExtent in the main axis. When shrinkOffset equals the difference between maxExtent and minExtent (a positive number), the contents will be rendered with a dimension of minExtent in the main axis. The shrinkOffset will always be a positive number in that range.

The overlapsContent argument is true if subsequent slivers (if any) will be rendered beneath this one, and false if the sliver will not have any contents below it. Typically this is used to decide whether to draw a shadow to simulate the sliver being above the contents below it. Typically this is true when shrinkOffset is at its greatest value and false otherwise, but that is not guaranteed. See NestedScrollView for an example of a case where overlapsContent's value can be unrelated to shrinkOffset.

Implementation

@override
Widget build(
    BuildContext context, double shrinkOffset, bool overlapsContent) {
  final currExtent = (expandedHeight - shrinkOffset)
      .clamp(minExtent, expandedHeight)
      .toDouble();
  final rem = currExtent - minExtent;
  final ratio = rem == 0 ? 0.0 : rem / (expandedHeight - minExtent);
  var shouldRebuild = shouldRebuildFn(currExtent, ratio, overlapsContent);
  if (_lastBuilt == null || shouldRebuild) {
    isExceeded = false;
//      print("${debugLabel ?? 'test'}: "
//          "extent: $currExtent; rem: ${currExtent - minExtent}; "
//          "ratio: $ratio; shrink: $shrinkOffset; "
//          "overlap: $overlapsContent");
    /// i changed the min to always be at least as large as the max
    _lastBuilt = FlexibleSpaceBar.createSettings(
      toolbarOpacity: 1,
      minExtent: minExtent.roundToDouble(),
      maxExtent:
          max(minExtent.roundToDouble(), expandedHeight - shrinkOffset),
      currentExtent: currExtent,
      child: builder(currExtent, ratio, child),
    );
  } else if (!shouldRebuild && !isExceeded) {
    /// i changed the min to always be at least as large as the max
    _lastBuilt = FlexibleSpaceBar.createSettings(
      toolbarOpacity: 1,
      minExtent: minExtent.roundToDouble(),
      maxExtent:
          max(minExtent.roundToDouble(), expandedHeight - shrinkOffset),
      currentExtent: currExtent,
      child: builder(currExtent, ratio, child),
    );
    isExceeded = true;
  }
  return _lastBuilt!;
}