@@ -384,14 +384,30 @@ abstract class FixedHeightScrollable extends Scrollable {
384
384
});
385
385
}
386
386
387
+ double get _leadingPadding {
388
+ if (scrollDirection == ScrollDirection .vertical)
389
+ return padding.top;
390
+ return padding.left;
391
+ }
392
+
393
+ double get _trailingPadding {
394
+ if (scrollDirection == ScrollDirection .vertical)
395
+ return padding.bottom;
396
+ return padding.right;
397
+ }
398
+
399
+ EdgeDims get _crossAxisPadding {
400
+ if (padding == null )
401
+ return null ;
402
+ if (scrollDirection == ScrollDirection .vertical)
403
+ return new EdgeDims .only (left: padding.left, right: padding.right);
404
+ return new EdgeDims .only (top: padding.top, bottom: padding.bottom);
405
+ }
406
+
387
407
void _updateContentsExtent () {
388
408
double contentsExtent = itemExtent * itemCount;
389
- if (padding != null ) {
390
- if (scrollDirection == ScrollDirection .vertical)
391
- contentsExtent += padding.top + padding.bottom;
392
- else
393
- contentsExtent += padding.left + padding.right;
394
- }
409
+ if (padding != null )
410
+ contentsExtent += _leadingPadding + _trailingPadding;
395
411
scrollBehavior.contentsSize = contentsExtent;
396
412
}
397
413
@@ -413,25 +429,29 @@ abstract class FixedHeightScrollable extends Scrollable {
413
429
_updateScrollOffset ();
414
430
}
415
431
432
+ double paddedScrollOffset = scrollOffset;
433
+ if (padding != null )
434
+ paddedScrollOffset -= _leadingPadding;
435
+
416
436
int itemShowIndex = 0 ;
417
437
int itemShowCount = 0 ;
418
438
Offset viewportOffset = Offset .zero;
419
439
if (_containerExtent != null && _containerExtent > 0.0 ) {
420
- if (scrollOffset < 0.0 ) {
421
- double visibleHeight = _containerExtent + scrollOffset ;
440
+ if (paddedScrollOffset < 0.0 ) {
441
+ double visibleHeight = _containerExtent + paddedScrollOffset ;
422
442
itemShowCount = (visibleHeight / itemExtent).round () + 1 ;
423
- viewportOffset = _toOffset (scrollOffset );
443
+ viewportOffset = _toOffset (paddedScrollOffset );
424
444
} else {
425
445
itemShowCount = (_containerExtent / itemExtent).ceil ();
426
- double alignmentDelta = - scrollOffset % itemExtent;
446
+ double alignmentDelta = - paddedScrollOffset % itemExtent;
427
447
double drawStart;
428
448
if (alignmentDelta != 0.0 ) {
429
449
alignmentDelta -= itemExtent;
430
450
itemShowCount += 1 ;
431
- drawStart = scrollOffset + alignmentDelta;
451
+ drawStart = paddedScrollOffset + alignmentDelta;
432
452
viewportOffset = _toOffset (- alignmentDelta);
433
453
} else {
434
- drawStart = scrollOffset ;
454
+ drawStart = paddedScrollOffset ;
435
455
}
436
456
itemShowIndex = math.max (0 , (drawStart / itemExtent).floor ());
437
457
}
@@ -453,7 +473,7 @@ abstract class FixedHeightScrollable extends Scrollable {
453
473
scrollDirection: scrollDirection,
454
474
scrollOffset: viewportOffset,
455
475
child: new Container (
456
- padding: padding ,
476
+ padding: _crossAxisPadding ,
457
477
child: new Block (items, direction: blockDirection)
458
478
)
459
479
)
0 commit comments