From 3709bdf9407e2cd2d2417f67c8f12667d8abed93 Mon Sep 17 00:00:00 2001 From: Denis Beketsky Date: Sun, 8 Sep 2019 02:02:33 +0300 Subject: [PATCH 1/8] change target for event binding --- lib/render.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/render.dart b/lib/render.dart index b7ab0f0..982a5a2 100644 --- a/lib/render.dart +++ b/lib/render.dart @@ -67,8 +67,8 @@ class StickyListItemRenderObject extends RenderStack { markNeedsPaint(); if (attached) { - oldScrollable.widget.controller.removeListener(markNeedsPaint); - newScrollable.widget.controller.addListener(markNeedsPaint); + oldScrollable.position.removeListener(markNeedsPaint); + newScrollable.position.addListener(markNeedsPaint); } } @@ -80,12 +80,12 @@ class StickyListItemRenderObject extends RenderStack { @override void attach(PipelineOwner owner) { super.attach(owner); - scrollable.widget.controller.addListener(markNeedsPaint); + scrollable.position.addListener(markNeedsPaint); } @override void detach() { - scrollable.widget.controller.removeListener(markNeedsPaint); + scrollable.position.removeListener(markNeedsPaint); super.detach(); } From 920c379edce9e70693a97f05dfc799885b8bde3c Mon Sep 17 00:00:00 2001 From: Denis Beketsky Date: Sun, 8 Sep 2019 23:08:49 +0300 Subject: [PATCH 2/8] added default alignment --- lib/widget.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/widget.dart b/lib/widget.dart index 1e4c046..4486e01 100644 --- a/lib/widget.dart +++ b/lib/widget.dart @@ -384,7 +384,7 @@ class StickyListItem extends Stack { }) : super( key: key, children: [content, header], - alignment: alignment, + alignment: alignment ?? AlignmentDirectional.topStart, overflow: Overflow.clip, ); From e16add0ecd9f24f5d6bc995e8cfcac8c858c5e12 Mon Sep 17 00:00:00 2001 From: Denis Beketsky Date: Sun, 8 Sep 2019 23:22:28 +0300 Subject: [PATCH 3/8] update docs --- README.md | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4def91b..201b4ff 100644 --- a/README.md +++ b/README.md @@ -330,8 +330,7 @@ Luckily you can extend and override base `InfiniteListItem` class class SomeCustomListItem extends InfiniteListItem { /// Header alignment /// - /// Currently it supports top left - /// and right alignment + /// Supports all sides alignment, see [HeaderAlignment] for more info /// /// By default [HeaderAlignment.topLeft] final HeaderAlignment headerAlignment; @@ -389,7 +388,7 @@ class SomeCustomListItem extends InfiniteListItem { } ``` -#### Need more override?.. Ok (not tested) +#### Need more override?.. **If you get any problems with this type of override, please create an issue** @@ -404,6 +403,55 @@ since it subscribes to scroll event and calculates position against `Viewport` coordinates (see `StickyListItemRenderObject` class for more information) +For example + +```dart +Widget build(BuildContext context) { + return SingleChildScrollView( + child: Column( + children: [ + Container( + height: height, + color: Colors.lightBlueAccent, + child: Placeholder(), + ), + StickyListItem( + header: Container( + height: 30, + width: double.infinity, + color: Colors.orange, + child: Center( + child: Text('Sticky Header') + ), + ), + content: Container( + height: height, + color: Colors.blueAccent, + child: Placeholder(), + ), + itemIndex: 'single-child-index', + ), + Container( + height: height, + color: Colors.cyan, + child: Placeholder(), + ), + ], + ), + ); +} +``` + +This code will render single child scroll +with 3 widgets. Middle one - item with sticky header. + +**Demo** + + + +For more complex example please take a look at "Single Example" page +in [Example project](https://github.com/TatsuUkraine/flutter_sticky_infinite_list_example) + ## Changelog Please see the [Changelog](https://github.com/TatsuUkraine/flutter_sticky_infinite_list/blob/master/CHANGELOG.md) page to know what's recently changed. From 9da271504966e84314165e8d8985e425f1fbdb8d Mon Sep 17 00:00:00 2001 From: Denis Beketsky Date: Sun, 8 Sep 2019 23:24:15 +0300 Subject: [PATCH 4/8] fixed different types of viewport usage --- lib/render.dart | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/render.dart b/lib/render.dart index b7ab0f0..59dac98 100644 --- a/lib/render.dart +++ b/lib/render.dart @@ -75,7 +75,7 @@ class StickyListItemRenderObject extends RenderStack { RenderBox get _headerBox => lastChild; RenderBox get _contentBox => firstChild; - RenderViewport get _viewport => RenderAbstractViewport.of(this); + RenderAbstractViewport get _viewport => RenderAbstractViewport.of(this); @override void attach(PipelineOwner owner) { @@ -175,19 +175,31 @@ class StickyListItemRenderObject extends RenderStack { } double get _scrollableSize { - final viewportSize = _scrollDirectionVertical - ? _viewport.size.height - : _viewport.size.width; + double viewportSize; + + if (_viewport is RenderBox) { + final viewportBox = _viewport as RenderBox; + viewportSize = _scrollDirectionVertical + ? viewportBox.size.height + : viewportBox.size.width; + } + + assert(viewportSize != null, 'Can\'t define view port size'); + + double anchor = 0; + if (_viewport is RenderViewport) { + anchor = (_viewport as RenderViewport).anchor; + } if (_alignmentStart) { - return -viewportSize * _viewport.anchor; + return -viewportSize * anchor; } - return viewportSize - viewportSize * _viewport.anchor; + return viewportSize - viewportSize * anchor; } double get _stuckOffset { - return _viewport.getOffsetToReveal(this, 0).offset - _viewport.offset.pixels - _scrollableSize; + return _viewport.getOffsetToReveal(this, 0).offset - _scrollable.position.pixels - _scrollableSize; } double _getContentDirectionSize() { From 598d7c1eadbb5cd8a547e629283f2ff8893e3ae0 Mon Sep 17 00:00:00 2001 From: Denis Beketsky Date: Sun, 8 Sep 2019 23:39:59 +0300 Subject: [PATCH 5/8] bump version, added version changelog --- CHANGELOG.md | 11 +++++++++++ pubspec.yaml | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7fe3c6..7b3f7c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## [1.2.3] - 2019-09-08 + +**Bug fixes** + +- fixed horizontal scroll usage without controller + [#13](https://github.com/TatsuUkraine/flutter_sticky_infinite_list/issues/13) +- fixed `SingleChildScrollView` viewport usage + +**Updates** +- added examples to `README.md` + ## [1.2.2] - 2019-06-22 **Bug fixes** diff --git a/pubspec.yaml b/pubspec.yaml index e564cbd..78f2bfb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ description: >- Can be customized or with config options or with override. -version: 1.2.2 +version: 1.2.3 author: TatsuUkraine homepage: https://github.com/TatsuUkraine/flutter_sticky_infinite_list repository: https://github.com/TatsuUkraine/flutter_sticky_infinite_list From b0b5bc77a2a9e9000f21367eb0db12f09d4a493e Mon Sep 17 00:00:00 2001 From: Denis Beketsky Date: Mon, 9 Sep 2019 00:04:08 +0300 Subject: [PATCH 6/8] some code optimization --- lib/render.dart | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/render.dart b/lib/render.dart index b986a89..a639a66 100644 --- a/lib/render.dart +++ b/lib/render.dart @@ -175,10 +175,13 @@ class StickyListItemRenderObject extends RenderStack { } double get _scrollableSize { + final viewportContainer = _viewport; + double viewportSize; - if (_viewport is RenderBox) { - final viewportBox = _viewport as RenderBox; + if (viewportContainer is RenderBox) { + final RenderBox viewportBox = viewportContainer as RenderBox; + viewportSize = _scrollDirectionVertical ? viewportBox.size.height : viewportBox.size.width; @@ -187,8 +190,9 @@ class StickyListItemRenderObject extends RenderStack { assert(viewportSize != null, 'Can\'t define view port size'); double anchor = 0; - if (_viewport is RenderViewport) { - anchor = (_viewport as RenderViewport).anchor; + + if (viewportContainer is RenderViewport) { + anchor = viewportContainer.anchor; } if (_alignmentStart) { From f37e3335253fa6694d1b6f65c43e02646cc43fcc Mon Sep 17 00:00:00 2001 From: Denis Beketsky Date: Mon, 9 Sep 2019 00:21:49 +0300 Subject: [PATCH 7/8] update readme Known issues section --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 201b4ff..2c6d83d 100644 --- a/README.md +++ b/README.md @@ -465,5 +465,8 @@ Pull request are also welcome. ## Known issues -Currently this package can't work with reverse lists. I hope I will -get enough time to implement this feature soon) +Currently this package can't work with reverse scroll. For some reason +flutter calculates coordinate for negative list items in a +different way in reverse mode, comparing to regular scroll direction. + +But there is an workaround can be used, described in [Reverse infinite scroll] From 29f72aebea158337dcc2323cd9ed63b8bea49bdf Mon Sep 17 00:00:00 2001 From: Denis Beketsky Date: Mon, 9 Sep 2019 00:23:07 +0300 Subject: [PATCH 8/8] update readme Known issues section --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2c6d83d..060233c 100644 --- a/README.md +++ b/README.md @@ -469,4 +469,5 @@ Currently this package can't work with reverse scroll. For some reason flutter calculates coordinate for negative list items in a different way in reverse mode, comparing to regular scroll direction. -But there is an workaround can be used, described in [Reverse infinite scroll] +But there is an workaround can be used, described +in [Reverse infinite scroll](#reverse-infinite-scroll)