Add ScrollMetrics.extentTotal for completeness (#126607)
When implementing scrollbars, I found that it would be useful and idiomatic to be able to do `m.extentInside / m.extentTotal` to get the scrollbar thumb size.
This commit is contained in:
@@ -115,11 +115,12 @@ mixin ScrollMetrics {
|
||||
/// This is the content above the content described by [extentInside].
|
||||
double get extentBefore => math.max(pixels - minScrollExtent, 0.0);
|
||||
|
||||
/// The quantity of content conceptually "inside" the viewport in the scrollable.
|
||||
/// The quantity of content conceptually "inside" the viewport in the
|
||||
/// scrollable (including empty space if the total amount of content is less
|
||||
/// than the [viewportDimension]).
|
||||
///
|
||||
/// The value is typically the height of the viewport when [outOfRange] is false.
|
||||
/// It could be less if there is less content visible than the size of the
|
||||
/// viewport, such as when overscrolling.
|
||||
/// The value is typically the extent of the viewport ([viewportDimension])
|
||||
/// when [outOfRange] is false. It can be less when overscrolling.
|
||||
///
|
||||
/// The value is always non-negative, and less than or equal to [viewportDimension].
|
||||
double get extentInside {
|
||||
@@ -135,6 +136,12 @@ mixin ScrollMetrics {
|
||||
/// This is the content below the content described by [extentInside].
|
||||
double get extentAfter => math.max(maxScrollExtent - pixels, 0.0);
|
||||
|
||||
/// The total quantity of content available.
|
||||
///
|
||||
/// This is the sum of [extentBefore], [extentInside], and [extentAfter], modulo
|
||||
/// any rounding errors.
|
||||
double get extentTotal => maxScrollExtent - minScrollExtent + viewportDimension;
|
||||
|
||||
/// The [FlutterView.devicePixelRatio] of the view that the [Scrollable]
|
||||
/// associated with this metrics object is drawn into.
|
||||
double get devicePixelRatio;
|
||||
|
||||
@@ -31,6 +31,7 @@ void main() {
|
||||
expect(event.metrics.extentBefore, 0.0);
|
||||
expect(event.metrics.extentInside, 600.0);
|
||||
expect(event.metrics.extentAfter, 400.0);
|
||||
expect(event.metrics.extentTotal, 1000.0);
|
||||
|
||||
events.clear();
|
||||
final TestGesture gesture = await tester.startGesture(const Offset(100.0, 100.0));
|
||||
@@ -53,6 +54,7 @@ void main() {
|
||||
expect(event.metrics.extentBefore, 10.0);
|
||||
expect(event.metrics.extentInside, 590.0);
|
||||
expect(event.metrics.extentAfter, 0.0);
|
||||
expect(event.metrics.extentTotal, 600.0);
|
||||
|
||||
events.clear();
|
||||
// The content dimensions does not change.
|
||||
|
||||
Reference in New Issue
Block a user