Skip to content

Commit

Permalink
Merge pull request #51 from TatsuUkraine/release-4.0.0
Browse files Browse the repository at this point in the history
Release 4.0.0 -> master
  • Loading branch information
TatsuUkraine authored Feb 28, 2021
2 parents f77c668 + 6b3f4d6 commit 5e63c96
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 225 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
pubspec.lock
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [4.0.0] - 2021-03-01

- stable null-safety release

## [4.0.0-nullsafety.0] - 2021-02-14

- migrate to null-safety

## [3.0.1] - 2020-11-09

- fixed positive list render on rebuild
Expand Down
10 changes: 5 additions & 5 deletions lib/models/sticky_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class StickyState<I> {
/// If [InfiniteListItem.initialHeaderBuild] is true with [InfiniteListItem.overlay],
/// or default [InfiniteListItem] constructor is used,
/// initial header render will be called without this value
final double contentSize;
final double? contentSize;

StickyState(this.index,
{this.position = 0,
Expand All @@ -54,10 +54,10 @@ class StickyState<I> {

/// Create state duplicate, with optional state options override
StickyState<I> copyWith(
{double position,
double offset,
bool sticky,
double contentHeight}) =>
{double? position,
double? offset,
bool? sticky,
double? contentHeight}) =>
StickyState<I>(
index,
position: position ?? this.position,
Expand Down
8 changes: 4 additions & 4 deletions lib/models/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'package:flutter/widgets.dart';

import 'sticky_state.dart';

typedef Widget ContentBuilder(BuildContext context);
typedef Widget HeaderStateBuilder<I>(
typedef ContentBuilder = Widget Function(BuildContext context);
typedef HeaderStateBuilder<I> = Widget Function(
BuildContext context, StickyState<I> state);
typedef Widget HeaderBuilder(BuildContext context);
typedef double MinOffsetProvider<I>(StickyState<I> state);
typedef HeaderBuilder = Widget Function(BuildContext context);
typedef MinOffsetProvider<I> = double? Function(StickyState<I> state);
67 changes: 37 additions & 30 deletions lib/render.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ import 'models/types.dart';
/// Sticky item render object based on [RenderStack]
class StickyListItemRenderObject<I> extends RenderStack {
ScrollableState _scrollable;
StreamSink<StickyState<I>> _streamSink;
StreamSink<StickyState<I>>? _streamSink;
I _itemIndex;
MinOffsetProvider<I> _minOffsetProvider;
MinOffsetProvider<I>? _minOffsetProvider;
bool _overlayContent;
HeaderPositionAxis _positionAxis;
HeaderMainAxisAlignment _mainAxisAlignment;
HeaderCrossAxisAlignment _crossAxisAlignment;

double _lastOffset;
double? _lastOffset;
bool _headerOverflow = false;

StickyListItemRenderObject({
@required ScrollableState scrollable,
@required I itemIndex,
MinOffsetProvider<I> minOffsetProvider,
StreamSink<StickyState<I>> streamSink,
TextDirection textDirection,
required ScrollableState scrollable,
required I itemIndex,
MinOffsetProvider<I>? minOffsetProvider,
StreamSink<StickyState<I>>? streamSink,
TextDirection? textDirection,
Clip clipBehavior = Clip.hardEdge,
bool overlayContent,
bool overlayContent = false,
HeaderPositionAxis positionAxis = HeaderPositionAxis.mainAxis,
HeaderMainAxisAlignment mainAxisAlignment = HeaderMainAxisAlignment.start,
HeaderCrossAxisAlignment crossAxisAlignment =
Expand All @@ -50,9 +50,9 @@ class StickyListItemRenderObject<I> extends RenderStack {
clipBehavior: clipBehavior,
);

StreamSink<StickyState<I>> get streamSink => _streamSink;
StreamSink<StickyState<I>>? get streamSink => _streamSink;

set streamSink(StreamSink<StickyState<I>> sink) {
set streamSink(StreamSink<StickyState<I>>? sink) {
_streamSink = sink;
markNeedsPaint();
}
Expand All @@ -67,7 +67,7 @@ class StickyListItemRenderObject<I> extends RenderStack {
MinOffsetProvider<I> get minOffsetProvider =>
_minOffsetProvider ?? (state) => null;

set minOffsetProvider(MinOffsetProvider<I> offsetProvider) {
set minOffsetProvider(MinOffsetProvider<I>? offsetProvider) {
_minOffsetProvider = offsetProvider;
markNeedsPaint();
}
Expand Down Expand Up @@ -103,8 +103,6 @@ class StickyListItemRenderObject<I> extends RenderStack {
ScrollableState get scrollable => _scrollable;

set scrollable(ScrollableState newScrollable) {
assert(newScrollable != null);

final ScrollableState oldScrollable = _scrollable;
_scrollable = newScrollable;

Expand All @@ -116,11 +114,17 @@ class StickyListItemRenderObject<I> extends RenderStack {
}
}

RenderBox get _headerBox => lastChild;
RenderBox get _headerBox => lastChild!;

RenderBox get _contentBox => firstChild!;

RenderBox get _contentBox => firstChild;
RenderAbstractViewport get _viewport {
final viewport = RenderAbstractViewport.of(this);

RenderAbstractViewport get _viewport => RenderAbstractViewport.of(this);
assert(viewport != null, 'Can\'t find viewport');

return viewport!;
}

@override
void attach(PipelineOwner owner) {
Expand All @@ -135,7 +139,7 @@ class StickyListItemRenderObject<I> extends RenderStack {
}

@override
Rect describeApproximatePaintClip(RenderObject child) =>
Rect? describeApproximatePaintClip(RenderObject child) =>
_headerOverflow ? Offset.zero & size : null;

@override
Expand All @@ -144,7 +148,8 @@ class StickyListItemRenderObject<I> extends RenderStack {

if (clipBehavior != Clip.none && _headerOverflow) {
context.pushClipRect(
needsCompositing, paintOffset, Offset.zero & size, paintStack, clipBehavior: clipBehavior);
needsCompositing, paintOffset, Offset.zero & size, paintStack,
clipBehavior: clipBehavior);
} else {
paintStack(context, paintOffset);
}
Expand Down Expand Up @@ -186,22 +191,23 @@ class StickyListItemRenderObject<I> extends RenderStack {

final double stuckOffset = _stuckOffset;

final StackParentData parentData = _headerBox.parentData;
final StackParentData parentData =
_headerBox.parentData as StackParentData;
final double contentSize = _contentDirectionSize;
final double headerSize = _headerDirectionSize;

final double offset = _calculateStateOffset(stuckOffset, contentSize);
final double position = offset / contentSize;

final StickyState state = StickyState<I>(
final StickyState<I> state = StickyState<I>(
itemIndex,
position: position,
offset: offset,
contentSize: contentSize,
);

final double headerOffset = _calculateHeaderOffset(
contentSize, stuckOffset, headerSize, minOffsetProvider(state));
final double headerOffset = _calculateHeaderOffset(contentSize, stuckOffset,
headerSize, minOffsetProvider(state));

parentData.offset =
_headerDirectionalOffset(parentData.offset, headerOffset);
Expand Down Expand Up @@ -282,7 +288,7 @@ class StickyListItemRenderObject<I> extends RenderStack {
double get _scrollableSize {
final viewportContainer = _viewport;

double viewportSize;
double? viewportSize;

if (viewportContainer is RenderBox) {
final RenderBox viewportBox = viewportContainer as RenderBox;
Expand All @@ -292,7 +298,7 @@ class StickyListItemRenderObject<I> extends RenderStack {
: viewportBox.size.width;
}

assert(viewportSize != null, 'Can\'t define view port size');
assert(viewportSize != null, 'Can\'t define viewport size');

double anchor = 0;

Expand All @@ -301,10 +307,10 @@ class StickyListItemRenderObject<I> extends RenderStack {
}

if (_alignmentStart) {
return -viewportSize * anchor;
return -viewportSize! * anchor;
}

return viewportSize - viewportSize * anchor;
return viewportSize! - viewportSize * anchor;
}

double get _stuckOffset {
Expand All @@ -316,8 +322,9 @@ class StickyListItemRenderObject<I> extends RenderStack {
double get _contentDirectionSize =>
_scrollDirectionVertical ? size.height : size.width;

double get _headerDirectionSize =>
_scrollDirectionVertical ? _headerBox.size.height : _headerBox.size.width;
double get _headerDirectionSize => _scrollDirectionVertical
? _headerBox.size.height
: _headerBox.size.width;

Offset _headerDirectionalOffset(Offset originalOffset, double offset) {
if (_scrollDirectionVertical) {
Expand All @@ -339,7 +346,7 @@ class StickyListItemRenderObject<I> extends RenderStack {

double _calculateHeaderOffset(
double contentSize, double stuckOffset, double headerSize,
[double providedMinOffset]) {
[double? providedMinOffset]) {
if (providedMinOffset == null) {
providedMinOffset = headerSize;
}
Expand Down
Loading

0 comments on commit 5e63c96

Please sign in to comment.