expandable_page_view icon indicating copy to clipboard operation
expandable_page_view copied to clipboard

viewportFraction bug. Zero height error when changing the length of children.

Open adimshev opened this issue 1 year ago • 2 comments

https://github.com/Limbou/expandable_page_view/assets/33316685/ab1a6880-38e4-447a-8831-11803fb83743

code from video: https://github.com/adimshev/expandable_page_view_bug_demo

Tested for web and iOS The error is reproduced only when viewportFaction < 1

Flutter 3.13.6 • channel stable • https://github.com/flutter/flutter.git Framework • revision ead455963c (2 days ago) • 2023-09-26 18:28:17 -0700 Engine • revision a794cf2681 Tools • Dart 3.1.3 • DevTools 2.25.0

adimshev avatar Sep 28 '23 13:09 adimshev

Hi ! I have the same problem, using viewPortFaction < 1. Did anyone found a solution ?

Velliane avatar Nov 21 '23 16:11 Velliane

@Velliane @adimshev
Maybe try the code below; it worked for me:

void _reinitializeSizes() {
    final currentPageSize = _sizes[_currentPage];

    /// use with [viewportFraction] < 1
    var prePage = _currentPage - 1;
    double prePageSize = 0;
    if (prePage >= 0) prePageSize = _sizes[prePage];

    var nextPage = _currentPage + 1;
    double nextPageSize = 0;
    if (nextPage < _sizes.length) nextPageSize = _sizes[nextPage];
    ///
    _sizes = _prepareSizes();
    if (_currentPage >= _sizes.length) {
      final differenceFromPreviousToCurrent = _previousPage - _currentPage;
      _currentPage = _sizes.length - 1;
      widget.onPageChanged?.call(_currentPage);

      _previousPage = (_currentPage + differenceFromPreviousToCurrent)
          .clamp(0, _sizes.length - 1);
    }

    _previousPage = _previousPage.clamp(0, _sizes.length - 1);
    /// use with [viewportFraction] < 1
    if (prePage >= 0) _sizes[prePage] = prePageSize;
    if (nextPage < _sizes.length) _sizes[nextPage] = nextPageSize;
    ///
    _sizes[_currentPage] = currentPageSize;
  }

ditavo98 avatar Mar 27 '24 07:03 ditavo98