From 95c6880ff787c18a3cef7fe6a7febd2a4dbb845a Mon Sep 17 00:00:00 2001 From: fujidaiti Date: Sat, 21 Sep 2024 12:57:21 +0900 Subject: [PATCH 01/22] Redefine SheetMetrics as a mixin --- lib/src/foundation/foundation.dart | 7 +- lib/src/foundation/sheet_extent.dart | 103 +++++++++++++++-------- migrations/migration-guide-0.10.x.md | 8 +- test/foundation/physics_test.dart | 2 +- test/foundation/sheet_activity_test.dart | 12 +-- 5 files changed, 87 insertions(+), 45 deletions(-) diff --git a/lib/src/foundation/foundation.dart b/lib/src/foundation/foundation.dart index d88802b..8228936 100644 --- a/lib/src/foundation/foundation.dart +++ b/lib/src/foundation/foundation.dart @@ -24,7 +24,12 @@ export 'sheet_drag.dart' SheetDragStartDetails, SheetDragUpdateDetails; export 'sheet_extent.dart' - show Extent, FixedExtent, ProportionalExtent, SheetMetrics; + show + Extent, + FixedExtent, + ProportionalExtent, + SheetMetrics, + SheetMetricsSnapshot; export 'sheet_notification.dart' show SheetDragCancelNotification, diff --git a/lib/src/foundation/sheet_extent.dart b/lib/src/foundation/sheet_extent.dart index 5ed7d3a..f8fc76d 100644 --- a/lib/src/foundation/sheet_extent.dart +++ b/lib/src/foundation/sheet_extent.dart @@ -210,7 +210,7 @@ abstract class SheetExtent extends ChangeNotifier Size? viewportSize, EdgeInsets? viewportInsets, }) { - _metrics = SheetMetrics( + _metrics = SheetMetricsSnapshot( pixels: pixels ?? metrics.maybePixels, minExtent: minExtent ?? metrics.maybeMinExtent, maxExtent: maxExtent ?? metrics.maybeMaxExtent, @@ -555,26 +555,10 @@ abstract class SheetExtent extends ChangeNotifier } } -/// An immutable snapshot of the state of a sheet. -class SheetMetrics { - /// Creates an immutable snapshot of the state of a sheet. - const SheetMetrics({ - required double? pixels, - required Extent? minExtent, - required Extent? maxExtent, - required Size? contentSize, - required Size? viewportSize, - required EdgeInsets? viewportInsets, - this.devicePixelRatio = 1.0, - }) : maybePixels = pixels, - maybeMinExtent = minExtent, - maybeMaxExtent = maxExtent, - maybeContentSize = contentSize, - maybeViewportSize = viewportSize, - maybeViewportInsets = viewportInsets; - +/// The metrics of a sheet. +mixin SheetMetrics { /// An empty metrics object with all values set to null. - static const empty = SheetMetrics( + static const SheetMetrics empty = SheetMetricsSnapshot( pixels: null, minExtent: null, maxExtent: null, @@ -583,17 +567,28 @@ class SheetMetrics { viewportInsets: null, ); - final double? maybePixels; - final Extent? maybeMinExtent; - final Extent? maybeMaxExtent; - final Size? maybeContentSize; - final Size? maybeViewportSize; - final EdgeInsets? maybeViewportInsets; + double? get maybePixels; + Extent? get maybeMinExtent; + Extent? get maybeMaxExtent; + Size? get maybeContentSize; + Size? get maybeViewportSize; + EdgeInsets? get maybeViewportInsets; /// The [FlutterView.devicePixelRatio] of the view that the sheet - /// associated with this metrics object is drawn into. + /// associated with this metrics is drawn into. // TODO: Move this to SheetContext. - final double devicePixelRatio; + double get devicePixelRatio; + + /// Creates a copy of the metrics with the given fields replaced. + SheetMetrics copyWith({ + double? pixels, + Extent? minExtent, + Extent? maxExtent, + Size? contentSize, + Size? viewportSize, + EdgeInsets? viewportInsets, + double? devicePixelRatio, + }); double? get maybeMinPixels => switch ((maybeMinExtent, maybeContentSize)) { (final minExtent?, final contentSize?) => @@ -698,9 +693,9 @@ class SheetMetrics { assert(() { if (value == null) { throw FlutterError( - 'SheetMetrics.$name cannot be accessed before the value is set. ' - 'Consider using the corresponding SheetMetrics.maybe* getter ' - 'to handle the case when the value is null. SheetMetrics.hasPixels ' + '$runtimeType.$name cannot be accessed before the value is set. ' + 'Consider using the corresponding $runtimeType.maybe* getter ' + 'to handle the case when the value is null. $runtimeType.hasPixels ' 'is also useful to check if all the metrics values are set ' 'before accessing them.', ); @@ -709,9 +704,49 @@ class SheetMetrics { }()); return true; } +} - /// Creates a copy of this object with the given fields replaced. - SheetMetrics copyWith({ +/// An immutable snapshot of the state of a sheet. +class SheetMetricsSnapshot with SheetMetrics { + /// Creates an immutable snapshot of the state of a sheet. + const SheetMetricsSnapshot({ + required double? pixels, + required Extent? minExtent, + required Extent? maxExtent, + required Size? contentSize, + required Size? viewportSize, + required EdgeInsets? viewportInsets, + this.devicePixelRatio = 1.0, + }) : maybePixels = pixels, + maybeMinExtent = minExtent, + maybeMaxExtent = maxExtent, + maybeContentSize = contentSize, + maybeViewportSize = viewportSize, + maybeViewportInsets = viewportInsets; + + @override + final double? maybePixels; + + @override + final Extent? maybeMinExtent; + + @override + final Extent? maybeMaxExtent; + + @override + final Size? maybeContentSize; + + @override + final Size? maybeViewportSize; + + @override + final EdgeInsets? maybeViewportInsets; + + @override + final double devicePixelRatio; + + @override + SheetMetricsSnapshot copyWith({ double? pixels, Extent? minExtent, Extent? maxExtent, @@ -720,7 +755,7 @@ class SheetMetrics { EdgeInsets? viewportInsets, double? devicePixelRatio, }) { - return SheetMetrics( + return SheetMetricsSnapshot( pixels: pixels ?? maybePixels, minExtent: minExtent ?? maybeMinExtent, maxExtent: maxExtent ?? maybeMaxExtent, diff --git a/migrations/migration-guide-0.10.x.md b/migrations/migration-guide-0.10.x.md index 68ffd40..787d998 100644 --- a/migrations/migration-guide-0.10.x.md +++ b/migrations/migration-guide-0.10.x.md @@ -4,12 +4,14 @@ The changes in v0.10.0 are summarized as follows. Breaking changes are marked wi ## Changes in `SheetMetrics` :boom: -The `double? minPixels` and `double? maxPixels` parameters in the constructor and `copyWith` method have been replaced with `Extent? minExtent` and `Extent? maxExtent`, respectively. However, the `minPixels` and `maxPixels` getters are still available in this version. +- The `double? minPixels` and `double? maxPixels` parameters in the `copyWith` method have been replaced with `Extent? minExtent` and `Extent? maxExtent`, respectively. The `minPixels` and `maxPixels` getters are still available in this version. + +- `SheetMetrics` is now a mixin and can no longer be instantiated directly. Use the `SheetMetricsSnapshot` class for this purpose. ## Change in `SnappingSheetBehavior` :boom: The `findSnapPixels` method has been removed. Use `findSnapExtent` instead. -## Change in `SheetPhysics` :boom: +## Changes in `SheetPhysics` :boom: -The `createSettlingSimulation` method has been removed in favor of the `findSettledExtent` method. As a result, `InterpolationSimulation` has also been removed since it is no longer used and is not a core feature of the package. \ No newline at end of file +The `createSettlingSimulation` method has been removed in favor of the `findSettledExtent` method. As a result, `InterpolationSimulation` has also been removed since it is no longer used internally and is not a core feature of the package. diff --git a/test/foundation/physics_test.dart b/test/foundation/physics_test.dart index fa850ee..995043b 100644 --- a/test/foundation/physics_test.dart +++ b/test/foundation/physics_test.dart @@ -14,7 +14,7 @@ class _SheetPhysicsWithDefaultConfiguration extends SheetPhysics } } -const _referenceSheetMetrics = SheetMetrics( +const _referenceSheetMetrics = SheetMetricsSnapshot( minExtent: Extent.pixels(0), maxExtent: Extent.proportional(1), pixels: 600, diff --git a/test/foundation/sheet_activity_test.dart b/test/foundation/sheet_activity_test.dart index f54836e..c829f6c 100644 --- a/test/foundation/sheet_activity_test.dart +++ b/test/foundation/sheet_activity_test.dart @@ -45,7 +45,7 @@ void main() { test('should animate to the destination', () { when(owner.metrics).thenReturn( - const SheetMetrics( + const SheetMetricsSnapshot( pixels: 300, minExtent: Extent.pixels(300), maxExtent: Extent.pixels(700), @@ -84,7 +84,7 @@ void main() { }); test('should absorb viewport changes', () { - var metrics = const SheetMetrics( + var metrics = const SheetMetricsSnapshot( pixels: 300, minExtent: Extent.pixels(300), maxExtent: Extent.proportional(1), @@ -146,7 +146,7 @@ void main() { late MockTicker internalTicker; late TickerCallback? internalOnTickCallback; - const initialMetrics = SheetMetrics( + const initialMetrics = SheetMetricsSnapshot( pixels: 300, minExtent: Extent.proportional(0.5), maxExtent: Extent.proportional(1), @@ -311,7 +311,7 @@ void main() { final activity = IdleSheetActivity()..init(owner); const oldContentSize = Size(400, 900); const oldViewportInsets = EdgeInsets.zero; - metrics = const SheetMetrics( + metrics = const SheetMetricsSnapshot( pixels: 450, minExtent: Extent.proportional(0.5), maxExtent: Extent.proportional(1), @@ -332,7 +332,7 @@ void main() { () { final activity = IdleSheetActivity()..init(owner); const oldContentSize = Size(400, 600); - metrics = const SheetMetrics( + metrics = const SheetMetricsSnapshot( pixels: 300, minExtent: Extent.proportional(0.5), maxExtent: Extent.proportional(1), @@ -355,7 +355,7 @@ void main() { () { final activity = IdleSheetActivity()..init(owner); const oldContentSize = Size(400, 600); - metrics = const SheetMetrics( + metrics = const SheetMetricsSnapshot( pixels: 300, minExtent: Extent.proportional(0.5), maxExtent: Extent.proportional(1), From bb4cb62a6d122bdaa645bc8e56852e949e2aaea0 Mon Sep 17 00:00:00 2001 From: fujidaiti Date: Sat, 21 Sep 2024 17:53:16 +0900 Subject: [PATCH 02/22] Mix-in SheetExtent with SheetMetrics --- lib/src/draggable/draggable_sheet_extent.dart | 4 +- lib/src/foundation/sheet_activity.dart | 53 +- .../foundation/sheet_content_scaffold.dart | 12 +- lib/src/foundation/sheet_controller.dart | 2 +- lib/src/foundation/sheet_extent.dart | 143 +++--- lib/src/foundation/sheet_viewport.dart | 4 +- .../navigation/navigation_sheet_activity.dart | 8 +- .../scrollable/scrollable_sheet_activity.dart | 18 +- .../scrollable/scrollable_sheet_extent.dart | 12 +- test/foundation/sheet_activity_test.dart | 193 ++++---- test/foundation/sheet_viewport_test.dart | 4 +- test/src/stubbing.dart | 144 +++++- test/src/stubbing.mocks.dart | 467 ++++++++++++------ 13 files changed, 693 insertions(+), 371 deletions(-) diff --git a/lib/src/draggable/draggable_sheet_extent.dart b/lib/src/draggable/draggable_sheet_extent.dart index 8c4406d..292e895 100644 --- a/lib/src/draggable/draggable_sheet_extent.dart +++ b/lib/src/draggable/draggable_sheet_extent.dart @@ -24,8 +24,8 @@ class DraggableSheetExtent extends SheetExtent { @override void applyNewContentSize(Size contentSize) { super.applyNewContentSize(contentSize); - if (metrics.maybePixels == null) { - setPixels(initialExtent.resolve(metrics.contentSize)); + if (maybePixels == null) { + setPixels(initialExtent.resolve(contentSize)); } } } diff --git a/lib/src/foundation/sheet_activity.dart b/lib/src/foundation/sheet_activity.dart index f8835d6..22f99b2 100644 --- a/lib/src/foundation/sheet_activity.dart +++ b/lib/src/foundation/sheet_activity.dart @@ -158,8 +158,8 @@ class AnimatedSheetActivity extends SheetActivity @override void init(SheetExtent delegate) { super.init(delegate); - _startPixels = owner.metrics.pixels; - _endPixels = destination.resolve(owner.metrics.contentSize); + _startPixels = owner.pixels; + _endPixels = destination.resolve(owner.contentSize); } @override @@ -198,7 +198,7 @@ class AnimatedSheetActivity extends SheetActivity if (oldViewportInsets != null) { absorbBottomViewportInset(owner, oldViewportInsets); } - final newEndPixels = destination.resolve(owner.metrics.contentSize); + final newEndPixels = destination.resolve(owner.contentSize); if (newEndPixels != _endPixels) { final remainingDuration = duration - (controller.lastElapsedDuration ?? Duration.zero); @@ -252,7 +252,7 @@ class BallisticSheetActivity extends SheetActivity return; } - final oldMetrics = owner.metrics.copyWith( + final oldMetrics = owner.copyWith( contentSize: oldContentSize, viewportSize: oldViewportSize, viewportInsets: oldViewportInsets, @@ -263,13 +263,13 @@ class BallisticSheetActivity extends SheetActivity absorbBottomViewportInset(owner, oldViewportInsets); } - final endPixels = destination.resolve(owner.metrics.contentSize); - if (endPixels == owner.metrics.pixels) { + final endPixels = destination.resolve(owner.contentSize); + if (endPixels == owner.pixels) { return; } const maxSettlingDuration = 150; // milliseconds - final distance = (endPixels - owner.metrics.pixels).abs(); + final distance = (endPixels - owner.pixels).abs(); final velocityNorm = velocity.abs(); final estimatedSettlingDuration = velocityNorm > 0 ? distance / velocityNorm * Duration.millisecondsPerSecond @@ -359,8 +359,8 @@ class SettlingSheetActivity extends SheetActivity { final elapsedFrameTime = (elapsedDuration - _elapsedDuration).inMicroseconds / Duration.microsecondsPerSecond; - final destination = this.destination.resolve(owner.metrics.contentSize); - final pixels = owner.metrics.pixels; + final destination = this.destination.resolve(owner.contentSize); + final pixels = owner.pixels; final newPixels = destination > pixels ? min(destination, pixels + velocity * elapsedFrameTime) : max(destination, pixels - velocity * elapsedFrameTime); @@ -406,8 +406,8 @@ class SettlingSheetActivity extends SheetActivity { if (duration case final duration?) { final remainingSeconds = (duration - _elapsedDuration).inMicroseconds / Duration.microsecondsPerSecond; - final destination = this.destination.resolve(owner.metrics.contentSize); - final pixels = owner.metrics.pixels; + final destination = this.destination.resolve(owner.contentSize); + final pixels = owner.pixels; _velocity = remainingSeconds > 0 ? (destination - pixels).abs() / remainingSeconds : (destination - pixels).abs(); @@ -435,18 +435,18 @@ class IdleSheetActivity extends SheetActivity { return; } - final oldMetrics = owner.metrics.copyWith( + final oldMetrics = owner.copyWith( contentSize: oldContentSize, viewportSize: oldViewportSize, viewportInsets: oldViewportInsets, ); final prevDetent = owner.physics.findSettledExtent(0, oldMetrics); - final newPixels = prevDetent.resolve(owner.metrics.contentSize); + final newPixels = prevDetent.resolve(owner.contentSize); - if (newPixels == owner.metrics.pixels) { + if (newPixels == owner.pixels) { return; } else if (oldViewportInsets != null && - oldViewportInsets.bottom != owner.metrics.viewportInsets.bottom) { + oldViewportInsets.bottom != owner.viewportInsets.bottom) { // TODO: Is it possible to remove this assumption? // We currently assume that when the bottom viewport inset changes, // it is due to the appearance or disappearance of the keyboard, @@ -460,7 +460,7 @@ class IdleSheetActivity extends SheetActivity { const minAnimationDuration = Duration(milliseconds: 150); const meanAnimationVelocity = 300 / 1000; // pixels per millisecond - final distance = (newPixels - owner.metrics.pixels).abs(); + final distance = (newPixels - owner.pixels).abs(); final estimatedDuration = Duration( milliseconds: (distance / meanAnimationVelocity).round(), ); @@ -491,15 +491,13 @@ class DragSheetActivity extends SheetActivity @override Offset computeMinPotentialDeltaConsumption(Offset delta) { - final metrics = owner.metrics; - switch (delta.dy) { case > 0: - final draggableDistance = max(0.0, metrics.maxPixels - metrics.pixels); + final draggableDistance = max(0.0, owner.maxPixels - owner.pixels); return Offset(delta.dx, min(draggableDistance, delta.dy)); case < 0: - final draggableDistance = max(0.0, metrics.pixels - metrics.minPixels); + final draggableDistance = max(0.0, owner.pixels - owner.minPixels); return Offset(delta.dx, max(-1 * draggableDistance, delta.dy)); case _: @@ -510,15 +508,14 @@ class DragSheetActivity extends SheetActivity @override void onDragUpdate(SheetDragUpdateDetails details) { final physicsAppliedDelta = - owner.physics.applyPhysicsToOffset(details.deltaY, owner.metrics); + owner.physics.applyPhysicsToOffset(details.deltaY, owner); if (physicsAppliedDelta != 0) { owner - ..setPixels(owner.metrics.pixels + physicsAppliedDelta) + ..setPixels(owner.pixels + physicsAppliedDelta) ..didDragUpdateMetrics(details); } - final overflow = - owner.physics.computeOverflow(details.deltaY, owner.metrics); + final overflow = owner.physics.computeOverflow(details.deltaY, owner); if (overflow != 0) { owner.didOverflowBy(overflow); } @@ -588,7 +585,7 @@ mixin UserControlledSheetActivityMixin Size? oldViewportSize, EdgeInsets? oldViewportInsets, ) { - assert(owner.metrics.hasDimensions); + assert(owner.hasDimensions); if (oldViewportInsets != null) { absorbBottomViewportInset(owner, oldViewportInsets); } @@ -605,11 +602,11 @@ void absorbBottomViewportInset( SheetExtent activityOwner, EdgeInsets oldViewportInsets, ) { - final newInsets = activityOwner.metrics.viewportInsets; + final newInsets = activityOwner.viewportInsets; final oldInsets = oldViewportInsets; final deltaInsetBottom = newInsets.bottom - oldInsets.bottom; - final newPixels = activityOwner.metrics.pixels - deltaInsetBottom; - if (newPixels != activityOwner.metrics.pixels) { + final newPixels = activityOwner.pixels - deltaInsetBottom; + if (newPixels != activityOwner.pixels) { activityOwner ..setPixels(newPixels) ..didUpdateMetrics(); diff --git a/lib/src/foundation/sheet_content_scaffold.dart b/lib/src/foundation/sheet_content_scaffold.dart index 43c9fef..043ab26 100644 --- a/lib/src/foundation/sheet_content_scaffold.dart +++ b/lib/src/foundation/sheet_content_scaffold.dart @@ -257,11 +257,10 @@ abstract class _RenderBottomBarVisibility extends RenderTransform { void invalidateVisibility() { final size = _bottomBarSize; - if (size != null && _extent.metrics.hasDimensions) { - final metrics = _extent.metrics; - final baseTransition = (metrics.pixels - metrics.viewportSize.height) - .clamp(size.height - metrics.viewportSize.height, 0.0); - final visibility = computeVisibility(metrics, size); + if (size != null && _extent.hasDimensions) { + final baseTransition = (_extent.pixels - _extent.viewportSize.height) + .clamp(size.height - _extent.viewportSize.height, 0.0); + final visibility = computeVisibility(_extent, size); assert(0 <= visibility && visibility <= 1); final invisibleHeight = size.height * (1 - visibility); final transition = baseTransition + invisibleHeight; @@ -605,8 +604,7 @@ class _ConditionalStickyBottomBarVisibilityState } void _didSheetMetricsChanged() { - final isVisible = - _extent!.metrics.hasDimensions && widget.getIsVisible(_extent!.metrics); + final isVisible = _extent!.hasDimensions && widget.getIsVisible(_extent!); if (isVisible) { if (_controller.status != AnimationStatus.forward) { diff --git a/lib/src/foundation/sheet_controller.dart b/lib/src/foundation/sheet_controller.dart index 5b3a1a7..6af6813 100644 --- a/lib/src/foundation/sheet_controller.dart +++ b/lib/src/foundation/sheet_controller.dart @@ -18,7 +18,7 @@ class SheetController extends ChangeNotifier final _immediateListeners = ChangeNotifier(); @override - SheetMetrics get value => _client?.metrics ?? SheetMetrics.empty; + SheetMetrics get value => _client?.snapshot ?? SheetMetrics.empty; SheetStatus? get status => _client?.status; diff --git a/lib/src/foundation/sheet_extent.dart b/lib/src/foundation/sheet_extent.dart index f8fc76d..2930add 100644 --- a/lib/src/foundation/sheet_extent.dart +++ b/lib/src/foundation/sheet_extent.dart @@ -123,6 +123,7 @@ class FixedExtent implements Extent { @internal @optionalTypeArgs abstract class SheetExtent extends ChangeNotifier + with SheetMetrics implements ValueListenable { /// Creates an object that manages the extent of a sheet. SheetExtent({ @@ -134,7 +135,7 @@ abstract class SheetExtent extends ChangeNotifier SheetGestureProxyMixin? gestureTamperer, }) : _physics = physics, _gestureTamperer = gestureTamperer, - _metrics = SheetMetrics.empty.copyWith( + _snapshot = SheetMetrics.empty.copyWith( minExtent: minExtent, maxExtent: maxExtent, ) { @@ -142,29 +143,34 @@ abstract class SheetExtent extends ChangeNotifier } @override - SheetMetrics get value => metrics; + SheetMetrics get value => snapshot; + + @override + double? get maybePixels => snapshot.maybePixels; + + @override + Extent? get maybeMinExtent => snapshot.maybeMinExtent; + + @override + Extent? get maybeMaxExtent => snapshot.maybeMaxExtent; + + @override + Size? get maybeContentSize => snapshot.maybeContentSize; + + @override + Size? get maybeViewportSize => snapshot.maybeViewportSize; + + @override + EdgeInsets? get maybeViewportInsets => snapshot.maybeViewportInsets; + + @override + double get devicePixelRatio => context.devicePixelRatio; SheetStatus get status => activity.status; /// A handle to the owner of this object. final SheetContext context; - /// {@template SheetExtent.minExtent} - /// The minimum extent of the sheet. - /// - /// The sheet may below this extent if the [physics] allows it. - /// {@endtemplate} - // TODO: Remove this in favor of SheetMetrics.minExtent. - Extent get minExtent => _metrics.minExtent; - - /// {@template SheetExtent.maxExtent} - /// The maximum extent of the sheet. - /// - /// The sheet may exceed this extent if the [physics] allows it. - /// {@endtemplate} - // TODO: Remove this in favor of SheetMetrics.maxExtent. - Extent get maxExtent => _metrics.maxExtent; - /// {@template SheetExtent.physics} /// How the sheet extent should respond to user input. /// @@ -195,8 +201,8 @@ abstract class SheetExtent extends ChangeNotifier SheetDragController? currentDrag; /// Snapshot of the current sheet's state. - SheetMetrics get metrics => _metrics; - SheetMetrics _metrics; + SheetMetrics get snapshot => _snapshot; + SheetMetrics _snapshot; /// Updates the metrics with the given values. /// @@ -210,13 +216,13 @@ abstract class SheetExtent extends ChangeNotifier Size? viewportSize, EdgeInsets? viewportInsets, }) { - _metrics = SheetMetricsSnapshot( - pixels: pixels ?? metrics.maybePixels, - minExtent: minExtent ?? metrics.maybeMinExtent, - maxExtent: maxExtent ?? metrics.maybeMaxExtent, - contentSize: contentSize ?? metrics.maybeContentSize, - viewportSize: viewportSize ?? metrics.maybeViewportSize, - viewportInsets: viewportInsets ?? metrics.maybeViewportInsets, + _snapshot = SheetMetricsSnapshot( + pixels: pixels ?? maybePixels, + minExtent: minExtent ?? maybeMinExtent, + maxExtent: maxExtent ?? maybeMaxExtent, + contentSize: contentSize ?? maybeContentSize, + viewportSize: viewportSize ?? maybeViewportSize, + viewportInsets: viewportInsets ?? maybeViewportInsets, // Ensure that the devicePixelRatio is always up-to-date. devicePixelRatio: context.devicePixelRatio, ); @@ -241,18 +247,19 @@ abstract class SheetExtent extends ChangeNotifier } else { goIdle(); } - if (other.metrics.maybePixels case final pixels?) { + if (other.maybePixels case final pixels?) { correctPixels(pixels); } applyNewBoundaryConstraints(other.minExtent, other.maxExtent); applyNewViewportDimensions( - other.metrics.viewportSize, - other.metrics.viewportInsets, + other.viewportSize, + other.viewportInsets, ); - applyNewContentSize(other.metrics.contentSize); + applyNewContentSize(other.contentSize); } @mustCallSuper + // TODO: Rename to updateGestureProxy void updateGestureTamperer(SheetGestureProxyMixin? gestureTamperer) { if (_gestureTamperer != gestureTamperer) { _gestureTamperer = gestureTamperer; @@ -267,8 +274,8 @@ abstract class SheetExtent extends ChangeNotifier @mustCallSuper void applyNewContentSize(Size contentSize) { - if (metrics.maybeContentSize != contentSize) { - _oldContentSize = metrics.maybeContentSize; + if (maybeContentSize != contentSize) { + _oldContentSize = maybeContentSize; _updateMetrics(contentSize: contentSize); activity.didChangeContentSize(_oldContentSize); } @@ -276,10 +283,9 @@ abstract class SheetExtent extends ChangeNotifier @mustCallSuper void applyNewViewportDimensions(Size size, EdgeInsets insets) { - if (metrics.maybeViewportSize != size || - metrics.maybeViewportInsets != insets) { - _oldViewportSize = metrics.maybeViewportSize; - _oldViewportInsets = metrics.maybeViewportInsets; + if (maybeViewportSize != size || maybeViewportInsets != insets) { + _oldViewportSize = maybeViewportSize; + _oldViewportInsets = maybeViewportInsets; _updateMetrics(viewportSize: size, viewportInsets: insets); activity.didChangeViewportDimensions( _oldViewportSize, @@ -291,8 +297,8 @@ abstract class SheetExtent extends ChangeNotifier @mustCallSuper void applyNewBoundaryConstraints(Extent minExtent, Extent maxExtent) { if (minExtent != this.minExtent || maxExtent != this.maxExtent) { - final oldMinExtent = metrics.maybeMinExtent; - final oldMaxExtent = metrics.maybeMaxExtent; + final oldMinExtent = maybeMinExtent; + final oldMaxExtent = maybeMaxExtent; _updateMetrics(minExtent: minExtent, maxExtent: maxExtent); activity.didChangeBoundaryConstraints(oldMinExtent, oldMaxExtent); } @@ -361,7 +367,7 @@ abstract class SheetExtent extends ChangeNotifier ), ); assert( - metrics.hasDimensions, + hasDimensions, _debugMessage( 'All the dimension values must be finalized ' 'at the time onDimensionsFinalized() is called.', @@ -397,8 +403,8 @@ abstract class SheetExtent extends ChangeNotifier } void goBallistic(double velocity) { - assert(metrics.hasDimensions); - final simulation = physics.createBallisticSimulation(velocity, metrics); + assert(hasDimensions); + final simulation = physics.createBallisticSimulation(velocity, snapshot); if (simulation != null) { goBallisticWith(simulation); } else { @@ -460,7 +466,7 @@ abstract class SheetExtent extends ChangeNotifier } void setPixels(double pixels) { - final oldPixels = metrics.maybePixels; + final oldPixels = maybePixels; correctPixels(pixels); if (oldPixels != pixels) { notifyListeners(); @@ -468,7 +474,7 @@ abstract class SheetExtent extends ChangeNotifier } void correctPixels(double pixels) { - if (metrics.maybePixels != pixels) { + if (maybePixels != pixels) { _updateMetrics(pixels: pixels); } } @@ -483,8 +489,8 @@ abstract class SheetExtent extends ChangeNotifier Curve curve = Curves.easeInOut, Duration duration = const Duration(milliseconds: 300), }) { - assert(metrics.hasDimensions); - if (metrics.pixels == newExtent.resolve(metrics.contentSize)) { + assert(hasDimensions); + if (pixels == newExtent.resolve(contentSize)) { return Future.value(); } else { final activity = AnimatedSheetActivity( @@ -498,50 +504,71 @@ abstract class SheetExtent extends ChangeNotifier } } + @override + SheetMetrics copyWith({ + double? pixels, + Extent? minExtent, + Extent? maxExtent, + Size? contentSize, + Size? viewportSize, + EdgeInsets? viewportInsets, + double? devicePixelRatio, + }) { + return snapshot.copyWith( + pixels: pixels, + minExtent: minExtent, + maxExtent: maxExtent, + contentSize: contentSize, + viewportSize: viewportSize, + viewportInsets: viewportInsets, + devicePixelRatio: devicePixelRatio, + ); + } + void didUpdateMetrics() { - if (metrics.hasDimensions) { + if (hasDimensions) { SheetUpdateNotification( - metrics: metrics, + metrics: snapshot, status: status, ).dispatch(context.notificationContext); } } void didDragStart(SheetDragStartDetails details) { - assert(metrics.hasDimensions); + assert(hasDimensions); SheetDragStartNotification( - metrics: metrics, + metrics: snapshot, dragDetails: details, ).dispatch(context.notificationContext); } void didDragEnd(SheetDragEndDetails details) { - assert(metrics.hasDimensions); + assert(hasDimensions); SheetDragEndNotification( - metrics: metrics, + metrics: snapshot, dragDetails: details, ).dispatch(context.notificationContext); } void didDragUpdateMetrics(SheetDragUpdateDetails details) { - assert(metrics.hasDimensions); + assert(hasDimensions); SheetDragUpdateNotification( - metrics: metrics, + metrics: snapshot, dragDetails: details, ).dispatch(context.notificationContext); } void didDragCancel() { - assert(metrics.hasDimensions); + assert(hasDimensions); SheetDragCancelNotification( - metrics: metrics, + metrics: snapshot, ).dispatch(context.notificationContext); } void didOverflowBy(double overflow) { - assert(metrics.hasDimensions); + assert(hasDimensions); SheetOverflowNotification( - metrics: metrics, + metrics: snapshot, status: status, overflow: overflow, ).dispatch(context.notificationContext); diff --git a/lib/src/foundation/sheet_viewport.dart b/lib/src/foundation/sheet_viewport.dart index 97c0bfb..e69c261 100644 --- a/lib/src/foundation/sheet_viewport.dart +++ b/lib/src/foundation/sheet_viewport.dart @@ -85,7 +85,7 @@ class RenderSheetViewport extends RenderTransform { ); assert( - _extent.metrics.hasDimensions, + _extent.hasDimensions, 'The sheet extent and the dimensions values ' 'must be finalized during the layout phase.', ); @@ -101,7 +101,7 @@ class RenderSheetViewport extends RenderTransform { } void _invalidateTranslationValue() { - final currentExtent = _extent.metrics.maybePixels; + final currentExtent = _extent.maybePixels; final viewportSize = _lastMeasuredSize; if (currentExtent != null && viewportSize != null) { final dy = viewportSize.height - _insets.bottom - currentExtent; diff --git a/lib/src/navigation/navigation_sheet_activity.dart b/lib/src/navigation/navigation_sheet_activity.dart index 3236f8a..b50f512 100644 --- a/lib/src/navigation/navigation_sheet_activity.dart +++ b/lib/src/navigation/navigation_sheet_activity.dart @@ -49,10 +49,8 @@ class TransitionSheetActivity extends NavigationSheetActivity { void _onAnimationTick() { final fraction = _curvedAnimation.value; - final startPixels = - currentRoute.scopeKey.maybeCurrentExtent?.metrics.maybePixels; - final endPixels = - nextRoute.scopeKey.maybeCurrentExtent?.metrics.maybePixels; + final startPixels = currentRoute.scopeKey.maybeCurrentExtent?.maybePixels; + final endPixels = nextRoute.scopeKey.maybeCurrentExtent?.maybePixels; if (startPixels != null && endPixels != null) { owner.setPixels(lerpDouble(startPixels, endPixels, fraction)!); @@ -105,7 +103,7 @@ class ProxySheetActivity extends NavigationSheetActivity { void _syncMetrics({bool notify = true}) { assert(route.scopeKey.maybeCurrentExtent != null); final localExtent = route.scopeKey.currentExtent; - final localMetrics = localExtent.metrics; + final localMetrics = localExtent.snapshot; owner.applyNewBoundaryConstraints( localExtent.minExtent, localExtent.maxExtent, diff --git a/lib/src/scrollable/scrollable_sheet_activity.dart b/lib/src/scrollable/scrollable_sheet_activity.dart index d4011fb..64b0eb0 100644 --- a/lib/src/scrollable/scrollable_sheet_activity.dart +++ b/lib/src/scrollable/scrollable_sheet_activity.dart @@ -50,7 +50,7 @@ abstract class ScrollableSheetActivity } double _applyPhysicsToOffset(double offset) { - return owner.physics.applyPhysicsToOffset(offset, owner.metrics); + return owner.physics.applyPhysicsToOffset(offset, owner.snapshot); } double _applyScrollOffset(double offset) { @@ -58,8 +58,8 @@ abstract class ScrollableSheetActivity if (cmp.isApprox(offset, 0)) return 0; final position = scrollPosition; - final maxPixels = owner.metrics.maxPixels; - final oldPixels = owner.metrics.pixels; + final maxPixels = owner.maxPixels; + final oldPixels = owner.pixels; final oldScrollPixels = position.pixels; final minScrollPixels = position.minScrollExtent; final maxScrollPixels = position.maxScrollExtent; @@ -123,7 +123,7 @@ abstract class ScrollableSheetActivity owner.setPixels(newPixels); - final overflow = owner.physics.computeOverflow(delta, owner.metrics); + final overflow = owner.physics.computeOverflow(delta, owner.snapshot); if (overflow.abs() > 0) { position.didOverscrollBy(overflow); return overflow; @@ -170,7 +170,7 @@ class DragScrollDrivenSheetActivity extends ScrollableSheetActivity @override Offset computeMinPotentialDeltaConsumption(Offset delta) { - final metrics = owner.metrics; + final metrics = owner.snapshot; switch (delta.dy) { case < 0: @@ -195,9 +195,9 @@ class DragScrollDrivenSheetActivity extends ScrollableSheetActivity scrollPosition.userScrollDirection = details.deltaY > 0.0 ? ScrollDirection.forward : ScrollDirection.reverse; - final oldPixels = owner.metrics.pixels; + final oldPixels = owner.pixels; final overflow = _applyScrollOffset(-1 * details.deltaY); - if (owner.metrics.pixels != oldPixels) { + if (owner.pixels != oldPixels) { owner.didDragUpdateMetrics(details); } if (overflow > 0) { @@ -261,7 +261,7 @@ class BallisticScrollDrivenSheetActivity extends ScrollableSheetActivity final delta = controller.value - _oldPixels; _oldPixels = controller.value; final overflow = _applyScrollOffset(delta); - if (owner.metrics.pixels != _oldPixels) { + if (owner.pixels != _oldPixels) { owner.didUpdateMetrics(); } if (cmp.isNotApprox(overflow, 0)) { @@ -277,7 +277,7 @@ class BallisticScrollDrivenSheetActivity extends ScrollableSheetActivity ((cmp.isApprox(scrollExtentBefore, 0) && velocity < 0) || (cmp.isApprox(scrollExtentAfter, 0) && velocity > 0)) && owner.physics - .shouldInterruptBallisticScroll(velocity, owner.metrics); + .shouldInterruptBallisticScroll(velocity, owner.snapshot); if (shouldInterruptBallisticScroll) { _end(); diff --git a/lib/src/scrollable/scrollable_sheet_extent.dart b/lib/src/scrollable/scrollable_sheet_extent.dart index db2403d..67fd785 100644 --- a/lib/src/scrollable/scrollable_sheet_extent.dart +++ b/lib/src/scrollable/scrollable_sheet_extent.dart @@ -84,8 +84,8 @@ class ScrollableSheetExtent extends SheetExtent @override void applyNewContentSize(Size contentSize) { super.applyNewContentSize(contentSize); - if (metrics.maybePixels == null) { - setPixels(initialExtent.resolve(metrics.contentSize)); + if (maybePixels == null) { + setPixels(initialExtent.resolve(contentSize)); } } @@ -187,10 +187,10 @@ class ScrollableSheetExtent extends SheetExtent required double velocity, required SheetContentScrollPosition scrollPosition, }) { - assert(metrics.hasDimensions); + assert(hasDimensions); if (FloatComp.distance(context.devicePixelRatio) .isApprox(scrollPosition.pixels, scrollPosition.minScrollExtent)) { - final simulation = physics.createBallisticSimulation(velocity, metrics); + final simulation = physics.createBallisticSimulation(velocity, snapshot); if (simulation != null) { scrollPosition.goIdle(calledByOwner: true); goBallisticWith(simulation); @@ -199,8 +199,8 @@ class ScrollableSheetExtent extends SheetExtent } final scrolledDistance = scrollPosition.pixels; - final draggedDistance = metrics.pixels - metrics.minPixels; - final draggableDistance = metrics.maxPixels - metrics.minPixels; + final draggedDistance = pixels - minPixels; + final draggableDistance = maxPixels - minPixels; final scrollableDistance = scrollPosition.maxScrollExtent - scrollPosition.minScrollExtent; final scrollPixelsForScrollPhysics = scrolledDistance + draggedDistance; diff --git a/test/foundation/sheet_activity_test.dart b/test/foundation/sheet_activity_test.dart index c829f6c..5edfecd 100644 --- a/test/foundation/sheet_activity_test.dart +++ b/test/foundation/sheet_activity_test.dart @@ -27,13 +27,10 @@ class _TestAnimatedSheetActivity extends AnimatedSheetActivity { void main() { group('AnimatedSheetActivity', () { - late MockSheetExtent owner; late MockAnimationController controller; setUp(() { - owner = MockSheetExtent(); controller = MockAnimationController(); - when( controller.animateTo( any, @@ -44,15 +41,14 @@ void main() { }); test('should animate to the destination', () { - when(owner.metrics).thenReturn( - const SheetMetricsSnapshot( - pixels: 300, - minExtent: Extent.pixels(300), - maxExtent: Extent.pixels(700), - contentSize: Size(400, 700), - viewportSize: Size(400, 900), - viewportInsets: EdgeInsets.zero, - ), + final (ownerMetrics, owner) = createMockSheetExtent( + pixels: 300, + minExtent: const Extent.pixels(300), + maxExtent: const Extent.pixels(700), + contentSize: const Size(400, 700), + viewportSize: const Size(400, 900), + viewportInsets: EdgeInsets.zero, + devicePixelRatio: 1, ); final activity = _TestAnimatedSheetActivity( @@ -72,31 +68,27 @@ void main() { when(controller.value).thenReturn(0.0); activity.onAnimationTick(); - verify(owner.setPixels(300)); + expect(ownerMetrics.pixels, 300); when(controller.value).thenReturn(0.5); activity.onAnimationTick(); - verify(owner.setPixels(500)); + expect(ownerMetrics.pixels, 500); when(controller.value).thenReturn(1.0); activity.onAnimationTick(); - verify(owner.setPixels(700)); + expect(ownerMetrics.pixels, 700); }); test('should absorb viewport changes', () { - var metrics = const SheetMetricsSnapshot( + final (ownerMetrics, owner) = createMockSheetExtent( pixels: 300, - minExtent: Extent.pixels(300), - maxExtent: Extent.proportional(1), - contentSize: Size(400, 900), - viewportSize: Size(400, 900), + minExtent: const Extent.pixels(300), + maxExtent: const Extent.proportional(1), + contentSize: const Size(400, 900), + viewportSize: const Size(400, 900), viewportInsets: EdgeInsets.zero, + devicePixelRatio: 1, ); - when(owner.metrics).thenAnswer((_) => metrics); - when(owner.setPixels(any)).thenAnswer((invocation) { - final pixels = invocation.positionalArguments[0] as double; - metrics = metrics.copyWith(pixels: pixels); - }); final activity = _TestAnimatedSheetActivity( controller: controller, @@ -107,13 +99,13 @@ void main() { when(controller.value).thenReturn(0.0); activity.onAnimationTick(); - expect(metrics.pixels, 300); + expect(ownerMetrics.pixels, 300); when(controller.value).thenReturn(0.25); when(controller.lastElapsedDuration) .thenReturn(const Duration(milliseconds: 75)); activity.onAnimationTick(); - expect(metrics.pixels, 450); + expect(ownerMetrics.pixels, 450); // The following lines simulate a viewport change, in which: // 1. The viewport's bottom inset increases, simulating the @@ -122,17 +114,17 @@ void main() { // increased bottom inset. // This scenario mimics the behavior when opening a keyboard // on a sheet that uses SheetContentScaffold. - final oldViewportInsets = metrics.viewportInsets; - final oldContentSize = metrics.contentSize; - metrics = metrics.copyWith( - viewportInsets: const EdgeInsets.only(bottom: 50), - contentSize: const Size(400, 850), - ); + final oldViewportInsets = ownerMetrics.viewportInsets; + final oldContentSize = ownerMetrics.contentSize; + ownerMetrics + ..maybeViewportInsets = const EdgeInsets.only(bottom: 50) + ..maybeContentSize = const Size(400, 850); + activity.didChangeViewportDimensions(null, oldViewportInsets); activity.didChangeContentSize(oldContentSize); activity.didFinalizeDimensions(oldContentSize, null, oldViewportInsets); - expect(metrics.pixels, 400); - expect(metrics.viewPixels, 450, + expect(ownerMetrics.pixels, 400); + expect(ownerMetrics.viewPixels, 450, reason: 'Visual position should not change when viewport changes.'); verify(owner.settleTo( const Extent.proportional(1), @@ -143,20 +135,20 @@ void main() { group('SettlingSheetActivity', () { late MockSheetExtent owner; + late MutableSheetMetrics ownerMetrics; late MockTicker internalTicker; late TickerCallback? internalOnTickCallback; - const initialMetrics = SheetMetricsSnapshot( - pixels: 300, - minExtent: Extent.proportional(0.5), - maxExtent: Extent.proportional(1), - contentSize: Size(400, 600), - viewportSize: Size(400, 900), - viewportInsets: EdgeInsets.zero, - ); - setUp(() { - owner = MockSheetExtent(); + (ownerMetrics, owner) = createMockSheetExtent( + pixels: 300, + minExtent: const Extent.proportional(0.5), + maxExtent: const Extent.proportional(1), + contentSize: const Size(400, 600), + viewportSize: const Size(400, 900), + viewportInsets: EdgeInsets.zero, + devicePixelRatio: 1, + ); internalTicker = MockTicker(); final tickerProvider = MockTickerProvider(); final context = MockSheetContext(); @@ -206,7 +198,6 @@ void main() { ); expect(() => activity.velocity, isNotInitialized); - when(owner.metrics).thenReturn(initialMetrics); activity.init(owner); expect(activity.velocity, 1000); // (300pixels / 300ms) = 1000 pixels/s }, @@ -221,25 +212,20 @@ void main() { activity.init(owner); verify(internalTicker.start()); - when(owner.metrics).thenReturn(initialMetrics); internalOnTickCallback!(const Duration(milliseconds: 200)); - verify(owner.setPixels(360)); // 300 * 0.2 = 60 pixels in 200ms + expect(ownerMetrics.pixels, 360); // 300 * 0.2 = 60 pixels in 200ms - when(owner.metrics).thenReturn(initialMetrics.copyWith(pixels: 360)); internalOnTickCallback!(const Duration(milliseconds: 400)); - verify(owner.setPixels(420)); // 300 * 0.2 = 60 pixels in 200ms + expect(ownerMetrics.pixels, 420); // 300 * 0.2 = 60 pixels in 200ms - when(owner.metrics).thenReturn(initialMetrics.copyWith(pixels: 420)); internalOnTickCallback!(const Duration(milliseconds: 500)); - verify(owner.setPixels(450)); // 300 * 0.1 = 30 pixels in 100ms + expect(ownerMetrics.pixels, 450); // 300 * 0.1 = 30 pixels in 100ms - when(owner.metrics).thenReturn(initialMetrics.copyWith(pixels: 450)); internalOnTickCallback!(const Duration(milliseconds: 800)); - verify(owner.setPixels(540)); // 300 * 0.3 = 90 pixels in 300ms + expect(ownerMetrics.pixels, 540); // 300 * 0.3 = 90 pixels in 300ms - when(owner.metrics).thenReturn(initialMetrics.copyWith(pixels: 540)); internalOnTickCallback!(const Duration(milliseconds: 1000)); - verify(owner.setPixels(600)); // 300 * 0.2 = 60 pixels in 200ms + expect(ownerMetrics.pixels, 600); // 300 * 0.2 = 60 pixels in 200ms }); test( @@ -250,20 +236,13 @@ void main() { velocity: 300, )..init(owner); - when(owner.metrics).thenReturn(initialMetrics.copyWith(pixels: 540)); + ownerMetrics.maybePixels = 540; internalOnTickCallback!(const Duration(milliseconds: 1000)); verify(owner.goIdle()); }, ); test('Should absorb viewport changes', () { - var metrics = initialMetrics; - when(owner.metrics).thenAnswer((_) => metrics); - when(owner.setPixels(any)).thenAnswer((invocation) { - final pixels = invocation.positionalArguments[0] as double; - metrics = metrics.copyWith(pixels: pixels); - }); - final activity = SettlingSheetActivity.withDuration( const Duration(milliseconds: 300), destination: const Extent.proportional(1), @@ -272,78 +251,69 @@ void main() { expect(activity.velocity, 1000); // (300 pixels / 0.3s) = 1000 pixels/s internalOnTickCallback!(const Duration(milliseconds: 50)); - expect(metrics.pixels, 350); // 1000 * 0.05 = 50 pixels in 50ms + expect(ownerMetrics.pixels, 350); // 1000 * 0.05 = 50 pixels in 50ms + final oldViewportInsets = ownerMetrics.viewportInsets; + final oldContentSize = ownerMetrics.contentSize; // Show the on-screen keyboard. - metrics = metrics.copyWith( - viewportInsets: const EdgeInsets.only(bottom: 30), - ); - final oldViewportInsets = initialMetrics.viewportInsets; - final oldContentSize = initialMetrics.contentSize; + ownerMetrics.maybeViewportInsets = const EdgeInsets.only(bottom: 30); activity.didChangeViewportDimensions(null, oldViewportInsets); activity.didChangeContentSize(oldContentSize); activity.didFinalizeDimensions(oldContentSize, null, oldViewportInsets); - expect(metrics.pixels, 320, + expect(ownerMetrics.pixels, 320, reason: 'Visual position should not change when viewport changes.'); expect(activity.velocity, 1120, // 280 pixels / 0.25s = 1120 pixels/s reason: 'Velocity should be updated when viewport changes.'); internalOnTickCallback!(const Duration(milliseconds: 100)); - expect(metrics.pixels, 376); // 1120 * 0.05 = 56 pixels in 50ms + expect(ownerMetrics.pixels, 376); // 1120 * 0.05 = 56 pixels in 50ms }); }); group('IdleSheetActivity', () { - late MockSheetExtent owner; - late SheetMetrics metrics; - - setUp(() { - owner = MockSheetExtent(); - when(owner.physics).thenReturn(kDefaultSheetPhysics); - when(owner.metrics).thenAnswer((_) => metrics); - when(owner.setPixels(any)).thenAnswer((invocation) { - final pixels = invocation.positionalArguments[0] as double; - metrics = metrics.copyWith(pixels: pixels); - }); - }); - test('should maintain previous extent when keyboard appears', () { + final (ownerMetrics, owner) = createMockSheetExtent( + pixels: 450, + minExtent: const Extent.proportional(0.5), + maxExtent: const Extent.proportional(1), + contentSize: const Size(400, 850), + viewportSize: const Size(400, 900), + viewportInsets: const EdgeInsets.only(bottom: 50), + devicePixelRatio: 1, + physics: kDefaultSheetPhysics, + ); + final activity = IdleSheetActivity()..init(owner); const oldContentSize = Size(400, 900); const oldViewportInsets = EdgeInsets.zero; - metrics = const SheetMetricsSnapshot( - pixels: 450, - minExtent: Extent.proportional(0.5), - maxExtent: Extent.proportional(1), - contentSize: Size(400, 850), - viewportSize: Size(400, 900), - viewportInsets: EdgeInsets.only(bottom: 50), - ); activity ..didChangeContentSize(oldContentSize) ..didChangeViewportDimensions(oldContentSize, oldViewportInsets) ..didFinalizeDimensions(oldContentSize, null, oldViewportInsets); - expect(metrics.pixels, 425); + expect(ownerMetrics.pixels, 425); }); test( 'should maintain previous extent when content size changes, ' 'without animation if gap is small', () { - final activity = IdleSheetActivity()..init(owner); - const oldContentSize = Size(400, 600); - metrics = const SheetMetricsSnapshot( + final (ownerMetrics, owner) = createMockSheetExtent( pixels: 300, - minExtent: Extent.proportional(0.5), - maxExtent: Extent.proportional(1), - contentSize: Size(400, 580), - viewportSize: Size(400, 900), + minExtent: const Extent.proportional(0.5), + maxExtent: const Extent.proportional(1), + contentSize: const Size(400, 580), + viewportSize: const Size(400, 900), viewportInsets: EdgeInsets.zero, + devicePixelRatio: 1, + physics: kDefaultSheetPhysics, ); + + final activity = IdleSheetActivity()..init(owner); + const oldContentSize = Size(400, 600); activity ..didChangeContentSize(oldContentSize) ..didFinalizeDimensions(oldContentSize, null, null); - expect(metrics.pixels, 290); + expect(ownerMetrics.pixels, 290); // Still in the idle activity. verifyNever(owner.beginActivity(any)); }, @@ -353,20 +323,23 @@ void main() { 'should maintain previous extent when content size changes, ' 'with animation if gap is large', () { - final activity = IdleSheetActivity()..init(owner); - const oldContentSize = Size(400, 600); - metrics = const SheetMetricsSnapshot( + final (ownerMetrics, owner) = createMockSheetExtent( pixels: 300, - minExtent: Extent.proportional(0.5), - maxExtent: Extent.proportional(1), - contentSize: Size(400, 500), - viewportSize: Size(400, 900), + minExtent: const Extent.proportional(0.5), + maxExtent: const Extent.proportional(1), + contentSize: const Size(400, 500), + viewportSize: const Size(400, 900), viewportInsets: EdgeInsets.zero, + devicePixelRatio: 1, + physics: kDefaultSheetPhysics, ); + + final activity = IdleSheetActivity()..init(owner); + const oldContentSize = Size(400, 600); activity ..didChangeContentSize(oldContentSize) ..didFinalizeDimensions(oldContentSize, null, null); - expect(metrics.pixels, 300); + expect(ownerMetrics.pixels, 300); verify( owner.animateTo( const Extent.proportional(0.5), diff --git a/test/foundation/sheet_viewport_test.dart b/test/foundation/sheet_viewport_test.dart index a8cd1cd..abfae01 100644 --- a/test/foundation/sheet_viewport_test.dart +++ b/test/foundation/sheet_viewport_test.dart @@ -51,8 +51,8 @@ class _FakeSheetExtent extends SheetExtent { @override void applyNewContentSize(Size contentSize) { super.applyNewContentSize(contentSize); - if (metrics.maybePixels == null) { - setPixels(maxExtent.resolve(metrics.contentSize)); + if (maybePixels == null) { + setPixels(maxExtent.resolve(contentSize)); } } diff --git a/test/src/stubbing.dart b/test/src/stubbing.dart index 61e3b6e..835dab9 100644 --- a/test/src/stubbing.dart +++ b/test/src/stubbing.dart @@ -1,7 +1,8 @@ -import 'package:flutter/animation.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter/widgets.dart'; import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; +import 'package:smooth_sheets/src/foundation/foundation.dart'; import 'package:smooth_sheets/src/foundation/sheet_context.dart'; import 'package:smooth_sheets/src/foundation/sheet_extent.dart'; @@ -13,4 +14,145 @@ import 'package:smooth_sheets/src/foundation/sheet_extent.dart'; MockSpec(), MockSpec() ]) +import 'stubbing.mocks.dart'; + export 'stubbing.mocks.dart'; + +class MutableSheetMetrics with SheetMetrics { + MutableSheetMetrics({ + required this.maybePixels, + required this.maybeMinExtent, + required this.maybeMaxExtent, + required this.maybeContentSize, + required this.maybeViewportSize, + required this.maybeViewportInsets, + required this.devicePixelRatio, + }); + + @override + double devicePixelRatio; + + @override + Extent? maybeMaxExtent; + + @override + Extent? maybeMinExtent; + + @override + double? maybePixels; + + @override + Size? maybeContentSize; + + @override + Size? maybeViewportSize; + + @override + EdgeInsets? maybeViewportInsets; + + @override + SheetMetrics copyWith({ + double? pixels, + Extent? minExtent, + Extent? maxExtent, + Size? contentSize, + Size? viewportSize, + EdgeInsets? viewportInsets, + double? devicePixelRatio, + }) { + return SheetMetricsSnapshot( + pixels: pixels ?? maybePixels, + minExtent: minExtent ?? maybeMinExtent, + maxExtent: maxExtent ?? maybeMaxExtent, + contentSize: contentSize ?? maybeContentSize, + viewportSize: viewportSize ?? maybeViewportSize, + viewportInsets: viewportInsets ?? maybeViewportInsets, + devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, + ); + } +} + +(MutableSheetMetrics, MockSheetExtent) createMockSheetExtent({ + required double pixels, + required Extent minExtent, + required Extent maxExtent, + required Size contentSize, + required Size viewportSize, + required EdgeInsets viewportInsets, + required double devicePixelRatio, + SheetPhysics? physics, +}) { + final metricsRegistry = MutableSheetMetrics( + maybePixels: pixels, + maybeMinExtent: minExtent, + maybeMaxExtent: maxExtent, + maybeContentSize: contentSize, + maybeViewportSize: viewportSize, + maybeViewportInsets: viewportInsets, + devicePixelRatio: devicePixelRatio, + ); + + final extent = MockSheetExtent(); + when(extent.pixels).thenAnswer((_) => metricsRegistry.pixels); + when(extent.maybePixels).thenAnswer((_) => metricsRegistry.maybePixels); + when(extent.minExtent).thenAnswer((_) => metricsRegistry.minExtent); + when(extent.maybeMinExtent).thenAnswer((_) => metricsRegistry.maybeMinExtent); + when(extent.maxExtent).thenAnswer((_) => metricsRegistry.maxExtent); + when(extent.maybeMaxExtent).thenAnswer((_) => metricsRegistry.maybeMaxExtent); + when(extent.contentSize).thenAnswer((_) => metricsRegistry.contentSize); + when(extent.maybeContentSize) + .thenAnswer((_) => metricsRegistry.maybeContentSize); + when(extent.viewportSize).thenAnswer((_) => metricsRegistry.viewportSize); + when(extent.maybeViewportSize) + .thenAnswer((_) => metricsRegistry.maybeViewportSize); + when(extent.viewportInsets).thenAnswer((_) => metricsRegistry.viewportInsets); + when(extent.maybeViewportInsets) + .thenAnswer((_) => metricsRegistry.maybeViewportInsets); + when(extent.devicePixelRatio) + .thenAnswer((_) => metricsRegistry.devicePixelRatio); + when(extent.snapshot).thenAnswer((_) => metricsRegistry); + + when(extent.setPixels(any)).thenAnswer((invocation) { + metricsRegistry.maybePixels = + invocation.positionalArguments.first as double; + }); + when(extent.applyNewContentSize(any)).thenAnswer((invocation) { + metricsRegistry.maybeContentSize = + invocation.positionalArguments.first as Size; + }); + when(extent.applyNewViewportDimensions(any, any)).thenAnswer((invocation) { + metricsRegistry + ..maybeViewportSize = invocation.positionalArguments.first as Size + ..maybeViewportInsets = invocation.positionalArguments.last as EdgeInsets; + }); + when(extent.applyNewBoundaryConstraints(any, any)).thenAnswer((invocation) { + metricsRegistry + ..maybeMinExtent = invocation.positionalArguments.first as Extent + ..maybeMaxExtent = invocation.positionalArguments.last as Extent; + }); + when(extent.copyWith( + pixels: anyNamed('pixels'), + minExtent: anyNamed('minExtent'), + maxExtent: anyNamed('maxExtent'), + contentSize: anyNamed('contentSize'), + viewportSize: anyNamed('viewportSize'), + viewportInsets: anyNamed('viewportInsets'), + devicePixelRatio: anyNamed('devicePixelRatio'), + )).thenAnswer((invocation) { + return metricsRegistry.copyWith( + pixels: invocation.namedArguments[#pixels] as double?, + minExtent: invocation.namedArguments[#minExtent] as Extent?, + maxExtent: invocation.namedArguments[#maxExtent] as Extent?, + contentSize: invocation.namedArguments[#contentSize] as Size?, + viewportSize: invocation.namedArguments[#viewportSize] as Size?, + viewportInsets: invocation.namedArguments[#viewportInsets] as EdgeInsets?, + devicePixelRatio: invocation.namedArguments[#devicePixelRatio] as double?, + ); + }); + + if (physics != null) { + when(extent.physics).thenReturn(physics); + } + + return (metricsRegistry, extent); +} diff --git a/test/src/stubbing.mocks.dart b/test/src/stubbing.mocks.dart index 02626bc..2be9a4d 100644 --- a/test/src/stubbing.mocks.dart +++ b/test/src/stubbing.mocks.dart @@ -3,24 +3,24 @@ // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i8; -import 'dart:ui' as _i14; +import 'dart:async' as _i9; +import 'dart:ui' as _i6; import 'package:flutter/cupertino.dart' as _i7; -import 'package:flutter/foundation.dart' as _i9; -import 'package:flutter/gestures.dart' as _i6; -import 'package:flutter/scheduler.dart' as _i10; +import 'package:flutter/foundation.dart' as _i10; +import 'package:flutter/gestures.dart' as _i8; +import 'package:flutter/scheduler.dart' as _i11; import 'package:flutter/src/animation/curves.dart' as _i15; import 'package:mockito/mockito.dart' as _i1; import 'package:mockito/src/dummies.dart' as _i16; import 'package:smooth_sheets/src/foundation/sheet_activity.dart' as _i5; import 'package:smooth_sheets/src/foundation/sheet_context.dart' as _i2; -import 'package:smooth_sheets/src/foundation/sheet_drag.dart' as _i11; +import 'package:smooth_sheets/src/foundation/sheet_drag.dart' as _i12; import 'package:smooth_sheets/src/foundation/sheet_extent.dart' as _i3; import 'package:smooth_sheets/src/foundation/sheet_gesture_tamperer.dart' - as _i13; + as _i14; import 'package:smooth_sheets/src/foundation/sheet_physics.dart' as _i4; -import 'package:smooth_sheets/src/foundation/sheet_status.dart' as _i12; +import 'package:smooth_sheets/src/foundation/sheet_status.dart' as _i13; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -55,8 +55,8 @@ class _FakeSheetMetrics_1 extends _i1.SmartFake implements _i3.SheetMetrics { ); } -class _FakeExtent_2 extends _i1.SmartFake implements _i3.Extent { - _FakeExtent_2( +class _FakeSheetPhysics_2 extends _i1.SmartFake implements _i4.SheetPhysics { + _FakeSheetPhysics_2( Object parent, Invocation parentInvocation, ) : super( @@ -65,8 +65,9 @@ class _FakeExtent_2 extends _i1.SmartFake implements _i3.Extent { ); } -class _FakeSheetPhysics_3 extends _i1.SmartFake implements _i4.SheetPhysics { - _FakeSheetPhysics_3( +class _FakeSheetActivity_3 extends _i1.SmartFake + implements _i5.SheetActivity { + _FakeSheetActivity_3( Object parent, Invocation parentInvocation, ) : super( @@ -75,9 +76,18 @@ class _FakeSheetPhysics_3 extends _i1.SmartFake implements _i4.SheetPhysics { ); } -class _FakeSheetActivity_4 extends _i1.SmartFake - implements _i5.SheetActivity { - _FakeSheetActivity_4( +class _FakeExtent_4 extends _i1.SmartFake implements _i3.Extent { + _FakeExtent_4( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeSize_5 extends _i1.SmartFake implements _i6.Size { + _FakeSize_5( Object parent, Invocation parentInvocation, ) : super( @@ -86,8 +96,8 @@ class _FakeSheetActivity_4 extends _i1.SmartFake ); } -class _FakeDrag_5 extends _i1.SmartFake implements _i6.Drag { - _FakeDrag_5( +class _FakeEdgeInsets_6 extends _i1.SmartFake implements _i7.EdgeInsets { + _FakeEdgeInsets_6( Object parent, Invocation parentInvocation, ) : super( @@ -96,9 +106,19 @@ class _FakeDrag_5 extends _i1.SmartFake implements _i6.Drag { ); } -class _FakeTickerProvider_6 extends _i1.SmartFake +class _FakeDrag_7 extends _i1.SmartFake implements _i8.Drag { + _FakeDrag_7( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeTickerProvider_8 extends _i1.SmartFake implements _i7.TickerProvider { - _FakeTickerProvider_6( + _FakeTickerProvider_8( Object parent, Invocation parentInvocation, ) : super( @@ -107,8 +127,8 @@ class _FakeTickerProvider_6 extends _i1.SmartFake ); } -class _FakeAnimation_7 extends _i1.SmartFake implements _i7.Animation { - _FakeAnimation_7( +class _FakeAnimation_9 extends _i1.SmartFake implements _i7.Animation { + _FakeAnimation_9( Object parent, Invocation parentInvocation, ) : super( @@ -117,8 +137,8 @@ class _FakeAnimation_7 extends _i1.SmartFake implements _i7.Animation { ); } -class _FakeTickerFuture_8 extends _i1.SmartFake implements _i7.TickerFuture { - _FakeTickerFuture_8( +class _FakeTickerFuture_10 extends _i1.SmartFake implements _i7.TickerFuture { + _FakeTickerFuture_10( Object parent, Invocation parentInvocation, ) : super( @@ -127,8 +147,8 @@ class _FakeTickerFuture_8 extends _i1.SmartFake implements _i7.TickerFuture { ); } -class _FakeFuture_9 extends _i1.SmartFake implements _i8.Future { - _FakeFuture_9( +class _FakeFuture_11 extends _i1.SmartFake implements _i9.Future { + _FakeFuture_11( Object parent, Invocation parentInvocation, ) : super( @@ -137,9 +157,9 @@ class _FakeFuture_9 extends _i1.SmartFake implements _i8.Future { ); } -class _FakeDiagnosticsNode_10 extends _i1.SmartFake +class _FakeDiagnosticsNode_12 extends _i1.SmartFake implements _i7.DiagnosticsNode { - _FakeDiagnosticsNode_10( + _FakeDiagnosticsNode_12( Object parent, Invocation parentInvocation, ) : super( @@ -149,14 +169,14 @@ class _FakeDiagnosticsNode_10 extends _i1.SmartFake @override String toString({ - _i9.TextTreeConfiguration? parentConfiguration, + _i10.TextTreeConfiguration? parentConfiguration, _i7.DiagnosticLevel? minLevel = _i7.DiagnosticLevel.info, }) => super.toString(); } -class _FakeTicker_11 extends _i1.SmartFake implements _i10.Ticker { - _FakeTicker_11( +class _FakeTicker_13 extends _i1.SmartFake implements _i11.Ticker { + _FakeTicker_13( Object parent, Invocation parentInvocation, ) : super( @@ -186,7 +206,7 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { ) as _i2.SheetContext); @override - set currentDrag(_i11.SheetDragController? _currentDrag) => super.noSuchMethod( + set currentDrag(_i12.SheetDragController? _currentDrag) => super.noSuchMethod( Invocation.setter( #currentDrag, _currentDrag, @@ -208,20 +228,94 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { ) as _i3.SheetMetrics); @override - _i12.SheetStatus get status => (super.noSuchMethod( + double get devicePixelRatio => (super.noSuchMethod( + Invocation.getter(#devicePixelRatio), + returnValue: 0.0, + returnValueForMissingStub: 0.0, + ) as double); + + @override + _i13.SheetStatus get status => (super.noSuchMethod( Invocation.getter(#status), - returnValue: _i12.SheetStatus.stable, - returnValueForMissingStub: _i12.SheetStatus.stable, - ) as _i12.SheetStatus); + returnValue: _i13.SheetStatus.stable, + returnValueForMissingStub: _i13.SheetStatus.stable, + ) as _i13.SheetStatus); + + @override + _i4.SheetPhysics get physics => (super.noSuchMethod( + Invocation.getter(#physics), + returnValue: _FakeSheetPhysics_2( + this, + Invocation.getter(#physics), + ), + returnValueForMissingStub: _FakeSheetPhysics_2( + this, + Invocation.getter(#physics), + ), + ) as _i4.SheetPhysics); + + @override + _i5.SheetActivity<_i3.SheetExtent> get activity => (super.noSuchMethod( + Invocation.getter(#activity), + returnValue: _FakeSheetActivity_3<_i3.SheetExtent>( + this, + Invocation.getter(#activity), + ), + returnValueForMissingStub: _FakeSheetActivity_3<_i3.SheetExtent>( + this, + Invocation.getter(#activity), + ), + ) as _i5.SheetActivity<_i3.SheetExtent>); + + @override + _i3.SheetMetrics get snapshot => (super.noSuchMethod( + Invocation.getter(#snapshot), + returnValue: _FakeSheetMetrics_1( + this, + Invocation.getter(#snapshot), + ), + returnValueForMissingStub: _FakeSheetMetrics_1( + this, + Invocation.getter(#snapshot), + ), + ) as _i3.SheetMetrics); + + @override + bool get hasListeners => (super.noSuchMethod( + Invocation.getter(#hasListeners), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); + + @override + double get pixels => (super.noSuchMethod( + Invocation.getter(#pixels), + returnValue: 0.0, + returnValueForMissingStub: 0.0, + ) as double); + + @override + double get minPixels => (super.noSuchMethod( + Invocation.getter(#minPixels), + returnValue: 0.0, + returnValueForMissingStub: 0.0, + ) as double); + + @override + double get maxPixels => (super.noSuchMethod( + Invocation.getter(#maxPixels), + returnValue: 0.0, + returnValueForMissingStub: 0.0, + ) as double); @override _i3.Extent get minExtent => (super.noSuchMethod( Invocation.getter(#minExtent), - returnValue: _FakeExtent_2( + returnValue: _FakeExtent_4( this, Invocation.getter(#minExtent), ), - returnValueForMissingStub: _FakeExtent_2( + returnValueForMissingStub: _FakeExtent_4( this, Invocation.getter(#minExtent), ), @@ -230,58 +324,93 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { @override _i3.Extent get maxExtent => (super.noSuchMethod( Invocation.getter(#maxExtent), - returnValue: _FakeExtent_2( + returnValue: _FakeExtent_4( this, Invocation.getter(#maxExtent), ), - returnValueForMissingStub: _FakeExtent_2( + returnValueForMissingStub: _FakeExtent_4( this, Invocation.getter(#maxExtent), ), ) as _i3.Extent); @override - _i4.SheetPhysics get physics => (super.noSuchMethod( - Invocation.getter(#physics), - returnValue: _FakeSheetPhysics_3( + _i6.Size get contentSize => (super.noSuchMethod( + Invocation.getter(#contentSize), + returnValue: _FakeSize_5( this, - Invocation.getter(#physics), + Invocation.getter(#contentSize), ), - returnValueForMissingStub: _FakeSheetPhysics_3( + returnValueForMissingStub: _FakeSize_5( this, - Invocation.getter(#physics), + Invocation.getter(#contentSize), ), - ) as _i4.SheetPhysics); + ) as _i6.Size); @override - _i5.SheetActivity<_i3.SheetExtent> get activity => (super.noSuchMethod( - Invocation.getter(#activity), - returnValue: _FakeSheetActivity_4<_i3.SheetExtent>( + _i6.Size get viewportSize => (super.noSuchMethod( + Invocation.getter(#viewportSize), + returnValue: _FakeSize_5( this, - Invocation.getter(#activity), + Invocation.getter(#viewportSize), ), - returnValueForMissingStub: _FakeSheetActivity_4<_i3.SheetExtent>( + returnValueForMissingStub: _FakeSize_5( this, - Invocation.getter(#activity), + Invocation.getter(#viewportSize), ), - ) as _i5.SheetActivity<_i3.SheetExtent>); + ) as _i6.Size); @override - _i3.SheetMetrics get metrics => (super.noSuchMethod( - Invocation.getter(#metrics), - returnValue: _FakeSheetMetrics_1( + _i7.EdgeInsets get viewportInsets => (super.noSuchMethod( + Invocation.getter(#viewportInsets), + returnValue: _FakeEdgeInsets_6( this, - Invocation.getter(#metrics), + Invocation.getter(#viewportInsets), ), - returnValueForMissingStub: _FakeSheetMetrics_1( + returnValueForMissingStub: _FakeEdgeInsets_6( this, - Invocation.getter(#metrics), + Invocation.getter(#viewportInsets), ), - ) as _i3.SheetMetrics); + ) as _i7.EdgeInsets); @override - bool get hasListeners => (super.noSuchMethod( - Invocation.getter(#hasListeners), + double get viewPixels => (super.noSuchMethod( + Invocation.getter(#viewPixels), + returnValue: 0.0, + returnValueForMissingStub: 0.0, + ) as double); + + @override + double get minViewPixels => (super.noSuchMethod( + Invocation.getter(#minViewPixels), + returnValue: 0.0, + returnValueForMissingStub: 0.0, + ) as double); + + @override + double get maxViewPixels => (super.noSuchMethod( + Invocation.getter(#maxViewPixels), + returnValue: 0.0, + returnValueForMissingStub: 0.0, + ) as double); + + @override + bool get hasDimensions => (super.noSuchMethod( + Invocation.getter(#hasDimensions), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); + + @override + bool get isPixelsInBounds => (super.noSuchMethod( + Invocation.getter(#isPixelsInBounds), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); + + @override + bool get isPixelsOutOfBounds => (super.noSuchMethod( + Invocation.getter(#isPixelsOutOfBounds), returnValue: false, returnValueForMissingStub: false, ) as bool); @@ -296,7 +425,7 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { ); @override - void updateGestureTamperer(_i13.SheetGestureProxyMixin? gestureTamperer) => + void updateGestureTamperer(_i14.SheetGestureProxyMixin? gestureTamperer) => super.noSuchMethod( Invocation.method( #updateGestureTamperer, @@ -315,7 +444,7 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { ); @override - void applyNewContentSize(_i14.Size? contentSize) => super.noSuchMethod( + void applyNewContentSize(_i6.Size? contentSize) => super.noSuchMethod( Invocation.method( #applyNewContentSize, [contentSize], @@ -325,7 +454,7 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { @override void applyNewViewportDimensions( - _i14.Size? size, + _i6.Size? size, _i7.EdgeInsets? insets, ) => super.noSuchMethod( @@ -436,9 +565,9 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { ); @override - _i6.Drag drag( + _i8.Drag drag( _i7.DragStartDetails? details, - _i14.VoidCallback? dragCancelCallback, + _i6.VoidCallback? dragCancelCallback, ) => (super.noSuchMethod( Invocation.method( @@ -448,7 +577,7 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { dragCancelCallback, ], ), - returnValue: _FakeDrag_5( + returnValue: _FakeDrag_7( this, Invocation.method( #drag, @@ -458,7 +587,7 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { ], ), ), - returnValueForMissingStub: _FakeDrag_5( + returnValueForMissingStub: _FakeDrag_7( this, Invocation.method( #drag, @@ -468,7 +597,7 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { ], ), ), - ) as _i6.Drag); + ) as _i8.Drag); @override void dispose() => super.noSuchMethod( @@ -498,7 +627,7 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { ); @override - _i8.Future animateTo( + _i9.Future animateTo( _i3.Extent? newExtent, { _i7.Curve? curve = _i7.Curves.easeInOut, Duration? duration = const Duration(milliseconds: 300), @@ -512,9 +641,67 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { #duration: duration, }, ), - returnValue: _i8.Future.value(), - returnValueForMissingStub: _i8.Future.value(), - ) as _i8.Future); + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value(), + ) as _i9.Future); + + @override + _i3.SheetMetrics copyWith({ + double? pixels, + _i3.Extent? minExtent, + _i3.Extent? maxExtent, + _i6.Size? contentSize, + _i6.Size? viewportSize, + _i7.EdgeInsets? viewportInsets, + double? devicePixelRatio, + }) => + (super.noSuchMethod( + Invocation.method( + #copyWith, + [], + { + #pixels: pixels, + #minExtent: minExtent, + #maxExtent: maxExtent, + #contentSize: contentSize, + #viewportSize: viewportSize, + #viewportInsets: viewportInsets, + #devicePixelRatio: devicePixelRatio, + }, + ), + returnValue: _FakeSheetMetrics_1( + this, + Invocation.method( + #copyWith, + [], + { + #pixels: pixels, + #minExtent: minExtent, + #maxExtent: maxExtent, + #contentSize: contentSize, + #viewportSize: viewportSize, + #viewportInsets: viewportInsets, + #devicePixelRatio: devicePixelRatio, + }, + ), + ), + returnValueForMissingStub: _FakeSheetMetrics_1( + this, + Invocation.method( + #copyWith, + [], + { + #pixels: pixels, + #minExtent: minExtent, + #maxExtent: maxExtent, + #contentSize: contentSize, + #viewportSize: viewportSize, + #viewportInsets: viewportInsets, + #devicePixelRatio: devicePixelRatio, + }, + ), + ), + ) as _i3.SheetMetrics); @override void didUpdateMetrics() => super.noSuchMethod( @@ -526,7 +713,7 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { ); @override - void didDragStart(_i11.SheetDragStartDetails? details) => super.noSuchMethod( + void didDragStart(_i12.SheetDragStartDetails? details) => super.noSuchMethod( Invocation.method( #didDragStart, [details], @@ -535,7 +722,7 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { ); @override - void didDragEnd(_i11.SheetDragEndDetails? details) => super.noSuchMethod( + void didDragEnd(_i12.SheetDragEndDetails? details) => super.noSuchMethod( Invocation.method( #didDragEnd, [details], @@ -544,7 +731,7 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { ); @override - void didDragUpdateMetrics(_i11.SheetDragUpdateDetails? details) => + void didDragUpdateMetrics(_i12.SheetDragUpdateDetails? details) => super.noSuchMethod( Invocation.method( #didDragUpdateMetrics, @@ -572,7 +759,7 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { ); @override - void addListener(_i14.VoidCallback? listener) => super.noSuchMethod( + void addListener(_i6.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #addListener, [listener], @@ -581,7 +768,7 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { ); @override - void removeListener(_i14.VoidCallback? listener) => super.noSuchMethod( + void removeListener(_i6.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #removeListener, [listener], @@ -606,11 +793,11 @@ class MockSheetContext extends _i1.Mock implements _i2.SheetContext { @override _i7.TickerProvider get vsync => (super.noSuchMethod( Invocation.getter(#vsync), - returnValue: _FakeTickerProvider_6( + returnValue: _FakeTickerProvider_8( this, Invocation.getter(#vsync), ), - returnValueForMissingStub: _FakeTickerProvider_6( + returnValueForMissingStub: _FakeTickerProvider_8( this, Invocation.getter(#vsync), ), @@ -671,11 +858,11 @@ class MockAnimationController extends _i1.Mock @override _i7.Animation get view => (super.noSuchMethod( Invocation.getter(#view), - returnValue: _FakeAnimation_7( + returnValue: _FakeAnimation_9( this, Invocation.getter(#view), ), - returnValueForMissingStub: _FakeAnimation_7( + returnValueForMissingStub: _FakeAnimation_9( this, Invocation.getter(#view), ), @@ -757,7 +944,7 @@ class MockAnimationController extends _i1.Mock [], {#from: from}, ), - returnValue: _FakeTickerFuture_8( + returnValue: _FakeTickerFuture_10( this, Invocation.method( #forward, @@ -765,7 +952,7 @@ class MockAnimationController extends _i1.Mock {#from: from}, ), ), - returnValueForMissingStub: _FakeTickerFuture_8( + returnValueForMissingStub: _FakeTickerFuture_10( this, Invocation.method( #forward, @@ -782,7 +969,7 @@ class MockAnimationController extends _i1.Mock [], {#from: from}, ), - returnValue: _FakeTickerFuture_8( + returnValue: _FakeTickerFuture_10( this, Invocation.method( #reverse, @@ -790,7 +977,7 @@ class MockAnimationController extends _i1.Mock {#from: from}, ), ), - returnValueForMissingStub: _FakeTickerFuture_8( + returnValueForMissingStub: _FakeTickerFuture_10( this, Invocation.method( #reverse, @@ -815,7 +1002,7 @@ class MockAnimationController extends _i1.Mock #curve: curve, }, ), - returnValue: _FakeTickerFuture_8( + returnValue: _FakeTickerFuture_10( this, Invocation.method( #animateTo, @@ -826,7 +1013,7 @@ class MockAnimationController extends _i1.Mock }, ), ), - returnValueForMissingStub: _FakeTickerFuture_8( + returnValueForMissingStub: _FakeTickerFuture_10( this, Invocation.method( #animateTo, @@ -854,7 +1041,7 @@ class MockAnimationController extends _i1.Mock #curve: curve, }, ), - returnValue: _FakeTickerFuture_8( + returnValue: _FakeTickerFuture_10( this, Invocation.method( #animateBack, @@ -865,7 +1052,7 @@ class MockAnimationController extends _i1.Mock }, ), ), - returnValueForMissingStub: _FakeTickerFuture_8( + returnValueForMissingStub: _FakeTickerFuture_10( this, Invocation.method( #animateBack, @@ -896,7 +1083,7 @@ class MockAnimationController extends _i1.Mock #period: period, }, ), - returnValue: _FakeTickerFuture_8( + returnValue: _FakeTickerFuture_10( this, Invocation.method( #repeat, @@ -909,7 +1096,7 @@ class MockAnimationController extends _i1.Mock }, ), ), - returnValueForMissingStub: _FakeTickerFuture_8( + returnValueForMissingStub: _FakeTickerFuture_10( this, Invocation.method( #repeat, @@ -940,7 +1127,7 @@ class MockAnimationController extends _i1.Mock #animationBehavior: animationBehavior, }, ), - returnValue: _FakeTickerFuture_8( + returnValue: _FakeTickerFuture_10( this, Invocation.method( #fling, @@ -952,7 +1139,7 @@ class MockAnimationController extends _i1.Mock }, ), ), - returnValueForMissingStub: _FakeTickerFuture_8( + returnValueForMissingStub: _FakeTickerFuture_10( this, Invocation.method( #fling, @@ -973,14 +1160,14 @@ class MockAnimationController extends _i1.Mock #animateWith, [simulation], ), - returnValue: _FakeTickerFuture_8( + returnValue: _FakeTickerFuture_10( this, Invocation.method( #animateWith, [simulation], ), ), - returnValueForMissingStub: _FakeTickerFuture_8( + returnValueForMissingStub: _FakeTickerFuture_10( this, Invocation.method( #animateWith, @@ -1031,7 +1218,7 @@ class MockAnimationController extends _i1.Mock ) as String); @override - void addListener(_i14.VoidCallback? listener) => super.noSuchMethod( + void addListener(_i6.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #addListener, [listener], @@ -1040,7 +1227,7 @@ class MockAnimationController extends _i1.Mock ); @override - void removeListener(_i14.VoidCallback? listener) => super.noSuchMethod( + void removeListener(_i6.VoidCallback? listener) => super.noSuchMethod( Invocation.method( #removeListener, [listener], @@ -1074,14 +1261,14 @@ class MockAnimationController extends _i1.Mock #drive, [child], ), - returnValue: _FakeAnimation_7( + returnValue: _FakeAnimation_9( this, Invocation.method( #drive, [child], ), ), - returnValueForMissingStub: _FakeAnimation_7( + returnValueForMissingStub: _FakeAnimation_9( this, Invocation.method( #drive, @@ -1150,14 +1337,14 @@ class MockAnimationController extends _i1.Mock /// See the documentation for Mockito's code generation for more information. class MockTickerFuture extends _i1.Mock implements _i7.TickerFuture { @override - _i8.Future get orCancel => (super.noSuchMethod( + _i9.Future get orCancel => (super.noSuchMethod( Invocation.getter(#orCancel), - returnValue: _i8.Future.value(), - returnValueForMissingStub: _i8.Future.value(), - ) as _i8.Future); + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value(), + ) as _i9.Future); @override - void whenCompleteOrCancel(_i14.VoidCallback? callback) => super.noSuchMethod( + void whenCompleteOrCancel(_i6.VoidCallback? callback) => super.noSuchMethod( Invocation.method( #whenCompleteOrCancel, [callback], @@ -1166,17 +1353,17 @@ class MockTickerFuture extends _i1.Mock implements _i7.TickerFuture { ); @override - _i8.Stream asStream() => (super.noSuchMethod( + _i9.Stream asStream() => (super.noSuchMethod( Invocation.method( #asStream, [], ), - returnValue: _i8.Stream.empty(), - returnValueForMissingStub: _i8.Stream.empty(), - ) as _i8.Stream); + returnValue: _i9.Stream.empty(), + returnValueForMissingStub: _i9.Stream.empty(), + ) as _i9.Stream); @override - _i8.Future catchError( + _i9.Future catchError( Function? onError, { bool Function(Object)? test, }) => @@ -1186,13 +1373,13 @@ class MockTickerFuture extends _i1.Mock implements _i7.TickerFuture { [onError], {#test: test}, ), - returnValue: _i8.Future.value(), - returnValueForMissingStub: _i8.Future.value(), - ) as _i8.Future); + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value(), + ) as _i9.Future); @override - _i8.Future then( - _i8.FutureOr Function(void)? onValue, { + _i9.Future then( + _i9.FutureOr Function(void)? onValue, { Function? onError, }) => (super.noSuchMethod( @@ -1210,9 +1397,9 @@ class MockTickerFuture extends _i1.Mock implements _i7.TickerFuture { {#onError: onError}, ), ), - (R v) => _i8.Future.value(v), + (R v) => _i9.Future.value(v), ) ?? - _FakeFuture_9( + _FakeFuture_11( this, Invocation.method( #then, @@ -1229,9 +1416,9 @@ class MockTickerFuture extends _i1.Mock implements _i7.TickerFuture { {#onError: onError}, ), ), - (R v) => _i8.Future.value(v), + (R v) => _i9.Future.value(v), ) ?? - _FakeFuture_9( + _FakeFuture_11( this, Invocation.method( #then, @@ -1239,12 +1426,12 @@ class MockTickerFuture extends _i1.Mock implements _i7.TickerFuture { {#onError: onError}, ), ), - ) as _i8.Future); + ) as _i9.Future); @override - _i8.Future timeout( + _i9.Future timeout( Duration? timeLimit, { - _i8.FutureOr Function()? onTimeout, + _i9.FutureOr Function()? onTimeout, }) => (super.noSuchMethod( Invocation.method( @@ -1252,26 +1439,26 @@ class MockTickerFuture extends _i1.Mock implements _i7.TickerFuture { [timeLimit], {#onTimeout: onTimeout}, ), - returnValue: _i8.Future.value(), - returnValueForMissingStub: _i8.Future.value(), - ) as _i8.Future); + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value(), + ) as _i9.Future); @override - _i8.Future whenComplete(dynamic Function()? action) => + _i9.Future whenComplete(dynamic Function()? action) => (super.noSuchMethod( Invocation.method( #whenComplete, [action], ), - returnValue: _i8.Future.value(), - returnValueForMissingStub: _i8.Future.value(), - ) as _i8.Future); + returnValue: _i9.Future.value(), + returnValueForMissingStub: _i9.Future.value(), + ) as _i9.Future); } /// A class which mocks [Ticker]. /// /// See the documentation for Mockito's code generation for more information. -class MockTicker extends _i1.Mock implements _i10.Ticker { +class MockTicker extends _i1.Mock implements _i11.Ticker { @override bool get muted => (super.noSuchMethod( Invocation.getter(#muted), @@ -1322,14 +1509,14 @@ class MockTicker extends _i1.Mock implements _i10.Ticker { #start, [], ), - returnValue: _FakeTickerFuture_8( + returnValue: _FakeTickerFuture_10( this, Invocation.method( #start, [], ), ), - returnValueForMissingStub: _FakeTickerFuture_8( + returnValueForMissingStub: _FakeTickerFuture_10( this, Invocation.method( #start, @@ -1344,14 +1531,14 @@ class MockTicker extends _i1.Mock implements _i10.Ticker { #describeForError, [name], ), - returnValue: _FakeDiagnosticsNode_10( + returnValue: _FakeDiagnosticsNode_12( this, Invocation.method( #describeForError, [name], ), ), - returnValueForMissingStub: _FakeDiagnosticsNode_10( + returnValueForMissingStub: _FakeDiagnosticsNode_12( this, Invocation.method( #describeForError, @@ -1390,7 +1577,7 @@ class MockTicker extends _i1.Mock implements _i10.Ticker { ); @override - void absorbTicker(_i10.Ticker? originalTicker) => super.noSuchMethod( + void absorbTicker(_i11.Ticker? originalTicker) => super.noSuchMethod( Invocation.method( #absorbTicker, [originalTicker], @@ -1416,24 +1603,24 @@ class MockTicker extends _i1.Mock implements _i10.Ticker { /// See the documentation for Mockito's code generation for more information. class MockTickerProvider extends _i1.Mock implements _i7.TickerProvider { @override - _i10.Ticker createTicker(_i10.TickerCallback? onTick) => (super.noSuchMethod( + _i11.Ticker createTicker(_i11.TickerCallback? onTick) => (super.noSuchMethod( Invocation.method( #createTicker, [onTick], ), - returnValue: _FakeTicker_11( + returnValue: _FakeTicker_13( this, Invocation.method( #createTicker, [onTick], ), ), - returnValueForMissingStub: _FakeTicker_11( + returnValueForMissingStub: _FakeTicker_13( this, Invocation.method( #createTicker, [onTick], ), ), - ) as _i10.Ticker); + ) as _i11.Ticker); } From e86684835526f9bbfebdaf2c934909c5b87d439e Mon Sep 17 00:00:00 2001 From: fujidaiti Date: Sat, 21 Sep 2024 19:51:00 +0900 Subject: [PATCH 03/22] Change SheetExtent to notify its "pixels" instead of "metrics" --- lib/src/foundation/sheet_extent.dart | 4 +- test/src/stubbing.mocks.dart | 93 ++++++++++++---------------- 2 files changed, 42 insertions(+), 55 deletions(-) diff --git a/lib/src/foundation/sheet_extent.dart b/lib/src/foundation/sheet_extent.dart index 2930add..dd28a81 100644 --- a/lib/src/foundation/sheet_extent.dart +++ b/lib/src/foundation/sheet_extent.dart @@ -124,7 +124,7 @@ class FixedExtent implements Extent { @optionalTypeArgs abstract class SheetExtent extends ChangeNotifier with SheetMetrics - implements ValueListenable { + implements ValueListenable { /// Creates an object that manages the extent of a sheet. SheetExtent({ required this.context, @@ -143,7 +143,7 @@ abstract class SheetExtent extends ChangeNotifier } @override - SheetMetrics get value => snapshot; + double? get value => snapshot.maybePixels; @override double? get maybePixels => snapshot.maybePixels; diff --git a/test/src/stubbing.mocks.dart b/test/src/stubbing.mocks.dart index 2be9a4d..1785d51 100644 --- a/test/src/stubbing.mocks.dart +++ b/test/src/stubbing.mocks.dart @@ -16,10 +16,10 @@ import 'package:mockito/src/dummies.dart' as _i16; import 'package:smooth_sheets/src/foundation/sheet_activity.dart' as _i5; import 'package:smooth_sheets/src/foundation/sheet_context.dart' as _i2; import 'package:smooth_sheets/src/foundation/sheet_drag.dart' as _i12; -import 'package:smooth_sheets/src/foundation/sheet_extent.dart' as _i3; +import 'package:smooth_sheets/src/foundation/sheet_extent.dart' as _i4; import 'package:smooth_sheets/src/foundation/sheet_gesture_tamperer.dart' as _i14; -import 'package:smooth_sheets/src/foundation/sheet_physics.dart' as _i4; +import 'package:smooth_sheets/src/foundation/sheet_physics.dart' as _i3; import 'package:smooth_sheets/src/foundation/sheet_status.dart' as _i13; // ignore_for_file: type=lint @@ -45,8 +45,8 @@ class _FakeSheetContext_0 extends _i1.SmartFake implements _i2.SheetContext { ); } -class _FakeSheetMetrics_1 extends _i1.SmartFake implements _i3.SheetMetrics { - _FakeSheetMetrics_1( +class _FakeSheetPhysics_1 extends _i1.SmartFake implements _i3.SheetPhysics { + _FakeSheetPhysics_1( Object parent, Invocation parentInvocation, ) : super( @@ -55,8 +55,9 @@ class _FakeSheetMetrics_1 extends _i1.SmartFake implements _i3.SheetMetrics { ); } -class _FakeSheetPhysics_2 extends _i1.SmartFake implements _i4.SheetPhysics { - _FakeSheetPhysics_2( +class _FakeSheetActivity_2 extends _i1.SmartFake + implements _i5.SheetActivity { + _FakeSheetActivity_2( Object parent, Invocation parentInvocation, ) : super( @@ -65,9 +66,8 @@ class _FakeSheetPhysics_2 extends _i1.SmartFake implements _i4.SheetPhysics { ); } -class _FakeSheetActivity_3 extends _i1.SmartFake - implements _i5.SheetActivity { - _FakeSheetActivity_3( +class _FakeSheetMetrics_3 extends _i1.SmartFake implements _i4.SheetMetrics { + _FakeSheetMetrics_3( Object parent, Invocation parentInvocation, ) : super( @@ -76,7 +76,7 @@ class _FakeSheetActivity_3 extends _i1.SmartFake ); } -class _FakeExtent_4 extends _i1.SmartFake implements _i3.Extent { +class _FakeExtent_4 extends _i1.SmartFake implements _i4.Extent { _FakeExtent_4( Object parent, Invocation parentInvocation, @@ -191,7 +191,7 @@ class _FakeTicker_13 extends _i1.SmartFake implements _i11.Ticker { /// A class which mocks [SheetExtent]. /// /// See the documentation for Mockito's code generation for more information. -class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { +class MockSheetExtent extends _i1.Mock implements _i4.SheetExtent { @override _i2.SheetContext get context => (super.noSuchMethod( Invocation.getter(#context), @@ -214,19 +214,6 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { returnValueForMissingStub: null, ); - @override - _i3.SheetMetrics get value => (super.noSuchMethod( - Invocation.getter(#value), - returnValue: _FakeSheetMetrics_1( - this, - Invocation.getter(#value), - ), - returnValueForMissingStub: _FakeSheetMetrics_1( - this, - Invocation.getter(#value), - ), - ) as _i3.SheetMetrics); - @override double get devicePixelRatio => (super.noSuchMethod( Invocation.getter(#devicePixelRatio), @@ -242,43 +229,43 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { ) as _i13.SheetStatus); @override - _i4.SheetPhysics get physics => (super.noSuchMethod( + _i3.SheetPhysics get physics => (super.noSuchMethod( Invocation.getter(#physics), - returnValue: _FakeSheetPhysics_2( + returnValue: _FakeSheetPhysics_1( this, Invocation.getter(#physics), ), - returnValueForMissingStub: _FakeSheetPhysics_2( + returnValueForMissingStub: _FakeSheetPhysics_1( this, Invocation.getter(#physics), ), - ) as _i4.SheetPhysics); + ) as _i3.SheetPhysics); @override - _i5.SheetActivity<_i3.SheetExtent> get activity => (super.noSuchMethod( + _i5.SheetActivity<_i4.SheetExtent> get activity => (super.noSuchMethod( Invocation.getter(#activity), - returnValue: _FakeSheetActivity_3<_i3.SheetExtent>( + returnValue: _FakeSheetActivity_2<_i4.SheetExtent>( this, Invocation.getter(#activity), ), - returnValueForMissingStub: _FakeSheetActivity_3<_i3.SheetExtent>( + returnValueForMissingStub: _FakeSheetActivity_2<_i4.SheetExtent>( this, Invocation.getter(#activity), ), - ) as _i5.SheetActivity<_i3.SheetExtent>); + ) as _i5.SheetActivity<_i4.SheetExtent>); @override - _i3.SheetMetrics get snapshot => (super.noSuchMethod( + _i4.SheetMetrics get snapshot => (super.noSuchMethod( Invocation.getter(#snapshot), - returnValue: _FakeSheetMetrics_1( + returnValue: _FakeSheetMetrics_3( this, Invocation.getter(#snapshot), ), - returnValueForMissingStub: _FakeSheetMetrics_1( + returnValueForMissingStub: _FakeSheetMetrics_3( this, Invocation.getter(#snapshot), ), - ) as _i3.SheetMetrics); + ) as _i4.SheetMetrics); @override bool get hasListeners => (super.noSuchMethod( @@ -309,7 +296,7 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { ) as double); @override - _i3.Extent get minExtent => (super.noSuchMethod( + _i4.Extent get minExtent => (super.noSuchMethod( Invocation.getter(#minExtent), returnValue: _FakeExtent_4( this, @@ -319,10 +306,10 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { this, Invocation.getter(#minExtent), ), - ) as _i3.Extent); + ) as _i4.Extent); @override - _i3.Extent get maxExtent => (super.noSuchMethod( + _i4.Extent get maxExtent => (super.noSuchMethod( Invocation.getter(#maxExtent), returnValue: _FakeExtent_4( this, @@ -332,7 +319,7 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { this, Invocation.getter(#maxExtent), ), - ) as _i3.Extent); + ) as _i4.Extent); @override _i6.Size get contentSize => (super.noSuchMethod( @@ -416,7 +403,7 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { ) as bool); @override - void takeOver(_i3.SheetExtent? other) => super.noSuchMethod( + void takeOver(_i4.SheetExtent? other) => super.noSuchMethod( Invocation.method( #takeOver, [other], @@ -435,7 +422,7 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { ); @override - void updatePhysics(_i4.SheetPhysics? physics) => super.noSuchMethod( + void updatePhysics(_i3.SheetPhysics? physics) => super.noSuchMethod( Invocation.method( #updatePhysics, [physics], @@ -470,8 +457,8 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { @override void applyNewBoundaryConstraints( - _i3.Extent? minExtent, - _i3.Extent? maxExtent, + _i4.Extent? minExtent, + _i4.Extent? maxExtent, ) => super.noSuchMethod( Invocation.method( @@ -512,7 +499,7 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { ); @override - void beginActivity(_i5.SheetActivity<_i3.SheetExtent>? activity) => + void beginActivity(_i5.SheetActivity<_i4.SheetExtent>? activity) => super.noSuchMethod( Invocation.method( #beginActivity, @@ -550,7 +537,7 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { @override void settleTo( - _i3.Extent? detent, + _i4.Extent? detent, Duration? duration, ) => super.noSuchMethod( @@ -628,7 +615,7 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { @override _i9.Future animateTo( - _i3.Extent? newExtent, { + _i4.Extent? newExtent, { _i7.Curve? curve = _i7.Curves.easeInOut, Duration? duration = const Duration(milliseconds: 300), }) => @@ -646,10 +633,10 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { ) as _i9.Future); @override - _i3.SheetMetrics copyWith({ + _i4.SheetMetrics copyWith({ double? pixels, - _i3.Extent? minExtent, - _i3.Extent? maxExtent, + _i4.Extent? minExtent, + _i4.Extent? maxExtent, _i6.Size? contentSize, _i6.Size? viewportSize, _i7.EdgeInsets? viewportInsets, @@ -669,7 +656,7 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { #devicePixelRatio: devicePixelRatio, }, ), - returnValue: _FakeSheetMetrics_1( + returnValue: _FakeSheetMetrics_3( this, Invocation.method( #copyWith, @@ -685,7 +672,7 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { }, ), ), - returnValueForMissingStub: _FakeSheetMetrics_1( + returnValueForMissingStub: _FakeSheetMetrics_3( this, Invocation.method( #copyWith, @@ -701,7 +688,7 @@ class MockSheetExtent extends _i1.Mock implements _i3.SheetExtent { }, ), ), - ) as _i3.SheetMetrics); + ) as _i4.SheetMetrics); @override void didUpdateMetrics() => super.noSuchMethod( From 80ed1be2447b3f7eda4ef930ea8759f7736218ba Mon Sep 17 00:00:00 2001 From: fujidaiti Date: Sat, 21 Sep 2024 20:08:51 +0900 Subject: [PATCH 04/22] Change SheetController to report client's "pixels" instead of "metrics" --- example/lib/showcase/airbnb_mobile_app.dart | 2 +- example/lib/tutorial/sheet_controller.dart | 4 ++-- .../foundation/extent_driven_animation.dart | 2 +- lib/src/foundation/sheet_controller.dart | 16 +++++++++++++--- lib/src/modal/cupertino.dart | 2 +- migrations/migration-guide-0.10.x.md | 4 ++++ test/draggable/draggable_sheet_test.dart | 8 ++++---- test/navigation/navigation_sheet_test.dart | 19 +++++++++++-------- test/scrollable/scrollable_sheet_test.dart | 8 ++++---- 9 files changed, 41 insertions(+), 24 deletions(-) diff --git a/example/lib/showcase/airbnb_mobile_app.dart b/example/lib/showcase/airbnb_mobile_app.dart index d1214b1..9534b9d 100644 --- a/example/lib/showcase/airbnb_mobile_app.dart +++ b/example/lib/showcase/airbnb_mobile_app.dart @@ -80,7 +80,7 @@ class _MapButton extends StatelessWidget { final sheetController = DefaultSheetController.of(context); void onPressed() { - final metrics = sheetController.value; + final metrics = sheetController.metrics; if (metrics.hasDimensions) { // Collapse the sheet to reveal the map behind. sheetController.animateTo( diff --git a/example/lib/tutorial/sheet_controller.dart b/example/lib/tutorial/sheet_controller.dart index 83c3cdd..727a0cf 100644 --- a/example/lib/tutorial/sheet_controller.dart +++ b/example/lib/tutorial/sheet_controller.dart @@ -50,9 +50,9 @@ class _ExampleHomeState extends State<_ExampleHome> { // SheetController can be used to observe changes in the sheet extent. child: ValueListenableBuilder( valueListenable: controller, - builder: (context, metrics, child) { + builder: (context, pixels, child) { return Text( - 'Extent: ${metrics.maybePixels?.toStringAsFixed(1)}', + 'Extent: ${pixels?.toStringAsFixed(1)}', style: Theme.of(context).textTheme.displaySmall, ); }, diff --git a/lib/src/foundation/extent_driven_animation.dart b/lib/src/foundation/extent_driven_animation.dart index cbd81dc..7a98601 100644 --- a/lib/src/foundation/extent_driven_animation.dart +++ b/lib/src/foundation/extent_driven_animation.dart @@ -42,7 +42,7 @@ class ExtentDrivenAnimation extends Animation { @override double get value { - final metrics = _controller.value; + final metrics = _controller.metrics; if (!metrics.hasDimensions) { return initialValue; } diff --git a/lib/src/foundation/sheet_controller.dart b/lib/src/foundation/sheet_controller.dart index 6af6813..d56327e 100644 --- a/lib/src/foundation/sheet_controller.dart +++ b/lib/src/foundation/sheet_controller.dart @@ -3,11 +3,11 @@ import 'package:flutter/scheduler.dart'; import 'package:flutter/widgets.dart'; import 'package:meta/meta.dart'; +import 'foundation.dart'; import 'sheet_extent.dart'; -import 'sheet_status.dart'; class SheetController extends ChangeNotifier - implements ValueListenable { + implements ValueListenable { SheetExtent? _client; /// A notifier which notifies listeners immediately when the [_client] fires. @@ -17,11 +17,21 @@ class SheetController extends ChangeNotifier /// not be notified during the middle of a frame. final _immediateListeners = ChangeNotifier(); + /// The current sheet position. + /// + /// Returns [SheetExtent.value] of the attached [SheetExtent], + /// or `null` if no [SheetExtent] is attached. @override - SheetMetrics get value => _client?.snapshot ?? SheetMetrics.empty; + double? get value => _client?.value; SheetStatus? get status => _client?.status; + /// The current metrics of the sheet. + /// + /// Returns [SheetExtent.snapshot] of the attached [SheetExtent], + /// or [SheetMetrics.empty] if no [SheetExtent] is attached. + SheetMetrics get metrics => _client?.snapshot ?? SheetMetrics.empty; + /// Whether a [SheetExtent] is attached to this controller. bool get hasClient => _client != null; diff --git a/lib/src/modal/cupertino.dart b/lib/src/modal/cupertino.dart index c47828a..efe62fa 100644 --- a/lib/src/modal/cupertino.dart +++ b/lib/src/modal/cupertino.dart @@ -373,7 +373,7 @@ abstract class _BaseCupertinoModalSheetRoute extends PageRoute switch (controller!.status) { case AnimationStatus.forward: case AnimationStatus.completed: - final metrics = _sheetController.value; + final metrics = _sheetController.metrics; if (metrics.hasDimensions) { _cupertinoTransitionControllerOf[_previousRoute]?.value = min( controller!.value, diff --git a/migrations/migration-guide-0.10.x.md b/migrations/migration-guide-0.10.x.md index 787d998..76efa52 100644 --- a/migrations/migration-guide-0.10.x.md +++ b/migrations/migration-guide-0.10.x.md @@ -15,3 +15,7 @@ The `findSnapPixels` method has been removed. Use `findSnapExtent` instead. ## Changes in `SheetPhysics` :boom: The `createSettlingSimulation` method has been removed in favor of the `findSettledExtent` method. As a result, `InterpolationSimulation` has also been removed since it is no longer used internally and is not a core feature of the package. + +## Changes in `SheetController` :boom: + +`SheetController` is no longer a notifier of `SheetMetrics`, and is now a notifier of the sheet position (`double?`) instead. It is still possible to access the `SheetMetrics` object through the `SheetController.metrics` getter. diff --git a/test/draggable/draggable_sheet_test.dart b/test/draggable/draggable_sheet_test.dart index 881fa38..027750b 100644 --- a/test/draggable/draggable_sheet_test.dart +++ b/test/draggable/draggable_sheet_test.dart @@ -97,9 +97,9 @@ void main() { ), ); - expect(controller.value.pixels, 200, + expect(controller.metrics.pixels, 200, reason: 'The sheet should be at the initial extent.'); - expect(controller.value.minPixels < controller.value.maxPixels, isTrue, + expect(controller.metrics.minPixels < controller.metrics.maxPixels, isTrue, reason: 'The sheet should be draggable.'); // Start animating the sheet to the max extent. @@ -118,8 +118,8 @@ void main() { expect(MediaQuery.viewInsetsOf(sheetKey.currentContext!).bottom, 200, reason: 'The keyboard should be fully shown.'); expect( - controller.value.pixels, - controller.value.maxPixels, + controller.metrics.pixels, + controller.metrics.maxPixels, reason: 'After the keyboard is fully shown, ' 'the entire sheet should also be visible.', ); diff --git a/test/navigation/navigation_sheet_test.dart b/test/navigation/navigation_sheet_test.dart index 0c49ec9..7ce74be 100644 --- a/test/navigation/navigation_sheet_test.dart +++ b/test/navigation/navigation_sheet_test.dart @@ -242,7 +242,7 @@ void main() { final pixelTracking = []; final controller = SheetController(); controller.addListener(() { - pixelTracking.add(controller.value.maybePixels); + pixelTracking.add(controller.metrics.maybePixels); }); await tester.pumpWidget( @@ -286,8 +286,8 @@ void main() { (double?, double?)? lastBoundaryValues; // (minPixels, maxPixels) controller.addListener(() { lastBoundaryValues = ( - controller.value.maybeMinPixels, - controller.value.maybeMaxPixels, + controller.metrics.maybeMinPixels, + controller.metrics.maybeMaxPixels, ); }); @@ -472,10 +472,13 @@ void main() { ), ); - expect(controller.value.pixels, 200, + expect(controller.metrics.pixels, 200, reason: 'The sheet should be at the initial extent.'); - expect(controller.value.minPixels < controller.value.maxPixels, isTrue, - reason: 'The sheet should be draggable.'); + expect( + controller.metrics.minPixels < controller.metrics.maxPixels, + isTrue, + reason: 'The sheet should be draggable.', + ); // Start animating the sheet to the max extent. unawaited( @@ -493,8 +496,8 @@ void main() { expect(MediaQuery.viewInsetsOf(sheetKey.currentContext!).bottom, 200, reason: 'The keyboard should be fully shown.'); expect( - controller.value.pixels, - controller.value.maxPixels, + controller.metrics.pixels, + controller.metrics.maxPixels, reason: 'After the keyboard is fully shown, ' 'the entire sheet should also be visible.', ); diff --git a/test/scrollable/scrollable_sheet_test.dart b/test/scrollable/scrollable_sheet_test.dart index cc7ddf4..5f4769b 100644 --- a/test/scrollable/scrollable_sheet_test.dart +++ b/test/scrollable/scrollable_sheet_test.dart @@ -114,9 +114,9 @@ void main() { ), ); - expect(controller.value.pixels, 200, + expect(controller.metrics.pixels, 200, reason: 'The sheet should be at the initial extent.'); - expect(controller.value.minPixels < controller.value.maxPixels, isTrue, + expect(controller.metrics.minPixels < controller.metrics.maxPixels, isTrue, reason: 'The sheet should be draggable.'); // Start animating the sheet to the max extent. @@ -135,8 +135,8 @@ void main() { expect(MediaQuery.viewInsetsOf(sheetKey.currentContext!).bottom, 200, reason: 'The keyboard should be fully shown.'); expect( - controller.value.pixels, - controller.value.maxPixels, + controller.metrics.pixels, + controller.metrics.maxPixels, reason: 'After the keyboard is fully shown, ' 'the entire sheet should also be visible.', ); From 3f34ea0f3e6f7869c704bbfd31771d6bee9b04ae Mon Sep 17 00:00:00 2001 From: fujidaiti Date: Wed, 25 Sep 2024 23:32:17 +0900 Subject: [PATCH 05/22] Rename sheet_extent to sheet_position --- lib/src/draggable/draggable_sheet.dart | 2 +- lib/src/draggable/draggable_sheet_extent.dart | 2 +- .../draggable/draggable_sheet_extent_scope.dart | 2 +- lib/src/draggable/sheet_draggable.dart | 2 +- lib/src/foundation/extent_driven_animation.dart | 2 +- lib/src/foundation/foundation.dart | 14 +++++++------- lib/src/foundation/sheet_activity.dart | 2 +- lib/src/foundation/sheet_content_scaffold.dart | 2 +- lib/src/foundation/sheet_context.dart | 2 +- lib/src/foundation/sheet_controller.dart | 2 +- lib/src/foundation/sheet_extent_scope.dart | 2 +- lib/src/foundation/sheet_notification.dart | 2 +- lib/src/foundation/sheet_physics.dart | 2 +- .../{sheet_extent.dart => sheet_position.dart} | 0 lib/src/foundation/sheet_viewport.dart | 2 +- lib/src/navigation/navigation_route.dart | 2 +- lib/src/navigation/navigation_routes.dart | 2 +- lib/src/navigation/navigation_sheet_extent.dart | 2 +- .../navigation/navigation_sheet_extent_scope.dart | 2 +- lib/src/navigation/navigation_sheet_viewport.dart | 2 +- lib/src/scrollable/scrollable_sheet.dart | 2 +- lib/src/scrollable/scrollable_sheet_extent.dart | 2 +- .../scrollable/scrollable_sheet_extent_scope.dart | 2 +- lib/src/scrollable/scrollable_sheet_physics.dart | 2 +- test/foundation/sheet_notification_test.dart | 2 +- test/foundation/sheet_viewport_test.dart | 2 +- test/src/stubbing.dart | 2 +- test/src/stubbing.mocks.dart | 2 +- 28 files changed, 33 insertions(+), 33 deletions(-) rename lib/src/foundation/{sheet_extent.dart => sheet_position.dart} (100%) diff --git a/lib/src/draggable/draggable_sheet.dart b/lib/src/draggable/draggable_sheet.dart index e3bf6b7..a3739c7 100644 --- a/lib/src/draggable/draggable_sheet.dart +++ b/lib/src/draggable/draggable_sheet.dart @@ -3,9 +3,9 @@ import 'package:flutter/widgets.dart'; import '../foundation/sheet_context.dart'; import '../foundation/sheet_controller.dart'; -import '../foundation/sheet_extent.dart'; import '../foundation/sheet_gesture_tamperer.dart'; import '../foundation/sheet_physics.dart'; +import '../foundation/sheet_position.dart'; import '../foundation/sheet_theme.dart'; import '../foundation/sheet_viewport.dart'; import '../scrollable/scrollable_sheet.dart'; diff --git a/lib/src/draggable/draggable_sheet_extent.dart b/lib/src/draggable/draggable_sheet_extent.dart index 292e895..a411d7c 100644 --- a/lib/src/draggable/draggable_sheet_extent.dart +++ b/lib/src/draggable/draggable_sheet_extent.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:meta/meta.dart'; -import '../foundation/sheet_extent.dart'; +import '../foundation/sheet_position.dart'; @internal class DraggableSheetExtent extends SheetExtent { diff --git a/lib/src/draggable/draggable_sheet_extent_scope.dart b/lib/src/draggable/draggable_sheet_extent_scope.dart index a4dda2b..5b38fe7 100644 --- a/lib/src/draggable/draggable_sheet_extent_scope.dart +++ b/lib/src/draggable/draggable_sheet_extent_scope.dart @@ -1,8 +1,8 @@ import 'package:meta/meta.dart'; import '../foundation/sheet_context.dart'; -import '../foundation/sheet_extent.dart'; import '../foundation/sheet_extent_scope.dart'; +import '../foundation/sheet_position.dart'; import 'draggable_sheet_extent.dart'; @internal diff --git a/lib/src/draggable/sheet_draggable.dart b/lib/src/draggable/sheet_draggable.dart index 554c694..23c6351 100644 --- a/lib/src/draggable/sheet_draggable.dart +++ b/lib/src/draggable/sheet_draggable.dart @@ -2,8 +2,8 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/widgets.dart'; -import '../foundation/sheet_extent.dart'; import '../foundation/sheet_extent_scope.dart'; +import '../foundation/sheet_position.dart'; import '../scrollable/scrollable_sheet.dart'; import 'draggable_sheet.dart'; diff --git a/lib/src/foundation/extent_driven_animation.dart b/lib/src/foundation/extent_driven_animation.dart index 7a98601..7e85d3d 100644 --- a/lib/src/foundation/extent_driven_animation.dart +++ b/lib/src/foundation/extent_driven_animation.dart @@ -1,7 +1,7 @@ import 'package:flutter/animation.dart'; import 'sheet_controller.dart'; -import 'sheet_extent.dart'; +import 'sheet_position.dart'; class ExtentDrivenAnimation extends Animation { ExtentDrivenAnimation({ diff --git a/lib/src/foundation/foundation.dart b/lib/src/foundation/foundation.dart index 8228936..a76a8fe 100644 --- a/lib/src/foundation/foundation.dart +++ b/lib/src/foundation/foundation.dart @@ -23,13 +23,6 @@ export 'sheet_drag.dart' SheetDragEndDetails, SheetDragStartDetails, SheetDragUpdateDetails; -export 'sheet_extent.dart' - show - Extent, - FixedExtent, - ProportionalExtent, - SheetMetrics, - SheetMetricsSnapshot; export 'sheet_notification.dart' show SheetDragCancelNotification, @@ -54,5 +47,12 @@ export 'sheet_physics.dart' SnappingSheetPhysics, kDefaultSheetPhysics, kDefaultSheetSpring; +export 'sheet_position.dart' + show + Extent, + FixedExtent, + ProportionalExtent, + SheetMetrics, + SheetMetricsSnapshot; export 'sheet_status.dart' show SheetStatus; export 'sheet_theme.dart' show SheetTheme, SheetThemeData; diff --git a/lib/src/foundation/sheet_activity.dart b/lib/src/foundation/sheet_activity.dart index 22f99b2..e7316ac 100644 --- a/lib/src/foundation/sheet_activity.dart +++ b/lib/src/foundation/sheet_activity.dart @@ -7,8 +7,8 @@ import 'package:flutter/widgets.dart'; import 'package:meta/meta.dart'; import 'sheet_drag.dart'; -import 'sheet_extent.dart'; import 'sheet_physics.dart'; +import 'sheet_position.dart'; import 'sheet_status.dart'; @internal diff --git a/lib/src/foundation/sheet_content_scaffold.dart b/lib/src/foundation/sheet_content_scaffold.dart index 043ab26..35c1548 100644 --- a/lib/src/foundation/sheet_content_scaffold.dart +++ b/lib/src/foundation/sheet_content_scaffold.dart @@ -4,8 +4,8 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import '../draggable/sheet_draggable.dart'; -import 'sheet_extent.dart'; import 'sheet_extent_scope.dart'; +import 'sheet_position.dart'; import 'sheet_viewport.dart'; class SheetContentScaffold extends StatelessWidget { diff --git a/lib/src/foundation/sheet_context.dart b/lib/src/foundation/sheet_context.dart index b42fb4c..701a985 100644 --- a/lib/src/foundation/sheet_context.dart +++ b/lib/src/foundation/sheet_context.dart @@ -1,7 +1,7 @@ import 'package:flutter/widgets.dart'; import 'package:meta/meta.dart'; -import 'sheet_extent.dart'; +import 'sheet_position.dart'; /// An interface that provides a set of dependencies required by [SheetExtent]. @internal diff --git a/lib/src/foundation/sheet_controller.dart b/lib/src/foundation/sheet_controller.dart index d56327e..2dc6466 100644 --- a/lib/src/foundation/sheet_controller.dart +++ b/lib/src/foundation/sheet_controller.dart @@ -4,7 +4,7 @@ import 'package:flutter/widgets.dart'; import 'package:meta/meta.dart'; import 'foundation.dart'; -import 'sheet_extent.dart'; +import 'sheet_position.dart'; class SheetController extends ChangeNotifier implements ValueListenable { diff --git a/lib/src/foundation/sheet_extent_scope.dart b/lib/src/foundation/sheet_extent_scope.dart index 655f48d..2cb92cd 100644 --- a/lib/src/foundation/sheet_extent_scope.dart +++ b/lib/src/foundation/sheet_extent_scope.dart @@ -5,9 +5,9 @@ import 'package:meta/meta.dart'; import 'sheet_context.dart'; import 'sheet_controller.dart'; -import 'sheet_extent.dart'; import 'sheet_gesture_tamperer.dart'; import 'sheet_physics.dart'; +import 'sheet_position.dart'; @internal @optionalTypeArgs diff --git a/lib/src/foundation/sheet_notification.dart b/lib/src/foundation/sheet_notification.dart index 301a7a1..6d45ae1 100644 --- a/lib/src/foundation/sheet_notification.dart +++ b/lib/src/foundation/sheet_notification.dart @@ -1,8 +1,8 @@ import 'package:flutter/widgets.dart'; import 'sheet_drag.dart'; -import 'sheet_extent.dart'; import 'sheet_physics.dart'; +import 'sheet_position.dart'; import 'sheet_status.dart'; /// A [Notification] that is dispatched when the sheet extent changes. diff --git a/lib/src/foundation/sheet_physics.dart b/lib/src/foundation/sheet_physics.dart index eaa4b50..274de66 100644 --- a/lib/src/foundation/sheet_physics.dart +++ b/lib/src/foundation/sheet_physics.dart @@ -7,7 +7,7 @@ import 'package:flutter/widgets.dart'; import '../internal/double_utils.dart'; import '../internal/float_comp.dart'; -import 'sheet_extent.dart'; +import 'sheet_position.dart'; /// The default [SpringDescription] used by [SheetPhysics] subclasses. /// diff --git a/lib/src/foundation/sheet_extent.dart b/lib/src/foundation/sheet_position.dart similarity index 100% rename from lib/src/foundation/sheet_extent.dart rename to lib/src/foundation/sheet_position.dart diff --git a/lib/src/foundation/sheet_viewport.dart b/lib/src/foundation/sheet_viewport.dart index e69c261..fbafb3d 100644 --- a/lib/src/foundation/sheet_viewport.dart +++ b/lib/src/foundation/sheet_viewport.dart @@ -4,8 +4,8 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; import 'package:meta/meta.dart'; -import 'sheet_extent.dart'; import 'sheet_extent_scope.dart'; +import 'sheet_position.dart'; @internal class SheetViewport extends SingleChildRenderObjectWidget { diff --git a/lib/src/navigation/navigation_route.dart b/lib/src/navigation/navigation_route.dart index 0f5fb18..a683f2e 100644 --- a/lib/src/navigation/navigation_route.dart +++ b/lib/src/navigation/navigation_route.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import '../foundation/sheet_context.dart'; -import '../foundation/sheet_extent.dart'; import '../foundation/sheet_extent_scope.dart'; +import '../foundation/sheet_position.dart'; import '../foundation/sheet_viewport.dart'; import 'navigation_sheet.dart'; import 'navigation_sheet_extent.dart'; diff --git a/lib/src/navigation/navigation_routes.dart b/lib/src/navigation/navigation_routes.dart index a0596f7..5bcb4ab 100644 --- a/lib/src/navigation/navigation_routes.dart +++ b/lib/src/navigation/navigation_routes.dart @@ -4,10 +4,10 @@ import 'package:flutter/material.dart'; import '../draggable/draggable_sheet_extent.dart'; import '../draggable/draggable_sheet_extent_scope.dart'; import '../draggable/sheet_draggable.dart'; -import '../foundation/sheet_extent.dart'; import '../foundation/sheet_extent_scope.dart'; import '../foundation/sheet_gesture_tamperer.dart'; import '../foundation/sheet_physics.dart'; +import '../foundation/sheet_position.dart'; import '../foundation/sheet_theme.dart'; import '../scrollable/scrollable_sheet.dart'; import '../scrollable/scrollable_sheet_extent.dart'; diff --git a/lib/src/navigation/navigation_sheet_extent.dart b/lib/src/navigation/navigation_sheet_extent.dart index cd197fb..87f7aad 100644 --- a/lib/src/navigation/navigation_sheet_extent.dart +++ b/lib/src/navigation/navigation_sheet_extent.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; import 'package:meta/meta.dart'; import '../foundation/sheet_drag.dart'; -import '../foundation/sheet_extent.dart'; +import '../foundation/sheet_position.dart'; import '../internal/transition_observer.dart'; import 'navigation_route.dart'; import 'navigation_sheet_activity.dart'; diff --git a/lib/src/navigation/navigation_sheet_extent_scope.dart b/lib/src/navigation/navigation_sheet_extent_scope.dart index b0a8895..823d600 100644 --- a/lib/src/navigation/navigation_sheet_extent_scope.dart +++ b/lib/src/navigation/navigation_sheet_extent_scope.dart @@ -1,9 +1,9 @@ import 'package:meta/meta.dart'; import '../foundation/sheet_context.dart'; -import '../foundation/sheet_extent.dart'; import '../foundation/sheet_extent_scope.dart'; import '../foundation/sheet_physics.dart'; +import '../foundation/sheet_position.dart'; import 'navigation_sheet_extent.dart'; @internal diff --git a/lib/src/navigation/navigation_sheet_viewport.dart b/lib/src/navigation/navigation_sheet_viewport.dart index 0d768ae..7bebe49 100644 --- a/lib/src/navigation/navigation_sheet_viewport.dart +++ b/lib/src/navigation/navigation_sheet_viewport.dart @@ -2,8 +2,8 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; import 'package:meta/meta.dart'; -import '../foundation/sheet_extent.dart'; import '../foundation/sheet_extent_scope.dart'; +import '../foundation/sheet_position.dart'; import '../foundation/sheet_viewport.dart'; @internal diff --git a/lib/src/scrollable/scrollable_sheet.dart b/lib/src/scrollable/scrollable_sheet.dart index 8a61eee..ab9d036 100644 --- a/lib/src/scrollable/scrollable_sheet.dart +++ b/lib/src/scrollable/scrollable_sheet.dart @@ -5,9 +5,9 @@ import 'package:meta/meta.dart'; import '../foundation/sheet_context.dart'; import '../foundation/sheet_controller.dart'; -import '../foundation/sheet_extent.dart'; import '../foundation/sheet_gesture_tamperer.dart'; import '../foundation/sheet_physics.dart'; +import '../foundation/sheet_position.dart'; import '../foundation/sheet_theme.dart'; import '../foundation/sheet_viewport.dart'; import 'scrollable_sheet_extent_scope.dart'; diff --git a/lib/src/scrollable/scrollable_sheet_extent.dart b/lib/src/scrollable/scrollable_sheet_extent.dart index 67fd785..03fa6df 100644 --- a/lib/src/scrollable/scrollable_sheet_extent.dart +++ b/lib/src/scrollable/scrollable_sheet_extent.dart @@ -5,8 +5,8 @@ import 'package:flutter/material.dart'; import 'package:meta/meta.dart'; import '../foundation/sheet_drag.dart'; -import '../foundation/sheet_extent.dart'; import '../foundation/sheet_physics.dart'; +import '../foundation/sheet_position.dart'; import '../internal/float_comp.dart'; import 'scrollable_sheet_activity.dart'; import 'scrollable_sheet_physics.dart'; diff --git a/lib/src/scrollable/scrollable_sheet_extent_scope.dart b/lib/src/scrollable/scrollable_sheet_extent_scope.dart index faef07a..506c466 100644 --- a/lib/src/scrollable/scrollable_sheet_extent_scope.dart +++ b/lib/src/scrollable/scrollable_sheet_extent_scope.dart @@ -1,8 +1,8 @@ import 'package:meta/meta.dart'; import '../foundation/sheet_context.dart'; -import '../foundation/sheet_extent.dart'; import '../foundation/sheet_extent_scope.dart'; +import '../foundation/sheet_position.dart'; import 'scrollable_sheet_extent.dart'; @internal diff --git a/lib/src/scrollable/scrollable_sheet_physics.dart b/lib/src/scrollable/scrollable_sheet_physics.dart index 7ea0a23..0c07f99 100644 --- a/lib/src/scrollable/scrollable_sheet_physics.dart +++ b/lib/src/scrollable/scrollable_sheet_physics.dart @@ -1,8 +1,8 @@ import 'package:flutter/physics.dart'; import 'package:meta/meta.dart'; -import '../foundation/sheet_extent.dart'; import '../foundation/sheet_physics.dart'; +import '../foundation/sheet_position.dart'; @internal class ScrollableSheetPhysics extends SheetPhysics with SheetPhysicsMixin { diff --git a/test/foundation/sheet_notification_test.dart b/test/foundation/sheet_notification_test.dart index 8fe7d21..3406b25 100644 --- a/test/foundation/sheet_notification_test.dart +++ b/test/foundation/sheet_notification_test.dart @@ -5,9 +5,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:smooth_sheets/src/draggable/draggable_sheet.dart'; import 'package:smooth_sheets/src/foundation/sheet_controller.dart'; -import 'package:smooth_sheets/src/foundation/sheet_extent.dart'; import 'package:smooth_sheets/src/foundation/sheet_notification.dart'; import 'package:smooth_sheets/src/foundation/sheet_physics.dart'; +import 'package:smooth_sheets/src/foundation/sheet_position.dart'; import 'package:smooth_sheets/src/foundation/sheet_status.dart'; void main() { diff --git a/test/foundation/sheet_viewport_test.dart b/test/foundation/sheet_viewport_test.dart index abfae01..8f4c9ea 100644 --- a/test/foundation/sheet_viewport_test.dart +++ b/test/foundation/sheet_viewport_test.dart @@ -2,9 +2,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:smooth_sheets/src/foundation/sheet_activity.dart'; import 'package:smooth_sheets/src/foundation/sheet_context.dart'; -import 'package:smooth_sheets/src/foundation/sheet_extent.dart'; import 'package:smooth_sheets/src/foundation/sheet_extent_scope.dart'; import 'package:smooth_sheets/src/foundation/sheet_physics.dart'; +import 'package:smooth_sheets/src/foundation/sheet_position.dart'; import 'package:smooth_sheets/src/foundation/sheet_status.dart'; import 'package:smooth_sheets/src/foundation/sheet_viewport.dart'; diff --git a/test/src/stubbing.dart b/test/src/stubbing.dart index 835dab9..be29f13 100644 --- a/test/src/stubbing.dart +++ b/test/src/stubbing.dart @@ -4,7 +4,7 @@ import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:smooth_sheets/src/foundation/foundation.dart'; import 'package:smooth_sheets/src/foundation/sheet_context.dart'; -import 'package:smooth_sheets/src/foundation/sheet_extent.dart'; +import 'package:smooth_sheets/src/foundation/sheet_position.dart'; @GenerateNiceMocks([ MockSpec(), diff --git a/test/src/stubbing.mocks.dart b/test/src/stubbing.mocks.dart index 1785d51..9ee2439 100644 --- a/test/src/stubbing.mocks.dart +++ b/test/src/stubbing.mocks.dart @@ -16,7 +16,7 @@ import 'package:mockito/src/dummies.dart' as _i16; import 'package:smooth_sheets/src/foundation/sheet_activity.dart' as _i5; import 'package:smooth_sheets/src/foundation/sheet_context.dart' as _i2; import 'package:smooth_sheets/src/foundation/sheet_drag.dart' as _i12; -import 'package:smooth_sheets/src/foundation/sheet_extent.dart' as _i4; +import 'package:smooth_sheets/src/foundation/sheet_position.dart' as _i4; import 'package:smooth_sheets/src/foundation/sheet_gesture_tamperer.dart' as _i14; import 'package:smooth_sheets/src/foundation/sheet_physics.dart' as _i3; From 3ce9efc0bc07a1396609cb5a1283aeef57802fda Mon Sep 17 00:00:00 2001 From: fujidaiti Date: Thu, 26 Sep 2024 15:34:23 +0900 Subject: [PATCH 06/22] Rename SheetExtent to SheetPosition --- lib/src/draggable/draggable_sheet_extent.dart | 2 +- lib/src/draggable/sheet_draggable.dart | 2 +- lib/src/foundation/sheet_activity.dart | 19 +++++++++--------- .../foundation/sheet_content_scaffold.dart | 8 ++++---- lib/src/foundation/sheet_context.dart | 3 ++- lib/src/foundation/sheet_controller.dart | 16 +++++++-------- lib/src/foundation/sheet_extent_scope.dart | 20 +++++++++---------- lib/src/foundation/sheet_physics.dart | 4 ++-- lib/src/foundation/sheet_position.dart | 12 +++++------ lib/src/foundation/sheet_viewport.dart | 14 ++++++------- lib/src/navigation/navigation_route.dart | 2 +- .../navigation/navigation_sheet_extent.dart | 4 ++-- .../navigation/navigation_sheet_viewport.dart | 6 +++--- .../scrollable/scrollable_sheet_extent.dart | 4 ++-- test/foundation/sheet_viewport_test.dart | 6 +++--- test/src/stubbing.dart | 2 +- test/src/stubbing.mocks.dart | 18 ++++++++--------- 17 files changed, 72 insertions(+), 70 deletions(-) diff --git a/lib/src/draggable/draggable_sheet_extent.dart b/lib/src/draggable/draggable_sheet_extent.dart index a411d7c..ecd8b10 100644 --- a/lib/src/draggable/draggable_sheet_extent.dart +++ b/lib/src/draggable/draggable_sheet_extent.dart @@ -5,7 +5,7 @@ import 'package:meta/meta.dart'; import '../foundation/sheet_position.dart'; @internal -class DraggableSheetExtent extends SheetExtent { +class DraggableSheetExtent extends SheetPosition { DraggableSheetExtent({ required super.context, required super.minExtent, diff --git a/lib/src/draggable/sheet_draggable.dart b/lib/src/draggable/sheet_draggable.dart index 23c6351..6d354db 100644 --- a/lib/src/draggable/sheet_draggable.dart +++ b/lib/src/draggable/sheet_draggable.dart @@ -41,7 +41,7 @@ class SheetDraggable extends StatefulWidget { } class _SheetDraggableState extends State { - SheetExtent? _extent; + SheetPosition? _extent; Drag? _currentDrag; @override diff --git a/lib/src/foundation/sheet_activity.dart b/lib/src/foundation/sheet_activity.dart index e7316ac..dee51a2 100644 --- a/lib/src/foundation/sheet_activity.dart +++ b/lib/src/foundation/sheet_activity.dart @@ -13,7 +13,7 @@ import 'sheet_status.dart'; @internal @optionalTypeArgs -abstract class SheetActivity { +abstract class SheetActivity { bool _disposed = false; bool get disposed { assert(!_mounted || !_disposed); @@ -60,7 +60,7 @@ abstract class SheetActivity { /// this activity. bool get shouldIgnorePointer => false; - bool isCompatibleWith(SheetExtent newOwner) => newOwner is T; + bool isCompatibleWith(SheetPosition newOwner) => newOwner is T; void didChangeContentSize(Size? oldSize) {} @@ -125,7 +125,7 @@ abstract class SheetActivity { } } -/// An activity that animates the [SheetExtent]'s `pixels` to a destination +/// An activity that animates the [SheetPosition]'s `pixels` to a destination /// position determined by [destination], using the specified [curve] and /// [duration]. /// @@ -156,7 +156,7 @@ class AnimatedSheetActivity extends SheetActivity late final double _endPixels; @override - void init(SheetExtent delegate) { + void init(SheetPosition delegate) { super.init(delegate); _startPixels = owner.pixels; _endPixels = destination.resolve(owner.contentSize); @@ -287,7 +287,7 @@ class BallisticSheetActivity extends SheetActivity /// A [SheetActivity] that performs a settling motion in response to changes /// in the viewport dimensions or content size. /// -/// A [SheetExtent] may start this activity when the viewport insets change +/// A [SheetPosition] may start this activity when the viewport insets change /// during an animation, typically due to the appearance or disappearance of /// the on-screen keyboard, or when the content size changes (e.g., due to /// entering a new line of text in a text field). @@ -343,7 +343,7 @@ class SettlingSheetActivity extends SheetActivity { SheetStatus get status => SheetStatus.animating; @override - void init(SheetExtent owner) { + void init(SheetPosition owner) { super.init(owner); _ticker = owner.context.vsync.createTicker(_tick)..start(); _invalidateVelocity(); @@ -538,7 +538,8 @@ class DragSheetActivity extends SheetActivity @internal @optionalTypeArgs -mixin ControlledSheetActivityMixin on SheetActivity { +mixin ControlledSheetActivityMixin + on SheetActivity { late final AnimationController controller; final _completer = Completer(); @@ -574,7 +575,7 @@ mixin ControlledSheetActivityMixin on SheetActivity { @internal @optionalTypeArgs -mixin UserControlledSheetActivityMixin +mixin UserControlledSheetActivityMixin on SheetActivity { @override SheetStatus get status => SheetStatus.dragging; @@ -599,7 +600,7 @@ mixin UserControlledSheetActivityMixin /// `pixels` to maintain the visual sheet position. @internal void absorbBottomViewportInset( - SheetExtent activityOwner, + SheetPosition activityOwner, EdgeInsets oldViewportInsets, ) { final newInsets = activityOwner.viewportInsets; diff --git a/lib/src/foundation/sheet_content_scaffold.dart b/lib/src/foundation/sheet_content_scaffold.dart index 35c1548..1f6f4c4 100644 --- a/lib/src/foundation/sheet_content_scaffold.dart +++ b/lib/src/foundation/sheet_content_scaffold.dart @@ -222,15 +222,15 @@ abstract class BottomBarVisibility implements Widget { abstract class _RenderBottomBarVisibility extends RenderTransform { _RenderBottomBarVisibility({ - required SheetExtent extent, + required SheetPosition extent, }) : _extent = extent, super(transform: Matrix4.zero(), transformHitTests: true) { _extent.addListener(invalidateVisibility); } - SheetExtent _extent; + SheetPosition _extent; // ignore: avoid_setters_without_getters - set extent(SheetExtent value) { + set extent(SheetPosition value) { if (_extent != value) { _extent.removeListener(invalidateVisibility); _extent = value..addListener(invalidateVisibility); @@ -558,7 +558,7 @@ class _ConditionalStickyBottomBarVisibilityState with SingleTickerProviderStateMixin { late final AnimationController _controller; late Animation _curveAnimation; - SheetExtent? _extent; + SheetPosition? _extent; @override void initState() { diff --git a/lib/src/foundation/sheet_context.dart b/lib/src/foundation/sheet_context.dart index 701a985..d3d222a 100644 --- a/lib/src/foundation/sheet_context.dart +++ b/lib/src/foundation/sheet_context.dart @@ -3,7 +3,8 @@ import 'package:meta/meta.dart'; import 'sheet_position.dart'; -/// An interface that provides a set of dependencies required by [SheetExtent]. +/// An interface that provides a set of dependencies +/// required by [SheetPosition]. @internal abstract class SheetContext { TickerProvider get vsync; diff --git a/lib/src/foundation/sheet_controller.dart b/lib/src/foundation/sheet_controller.dart index 2dc6466..3176514 100644 --- a/lib/src/foundation/sheet_controller.dart +++ b/lib/src/foundation/sheet_controller.dart @@ -8,7 +8,7 @@ import 'sheet_position.dart'; class SheetController extends ChangeNotifier implements ValueListenable { - SheetExtent? _client; + SheetPosition? _client; /// A notifier which notifies listeners immediately when the [_client] fires. /// @@ -19,8 +19,8 @@ class SheetController extends ChangeNotifier /// The current sheet position. /// - /// Returns [SheetExtent.value] of the attached [SheetExtent], - /// or `null` if no [SheetExtent] is attached. + /// Returns [SheetPosition.value] of the attached [SheetPosition], + /// or `null` if no [SheetPosition] is attached. @override double? get value => _client?.value; @@ -28,11 +28,11 @@ class SheetController extends ChangeNotifier /// The current metrics of the sheet. /// - /// Returns [SheetExtent.snapshot] of the attached [SheetExtent], - /// or [SheetMetrics.empty] if no [SheetExtent] is attached. + /// Returns [SheetPosition.snapshot] of the attached [SheetPosition], + /// or [SheetMetrics.empty] if no [SheetPosition] is attached. SheetMetrics get metrics => _client?.snapshot ?? SheetMetrics.empty; - /// Whether a [SheetExtent] is attached to this controller. + /// Whether a [SheetPosition] is attached to this controller. bool get hasClient => _client != null; @override @@ -50,7 +50,7 @@ class SheetController extends ChangeNotifier super.removeListener(listener); } - void attach(SheetExtent extent) { + void attach(SheetPosition extent) { if (_client case final oldExtent?) { detach(oldExtent); } @@ -58,7 +58,7 @@ class SheetController extends ChangeNotifier _client = extent..addListener(notifyListeners); } - void detach(SheetExtent? extent) { + void detach(SheetPosition? extent) { if (extent == _client) { extent?.removeListener(notifyListeners); _client = null; diff --git a/lib/src/foundation/sheet_extent_scope.dart b/lib/src/foundation/sheet_extent_scope.dart index 2cb92cd..a55e0d6 100644 --- a/lib/src/foundation/sheet_extent_scope.dart +++ b/lib/src/foundation/sheet_extent_scope.dart @@ -11,7 +11,7 @@ import 'sheet_position.dart'; @internal @optionalTypeArgs -class SheetExtentScopeKey +class SheetExtentScopeKey extends LabeledGlobalKey { SheetExtentScopeKey({String? debugLabel}) : super(debugLabel); @@ -46,12 +46,12 @@ class SheetExtentScopeKey } } -/// A widget that creates a [SheetExtent], manages its lifecycle, +/// A widget that creates a [SheetPosition], manages its lifecycle, /// and exposes it to the descendant widgets. @internal @optionalTypeArgs abstract class SheetExtentScope extends StatefulWidget { - /// Creates a widget that hosts a [SheetExtent]. + /// Creates a widget that hosts a [SheetPosition]. const SheetExtentScope({ super.key, required this.context, @@ -67,7 +67,7 @@ abstract class SheetExtentScope extends StatefulWidget { /// The context the extent object belongs to. final SheetContext context; - /// The [SheetController] attached to the [SheetExtent]. + /// The [SheetController] attached to the [SheetPosition]. final SheetController? controller; /// {@macro SheetExtent.minExtent} @@ -91,10 +91,10 @@ abstract class SheetExtentScope extends StatefulWidget { @override SheetExtentScopeState createState(); - /// Retrieves a [SheetExtent] from the closest [SheetExtentScope] + /// Retrieves a [SheetPosition] from the closest [SheetExtentScope] /// that encloses the given context, if any. // TODO: Add 'useRoot' option. - static E? maybeOf(BuildContext context) { + static E? maybeOf(BuildContext context) { final inherited = context .dependOnInheritedWidgetOfExactType() ?.extent; @@ -102,9 +102,9 @@ abstract class SheetExtentScope extends StatefulWidget { return inherited is E ? inherited : null; } - /// Retrieves a [SheetExtent] from the closest [SheetExtentScope] + /// Retrieves a [SheetPosition] from the closest [SheetExtentScope] /// that encloses the given context. - static E of(BuildContext context) { + static E of(BuildContext context) { final extent = maybeOf(context); assert(() { @@ -124,7 +124,7 @@ abstract class SheetExtentScope extends StatefulWidget { } @internal -abstract class SheetExtentScopeState extends State { late E _extent; SheetController? _controller; @@ -260,7 +260,7 @@ class InheritedSheetExtentScope extends InheritedWidget { required super.child, }); - final SheetExtent extent; + final SheetPosition extent; final bool isPrimary; @override diff --git a/lib/src/foundation/sheet_physics.dart b/lib/src/foundation/sheet_physics.dart index 274de66..1dc07a4 100644 --- a/lib/src/foundation/sheet_physics.dart +++ b/lib/src/foundation/sheet_physics.dart @@ -182,8 +182,8 @@ abstract interface class SnappingSheetBehavior { /// it will snap to [SheetMetrics.maxPixels]. /// /// Using this behavior is functionally identical to using [SnapToNearest] -/// with the snap positions of [SheetExtent.minExtent] and -/// [SheetExtent.maxExtent], but more simplified and efficient. +/// with the snap positions of [SheetPosition.minExtent] and +/// [SheetPosition.maxExtent], but more simplified and efficient. class SnapToNearestEdge implements SnappingSheetBehavior { /// Creates a [SnappingSheetBehavior] that snaps to either /// [SheetMetrics.minPixels] or [SheetMetrics.maxPixels]. diff --git a/lib/src/foundation/sheet_position.dart b/lib/src/foundation/sheet_position.dart index dd28a81..434b771 100644 --- a/lib/src/foundation/sheet_position.dart +++ b/lib/src/foundation/sheet_position.dart @@ -103,12 +103,12 @@ class FixedExtent implements Extent { /// As this value changes, the sheet translates its position, which changes the /// visible area of the content. The [SheetMetrics.minPixels] and /// [SheetMetrics.maxPixels] values limit the range of the *pixels*, but it can -/// be outside of the range if the [SheetExtent.physics] allows it. +/// be outside of the range if the [SheetPosition.physics] allows it. /// /// The current [activity] is responsible for how the *pixels* changes /// over time, for example, [AnimatedSheetActivity] animates the *pixels* to /// a target value, and [IdleSheetActivity] keeps the *pixels* unchanged. -/// [SheetExtent] starts with [IdleSheetActivity] as the initial activity, +/// [SheetPosition] starts with [IdleSheetActivity] as the initial activity, /// and it can be changed by calling [beginActivity]. /// /// This object is [Listenable] that notifies its listeners when *pixels* @@ -118,15 +118,15 @@ class FixedExtent implements Extent { /// /// See also: /// - [SheetController], which can be attached to a sheet to control its extent. -/// - [SheetExtentScope], which creates a [SheetExtent], manages its lifecycle, +/// - [SheetExtentScope], which creates a [SheetPosition], manages its lifecycle /// and exposes it to the descendant widgets. @internal @optionalTypeArgs -abstract class SheetExtent extends ChangeNotifier +abstract class SheetPosition extends ChangeNotifier with SheetMetrics implements ValueListenable { /// Creates an object that manages the extent of a sheet. - SheetExtent({ + SheetPosition({ required this.context, required Extent minExtent, required Extent maxExtent, @@ -229,7 +229,7 @@ abstract class SheetExtent extends ChangeNotifier } @mustCallSuper - void takeOver(SheetExtent other) { + void takeOver(SheetPosition other) { assert(currentDrag == null); if (other.activity.isCompatibleWith(this)) { activity.dispose(); diff --git a/lib/src/foundation/sheet_viewport.dart b/lib/src/foundation/sheet_viewport.dart index fbafb3d..9f14ac8 100644 --- a/lib/src/foundation/sheet_viewport.dart +++ b/lib/src/foundation/sheet_viewport.dart @@ -32,7 +32,7 @@ class SheetViewport extends SingleChildRenderObjectWidget { @internal class RenderSheetViewport extends RenderTransform { - RenderSheetViewport(SheetExtent extent, EdgeInsets insets) + RenderSheetViewport(SheetPosition extent, EdgeInsets insets) : _extent = extent, _insets = insets, super(transform: Matrix4.zero(), transformHitTests: true) { @@ -44,9 +44,9 @@ class RenderSheetViewport extends RenderTransform { Size? _lastMeasuredSize; Size? get lastMeasuredSize => _lastMeasuredSize; - SheetExtent _extent; + SheetPosition _extent; // ignore: avoid_setters_without_getters - set extent(SheetExtent value) { + set extent(SheetPosition value) { if (_extent != value) { _extent.removeListener(_invalidateTranslationValue); _extent = value..addListener(_invalidateTranslationValue); @@ -217,7 +217,7 @@ class _SheetContentLayoutObserver extends SingleChildRenderObjectWidget { }); final ValueGetter isEnabled; - final SheetExtent? extent; + final SheetPosition? extent; @override RenderObject createRenderObject(BuildContext context) { @@ -238,14 +238,14 @@ class _SheetContentLayoutObserver extends SingleChildRenderObjectWidget { class _RenderSheetContentLayoutObserver extends RenderPositionedBox { _RenderSheetContentLayoutObserver({ required ValueGetter isEnabled, - required SheetExtent? extent, + required SheetPosition? extent, }) : _isEnabled = isEnabled, _extent = extent, super(alignment: Alignment.topCenter); - SheetExtent? _extent; + SheetPosition? _extent; // ignore: avoid_setters_without_getters - set extent(SheetExtent? value) { + set extent(SheetPosition? value) { if (_extent != value) { _extent = value; markNeedsLayout(); diff --git a/lib/src/navigation/navigation_route.dart b/lib/src/navigation/navigation_route.dart index a683f2e..735b91e 100644 --- a/lib/src/navigation/navigation_route.dart +++ b/lib/src/navigation/navigation_route.dart @@ -9,7 +9,7 @@ import 'navigation_sheet_extent.dart'; import 'navigation_sheet_viewport.dart'; @optionalTypeArgs -abstract class NavigationSheetRoute +abstract class NavigationSheetRoute extends PageRoute { NavigationSheetRoute({super.settings}); diff --git a/lib/src/navigation/navigation_sheet_extent.dart b/lib/src/navigation/navigation_sheet_extent.dart index 87f7aad..c230cc0 100644 --- a/lib/src/navigation/navigation_sheet_extent.dart +++ b/lib/src/navigation/navigation_sheet_extent.dart @@ -9,7 +9,7 @@ import 'navigation_route.dart'; import 'navigation_sheet_activity.dart'; @internal -class NavigationSheetExtent extends SheetExtent { +class NavigationSheetExtent extends SheetPosition { NavigationSheetExtent({ required super.context, required super.minExtent, @@ -22,7 +22,7 @@ class NavigationSheetExtent extends SheetExtent { Transition? _lastReportedTransition; @override - void takeOver(SheetExtent other) { + void takeOver(SheetPosition other) { super.takeOver(other); assert(_debugAssertActivityTypeConsistency()); } diff --git a/lib/src/navigation/navigation_sheet_viewport.dart b/lib/src/navigation/navigation_sheet_viewport.dart index 7bebe49..506de81 100644 --- a/lib/src/navigation/navigation_sheet_viewport.dart +++ b/lib/src/navigation/navigation_sheet_viewport.dart @@ -99,7 +99,7 @@ class NavigationSheetRouteViewport extends SingleChildRenderObjectWidget { class _RenderNavigationSheetRouteViewport extends RenderProxyBox { _RenderNavigationSheetRouteViewport({ required _RenderNavigationSheetViewport globalViewport, - required SheetExtent localExtent, + required SheetPosition localExtent, }) : _globalViewport = globalViewport, _localExtent = localExtent { _globalViewport.addChild(this); @@ -114,9 +114,9 @@ class _RenderNavigationSheetRouteViewport extends RenderProxyBox { } } - SheetExtent _localExtent; + SheetPosition _localExtent; // ignore: avoid_setters_without_getters - set localExtent(SheetExtent value) { + set localExtent(SheetPosition value) { if (_localExtent != value) { _localExtent = value; markNeedsLayout(); diff --git a/lib/src/scrollable/scrollable_sheet_extent.dart b/lib/src/scrollable/scrollable_sheet_extent.dart index 03fa6df..98d7fc8 100644 --- a/lib/src/scrollable/scrollable_sheet_extent.dart +++ b/lib/src/scrollable/scrollable_sheet_extent.dart @@ -14,7 +14,7 @@ import 'sheet_content_scroll_activity.dart'; import 'sheet_content_scroll_position.dart'; @internal -class ScrollableSheetExtent extends SheetExtent +class ScrollableSheetExtent extends SheetPosition implements SheetContentScrollPositionOwner { ScrollableSheetExtent({ required super.context, @@ -90,7 +90,7 @@ class ScrollableSheetExtent extends SheetExtent } @override - void takeOver(SheetExtent other) { + void takeOver(SheetPosition other) { super.takeOver(other); if (other is ScrollableSheetExtent) { assert(_scrollPositions.isEmpty); diff --git a/test/foundation/sheet_viewport_test.dart b/test/foundation/sheet_viewport_test.dart index 8f4c9ea..af24f21 100644 --- a/test/foundation/sheet_viewport_test.dart +++ b/test/foundation/sheet_viewport_test.dart @@ -36,7 +36,7 @@ class _FakeSheetActivity extends SheetActivity { SheetStatus get status => SheetStatus.stable; } -class _FakeSheetExtent extends SheetExtent { +class _FakeSheetExtent extends SheetPosition { _FakeSheetExtent({ this.createIdleActivity, }) : super( @@ -73,7 +73,7 @@ class _TestWidget extends StatelessWidget { this.sheetContent, }); - final SheetExtent extent; + final SheetPosition extent; final Widget? sheetContent; final Widget? background; @@ -112,7 +112,7 @@ class _TestWidget extends StatelessWidget { void main() { group('Ignore pointer test:', () { ({ - SheetExtent extent, + SheetPosition extent, Widget testWidget, ValueGetter didTapForeground, ValueGetter didTapBackgroundTop, diff --git a/test/src/stubbing.dart b/test/src/stubbing.dart index be29f13..9964d6a 100644 --- a/test/src/stubbing.dart +++ b/test/src/stubbing.dart @@ -7,7 +7,7 @@ import 'package:smooth_sheets/src/foundation/sheet_context.dart'; import 'package:smooth_sheets/src/foundation/sheet_position.dart'; @GenerateNiceMocks([ - MockSpec(), + MockSpec(), MockSpec(), MockSpec(), MockSpec(), diff --git a/test/src/stubbing.mocks.dart b/test/src/stubbing.mocks.dart index 9ee2439..d16f001 100644 --- a/test/src/stubbing.mocks.dart +++ b/test/src/stubbing.mocks.dart @@ -16,10 +16,10 @@ import 'package:mockito/src/dummies.dart' as _i16; import 'package:smooth_sheets/src/foundation/sheet_activity.dart' as _i5; import 'package:smooth_sheets/src/foundation/sheet_context.dart' as _i2; import 'package:smooth_sheets/src/foundation/sheet_drag.dart' as _i12; -import 'package:smooth_sheets/src/foundation/sheet_position.dart' as _i4; import 'package:smooth_sheets/src/foundation/sheet_gesture_tamperer.dart' as _i14; import 'package:smooth_sheets/src/foundation/sheet_physics.dart' as _i3; +import 'package:smooth_sheets/src/foundation/sheet_position.dart' as _i4; import 'package:smooth_sheets/src/foundation/sheet_status.dart' as _i13; // ignore_for_file: type=lint @@ -55,7 +55,7 @@ class _FakeSheetPhysics_1 extends _i1.SmartFake implements _i3.SheetPhysics { ); } -class _FakeSheetActivity_2 extends _i1.SmartFake +class _FakeSheetActivity_2 extends _i1.SmartFake implements _i5.SheetActivity { _FakeSheetActivity_2( Object parent, @@ -191,7 +191,7 @@ class _FakeTicker_13 extends _i1.SmartFake implements _i11.Ticker { /// A class which mocks [SheetExtent]. /// /// See the documentation for Mockito's code generation for more information. -class MockSheetExtent extends _i1.Mock implements _i4.SheetExtent { +class MockSheetExtent extends _i1.Mock implements _i4.SheetPosition { @override _i2.SheetContext get context => (super.noSuchMethod( Invocation.getter(#context), @@ -242,17 +242,17 @@ class MockSheetExtent extends _i1.Mock implements _i4.SheetExtent { ) as _i3.SheetPhysics); @override - _i5.SheetActivity<_i4.SheetExtent> get activity => (super.noSuchMethod( + _i5.SheetActivity<_i4.SheetPosition> get activity => (super.noSuchMethod( Invocation.getter(#activity), - returnValue: _FakeSheetActivity_2<_i4.SheetExtent>( + returnValue: _FakeSheetActivity_2<_i4.SheetPosition>( this, Invocation.getter(#activity), ), - returnValueForMissingStub: _FakeSheetActivity_2<_i4.SheetExtent>( + returnValueForMissingStub: _FakeSheetActivity_2<_i4.SheetPosition>( this, Invocation.getter(#activity), ), - ) as _i5.SheetActivity<_i4.SheetExtent>); + ) as _i5.SheetActivity<_i4.SheetPosition>); @override _i4.SheetMetrics get snapshot => (super.noSuchMethod( @@ -403,7 +403,7 @@ class MockSheetExtent extends _i1.Mock implements _i4.SheetExtent { ) as bool); @override - void takeOver(_i4.SheetExtent? other) => super.noSuchMethod( + void takeOver(_i4.SheetPosition? other) => super.noSuchMethod( Invocation.method( #takeOver, [other], @@ -499,7 +499,7 @@ class MockSheetExtent extends _i1.Mock implements _i4.SheetExtent { ); @override - void beginActivity(_i5.SheetActivity<_i4.SheetExtent>? activity) => + void beginActivity(_i5.SheetActivity<_i4.SheetPosition>? activity) => super.noSuchMethod( Invocation.method( #beginActivity, From 958a048e98abfe6b847c578d4d24dd68ec441eb8 Mon Sep 17 00:00:00 2001 From: fujidaiti Date: Thu, 26 Sep 2024 16:04:34 +0900 Subject: [PATCH 07/22] Rename Extent to SheetAnchor --- .../lib/showcase/ai_playlist_generator.dart | 4 +- example/lib/showcase/airbnb_mobile_app.dart | 6 +- example/lib/showcase/safari/menu.dart | 4 +- .../lib/tutorial/bottom_bar_visibility.dart | 8 +- example/lib/tutorial/bouncing_behaviors.dart | 12 +-- .../lib/tutorial/cupertino_modal_sheet.dart | 6 +- .../lib/tutorial/extent_driven_animation.dart | 4 +- .../lib/tutorial/imperative_modal_sheet.dart | 2 +- example/lib/tutorial/scrollable_sheet.dart | 8 +- .../lib/tutorial/sheet_content_scaffold.dart | 11 ++- example/lib/tutorial/sheet_controller.dart | 4 +- example/lib/tutorial/sheet_draggable.dart | 2 +- example/lib/tutorial/sheet_physics.dart | 10 +- .../textfield_with_multiple_stops.dart | 10 +- lib/src/draggable/draggable_sheet.dart | 12 +-- lib/src/draggable/draggable_sheet_extent.dart | 2 +- .../draggable_sheet_extent_scope.dart | 2 +- .../foundation/extent_driven_animation.dart | 4 +- lib/src/foundation/foundation.dart | 2 +- lib/src/foundation/sheet_activity.dart | 12 +-- .../foundation/sheet_content_scaffold.dart | 2 +- lib/src/foundation/sheet_controller.dart | 2 +- lib/src/foundation/sheet_extent_scope.dart | 4 +- lib/src/foundation/sheet_physics.dart | 55 +++++------ lib/src/foundation/sheet_position.dart | 63 +++++++------ lib/src/navigation/navigation_routes.dart | 60 ++++++------ .../navigation/navigation_sheet_extent.dart | 2 +- .../navigation_sheet_extent_scope.dart | 4 +- lib/src/scrollable/scrollable_sheet.dart | 12 +-- .../scrollable/scrollable_sheet_extent.dart | 2 +- .../scrollable_sheet_extent_scope.dart | 2 +- test/draggable/draggable_sheet_test.dart | 6 +- test/foundation/physics_test.dart | 94 +++++++++---------- test/foundation/sheet_activity_test.dart | 48 +++++----- test/foundation/sheet_notification_test.dart | 12 +-- test/foundation/sheet_viewport_test.dart | 4 +- test/navigation/navigation_sheet_test.dart | 22 ++--- test/scrollable/scrollable_sheet_test.dart | 6 +- test/src/stubbing.dart | 20 ++-- test/src/stubbing.mocks.dart | 22 ++--- 40 files changed, 285 insertions(+), 282 deletions(-) diff --git a/example/lib/showcase/ai_playlist_generator.dart b/example/lib/showcase/ai_playlist_generator.dart index e535288..83ae83f 100644 --- a/example/lib/showcase/ai_playlist_generator.dart +++ b/example/lib/showcase/ai_playlist_generator.dart @@ -104,8 +104,8 @@ final _confirmRoute = GoRoute( path: 'confirm', pageBuilder: (context, state) { return const ScrollableNavigationSheetPage( - initialExtent: Extent.proportional(0.7), - minExtent: Extent.proportional(0.7), + initialExtent: SheetAnchor.proportional(0.7), + minExtent: SheetAnchor.proportional(0.7), physics: BouncingSheetPhysics( parent: SnappingSheetPhysics(), ), diff --git a/example/lib/showcase/airbnb_mobile_app.dart b/example/lib/showcase/airbnb_mobile_app.dart index 9534b9d..863cd73 100644 --- a/example/lib/showcase/airbnb_mobile_app.dart +++ b/example/lib/showcase/airbnb_mobile_app.dart @@ -84,7 +84,7 @@ class _MapButton extends StatelessWidget { if (metrics.hasDimensions) { // Collapse the sheet to reveal the map behind. sheetController.animateTo( - Extent.pixels(metrics.minPixels), + SheetAnchor.pixels(metrics.minPixels), curve: Curves.fastOutSlowIn, ); } @@ -156,7 +156,7 @@ class _ContentSheet extends StatelessWidget { final handleHeight = const _ContentSheetHandle().preferredSize.height; final sheetHeight = parentHeight - appbarHeight + handleHeight; final minSheetExtent = - Extent.pixels(handleHeight + systemUiInsets.bottom); + SheetAnchor.pixels(handleHeight + systemUiInsets.bottom); const sheetShape = RoundedRectangleBorder( borderRadius: BorderRadius.vertical( @@ -169,7 +169,7 @@ class _ContentSheet extends StatelessWidget { snappingBehavior: SnapToNearest( snapTo: [ minSheetExtent, - const Extent.proportional(1), + const SheetAnchor.proportional(1), ], ), ), diff --git a/example/lib/showcase/safari/menu.dart b/example/lib/showcase/safari/menu.dart index eb1d693..ba0452e 100644 --- a/example/lib/showcase/safari/menu.dart +++ b/example/lib/showcase/safari/menu.dart @@ -22,7 +22,7 @@ class MenuSheet extends StatelessWidget { @override Widget build(BuildContext context) { - const halfWayExtent = Extent.proportional(0.5); + const halfWayExtent = SheetAnchor.proportional(0.5); return ScrollableSheet( initialExtent: halfWayExtent, minExtent: halfWayExtent, @@ -152,7 +152,7 @@ class _MenuListItem extends StatelessWidget { trailing: Icon(icon, color: CupertinoColors.black), onTap: () { DefaultSheetController.maybeOf(context) - ?.animateTo(const Extent.proportional(1)); + ?.animateTo(const SheetAnchor.proportional(1)); showEditBookmarkSheet(context); }, ); diff --git a/example/lib/tutorial/bottom_bar_visibility.dart b/example/lib/tutorial/bottom_bar_visibility.dart index 6d75668..857dfa3 100644 --- a/example/lib/tutorial/bottom_bar_visibility.dart +++ b/example/lib/tutorial/bottom_bar_visibility.dart @@ -133,9 +133,9 @@ class _ExampleSheet extends StatelessWidget { ), ); - const minSize = Extent.proportional(0.3); - const halfSize = Extent.proportional(0.5); - const fullSize = Extent.proportional(1); + const minSize = SheetAnchor.proportional(0.3); + const halfSize = SheetAnchor.proportional(0.5); + const fullSize = SheetAnchor.proportional(1); const multiStopPhysics = BouncingSheetPhysics( parent: SnappingSheetPhysics( @@ -166,7 +166,7 @@ class _ExampleSheet extends StatelessWidget { getIsVisible: (metrics) { // The bottom bar is visible when at least 50% of the sheet is visible. return metrics.pixels >= - const Extent.proportional(0.5) + const SheetAnchor.proportional(0.5) .resolve(metrics.contentSize); }, child: bottomBar, diff --git a/example/lib/tutorial/bouncing_behaviors.dart b/example/lib/tutorial/bouncing_behaviors.dart index 777c50c..1d83e7b 100644 --- a/example/lib/tutorial/bouncing_behaviors.dart +++ b/example/lib/tutorial/bouncing_behaviors.dart @@ -27,7 +27,7 @@ class _Home extends StatelessWidget { behavior: FixedBouncingBehavior( // Allows the sheet position to exceed the content bounds // by ±10% of the content height. - Extent.proportional(0.1), + SheetAnchor.proportional(0.1), ), ), ), @@ -39,7 +39,7 @@ class _Home extends StatelessWidget { const _DraggableSheet( behavior: FixedBouncingBehavior( // Allows the sheet position to exceed the content bounds by ±50 pixels. - Extent.pixels(50), + SheetAnchor.pixels(50), ), ), ), @@ -53,8 +53,8 @@ class _Home extends StatelessWidget { // Allows the sheet position to exceed the content bounds by 10 pixels // when dragging the sheet upwards, and by ±30% of the content height // when dragging it downwards. - upward: Extent.pixels(20), - downward: Extent.proportional(0.3), + upward: SheetAnchor.pixels(20), + downward: SheetAnchor.proportional(0.3), ), ), ), @@ -66,8 +66,8 @@ class _Home extends StatelessWidget { const _DraggableSheet( behavior: DirectionAwareBouncingBehavior( // Allows the sheet to bounce only when dragging it downwards. - upward: Extent.pixels(0), - downward: Extent.proportional(0.1), + upward: SheetAnchor.pixels(0), + downward: SheetAnchor.proportional(0.1), ), ), ), diff --git a/example/lib/tutorial/cupertino_modal_sheet.dart b/example/lib/tutorial/cupertino_modal_sheet.dart index 9786fcb..7a3e6f5 100644 --- a/example/lib/tutorial/cupertino_modal_sheet.dart +++ b/example/lib/tutorial/cupertino_modal_sheet.dart @@ -72,8 +72,8 @@ class _HalfScreenSheet extends StatelessWidget { // `CupertinoStackedTransition` won't start the transition animation until // the visible height of a modal sheet (the extent) exceeds 50% of the screen height. return const DraggableSheet( - initialExtent: Extent.proportional(0.5), - minExtent: Extent.proportional(0.5), + initialExtent: SheetAnchor.proportional(0.5), + minExtent: SheetAnchor.proportional(0.5), physics: BouncingSheetPhysics( parent: SnappingSheetPhysics(), ), @@ -120,7 +120,7 @@ class _SheetContent extends StatelessWidget { // `DefaultSheetController.of` is a handy way to obtain a `SheetController` // that is exposed by the parent `CupertinoModalSheetRoute`. DefaultSheetController.maybeOf(context) - ?.animateTo(const Extent.proportional(1)); + ?.animateTo(const SheetAnchor.proportional(1)); _showModalSheet(context, isFullScreen: true); }, child: const Text('Stack'), diff --git a/example/lib/tutorial/extent_driven_animation.dart b/example/lib/tutorial/extent_driven_animation.dart index 3dfd767..7dd33ff 100644 --- a/example/lib/tutorial/extent_driven_animation.dart +++ b/example/lib/tutorial/extent_driven_animation.dart @@ -48,12 +48,12 @@ class _ExampleSheet extends StatelessWidget { @override Widget build(BuildContext context) { final bottomPadding = MediaQuery.of(context).padding.bottom; - final minExtent = Extent.pixels(56 + bottomPadding); + final minExtent = SheetAnchor.pixels(56 + bottomPadding); final physics = BouncingSheetPhysics( parent: SnappingSheetPhysics( snappingBehavior: SnapToNearest( - snapTo: [minExtent, const Extent.proportional(1)], + snapTo: [minExtent, const SheetAnchor.proportional(1)], ), ), ); diff --git a/example/lib/tutorial/imperative_modal_sheet.dart b/example/lib/tutorial/imperative_modal_sheet.dart index 546491e..fcd899f 100644 --- a/example/lib/tutorial/imperative_modal_sheet.dart +++ b/example/lib/tutorial/imperative_modal_sheet.dart @@ -67,7 +67,7 @@ class _ExampleSheet extends StatelessWidget { } }, child: DraggableSheet( - minExtent: const Extent.proportional(0.5), + minExtent: const SheetAnchor.proportional(0.5), child: Card( color: Theme.of(context).colorScheme.secondaryContainer, margin: EdgeInsets.zero, diff --git a/example/lib/tutorial/scrollable_sheet.dart b/example/lib/tutorial/scrollable_sheet.dart index 8e83a9e..6ed0d3c 100644 --- a/example/lib/tutorial/scrollable_sheet.dart +++ b/example/lib/tutorial/scrollable_sheet.dart @@ -45,14 +45,14 @@ class _MySheet extends StatelessWidget { child: buildSheetBackground(context, content), // Optional: Comment out the following lines to add multiple stop positions. // - // minExtent: const Extent.proportional(0.2), + // minExtent: const SheetAnchor.proportional(0.2), // physics: BouncingSheetPhysics( // parent: SnappingSheetPhysics( // snappingBehavior: SnapToNearest( // snapTo: [ - // const Extent.proportional(0.2), - // const Extent.proportional(0.5), - // const Extent.proportional(1), + // const SheetAnchor.proportional(0.2), + // const SheetAnchor.proportional(0.5), + // const SheetAnchor.proportional(1), // ], // ), // ), diff --git a/example/lib/tutorial/sheet_content_scaffold.dart b/example/lib/tutorial/sheet_content_scaffold.dart index 88550bc..ff6ca82 100644 --- a/example/lib/tutorial/sheet_content_scaffold.dart +++ b/example/lib/tutorial/sheet_content_scaffold.dart @@ -44,7 +44,8 @@ class _ExampleSheet extends StatelessWidget { getIsVisible: (metrics) { return metrics.viewportInsets.bottom == 0 && metrics.pixels > - const Extent.proportional(0.5).resolve(metrics.contentSize); + const SheetAnchor.proportional(0.5) + .resolve(metrics.contentSize); }, child: buildBottomBar(), ), @@ -54,9 +55,9 @@ class _ExampleSheet extends StatelessWidget { parent: SnappingSheetPhysics( snappingBehavior: SnapToNearest( snapTo: [ - Extent.proportional(0.2), - Extent.proportional(0.5), - Extent.proportional(1), + SheetAnchor.proportional(0.2), + SheetAnchor.proportional(0.5), + SheetAnchor.proportional(1), ], ), ), @@ -64,7 +65,7 @@ class _ExampleSheet extends StatelessWidget { return DraggableSheet( physics: physics, - minExtent: const Extent.pixels(0), + minExtent: const SheetAnchor.pixels(0), child: Card( clipBehavior: Clip.antiAlias, margin: EdgeInsets.zero, diff --git a/example/lib/tutorial/sheet_controller.dart b/example/lib/tutorial/sheet_controller.dart index 727a0cf..2e13cef 100644 --- a/example/lib/tutorial/sheet_controller.dart +++ b/example/lib/tutorial/sheet_controller.dart @@ -70,7 +70,7 @@ class _ExampleHomeState extends State<_ExampleHome> { child: const Icon(Icons.arrow_downward_rounded), onPressed: () { // SheetController can also be used to animate the sheet extent. - controller.animateTo(const Extent.proportional(0.5)); + controller.animateTo(const SheetAnchor.proportional(0.5)); }, ), ); @@ -88,7 +88,7 @@ class _ExampleSheet extends StatelessWidget { Widget build(BuildContext context) { return DraggableSheet( controller: controller, - minExtent: const Extent.proportional(0.5), + minExtent: const SheetAnchor.proportional(0.5), physics: const BouncingSheetPhysics( parent: SnappingSheetPhysics(), ), diff --git a/example/lib/tutorial/sheet_draggable.dart b/example/lib/tutorial/sheet_draggable.dart index f687394..3a718be 100644 --- a/example/lib/tutorial/sheet_draggable.dart +++ b/example/lib/tutorial/sheet_draggable.dart @@ -65,7 +65,7 @@ class _ExampleSheet extends StatelessWidget { ], ); - const minExtent = Extent.proportional(0.5); + const minExtent = SheetAnchor.proportional(0.5); const physics = BouncingSheetPhysics( parent: SnappingSheetPhysics(), ); diff --git a/example/lib/tutorial/sheet_physics.dart b/example/lib/tutorial/sheet_physics.dart index 9440ca7..5f914f9 100644 --- a/example/lib/tutorial/sheet_physics.dart +++ b/example/lib/tutorial/sheet_physics.dart @@ -90,8 +90,8 @@ class _MySheet extends StatelessWidget { const snappingPhysics = SnappingSheetPhysics( snappingBehavior: SnapToNearest( snapTo: [ - Extent.proportional(_halfwayFraction), - Extent.proportional(1), + SheetAnchor.proportional(_halfwayFraction), + SheetAnchor.proportional(1), ], ), // Tips: The above configuration can be replaced with a 'SnapToNearestEdge', @@ -119,9 +119,9 @@ class _MySheet extends StatelessWidget { // the configuration below ensures that the sheet is fully visible // at first and can then be dragged down to (_halfwayFraction * 100)% // of the sheet height at minimum. - minExtent: const Extent.proportional(_halfwayFraction), - maxExtent: const Extent.proportional(1), // Default - initialExtent: const Extent.proportional(1), // Default + minExtent: const SheetAnchor.proportional(_halfwayFraction), + maxExtent: const SheetAnchor.proportional(1), // Default + initialExtent: const SheetAnchor.proportional(1), // Default // 'physics' determines how the sheet will behave when the user reaches // the maximum or minimum extent, or when the user stops dragging. physics: createPhysics(physicsKind), diff --git a/example/lib/tutorial/textfield_with_multiple_stops.dart b/example/lib/tutorial/textfield_with_multiple_stops.dart index 315397a..248c6fe 100644 --- a/example/lib/tutorial/textfield_with_multiple_stops.dart +++ b/example/lib/tutorial/textfield_with_multiple_stops.dart @@ -15,15 +15,15 @@ class TextFieldWithMultipleStops extends StatelessWidget { children: [ const Scaffold(), ScrollableSheet( - initialExtent: const Extent.proportional(0.7), - minExtent: const Extent.proportional(0.4), + initialExtent: const SheetAnchor.proportional(0.7), + minExtent: const SheetAnchor.proportional(0.4), physics: const BouncingSheetPhysics( parent: SnappingSheetPhysics( snappingBehavior: SnapToNearest( snapTo: [ - Extent.proportional(0.4), - Extent.proportional(0.7), - Extent.proportional(1), + SheetAnchor.proportional(0.4), + SheetAnchor.proportional(0.7), + SheetAnchor.proportional(1), ], ), ), diff --git a/lib/src/draggable/draggable_sheet.dart b/lib/src/draggable/draggable_sheet.dart index a3739c7..20071f7 100644 --- a/lib/src/draggable/draggable_sheet.dart +++ b/lib/src/draggable/draggable_sheet.dart @@ -32,21 +32,21 @@ class DraggableSheet extends StatefulWidget { const DraggableSheet({ super.key, this.hitTestBehavior = HitTestBehavior.translucent, - this.initialExtent = const Extent.proportional(1), - this.minExtent = const Extent.proportional(1), - this.maxExtent = const Extent.proportional(1), + this.initialExtent = const SheetAnchor.proportional(1), + this.minExtent = const SheetAnchor.proportional(1), + this.maxExtent = const SheetAnchor.proportional(1), this.physics, required this.child, this.controller, }); - final Extent initialExtent; + final SheetAnchor initialExtent; /// {@macro SheetExtentConfig.minExtent} - final Extent minExtent; + final SheetAnchor minExtent; /// {@macro SheetExtentConfig.maxExtent} - final Extent maxExtent; + final SheetAnchor maxExtent; /// {@macro SheetExtentConfig.physics} final SheetPhysics? physics; diff --git a/lib/src/draggable/draggable_sheet_extent.dart b/lib/src/draggable/draggable_sheet_extent.dart index ecd8b10..622bf09 100644 --- a/lib/src/draggable/draggable_sheet_extent.dart +++ b/lib/src/draggable/draggable_sheet_extent.dart @@ -19,7 +19,7 @@ class DraggableSheetExtent extends SheetPosition { /// {@template DraggableSheetExtent.initialExtent} /// The initial extent of the sheet. /// {@endtemplate} - final Extent initialExtent; + final SheetAnchor initialExtent; @override void applyNewContentSize(Size contentSize) { diff --git a/lib/src/draggable/draggable_sheet_extent_scope.dart b/lib/src/draggable/draggable_sheet_extent_scope.dart index 5b38fe7..898e5b9 100644 --- a/lib/src/draggable/draggable_sheet_extent_scope.dart +++ b/lib/src/draggable/draggable_sheet_extent_scope.dart @@ -22,7 +22,7 @@ class DraggableSheetExtentScope extends SheetExtentScope { }); /// {@macro DraggableSheetExtent.initialExtent} - final Extent initialExtent; + final SheetAnchor initialExtent; /// {@macro SheetExtent.debugLabel} final String? debugLabel; diff --git a/lib/src/foundation/extent_driven_animation.dart b/lib/src/foundation/extent_driven_animation.dart index 7e85d3d..dde104f 100644 --- a/lib/src/foundation/extent_driven_animation.dart +++ b/lib/src/foundation/extent_driven_animation.dart @@ -14,8 +14,8 @@ class ExtentDrivenAnimation extends Animation { final SheetController _controller; final double initialValue; - final Extent? startExtent; - final Extent? endExtent; + final SheetAnchor? startExtent; + final SheetAnchor? endExtent; @override void addListener(VoidCallback listener) { diff --git a/lib/src/foundation/foundation.dart b/lib/src/foundation/foundation.dart index a76a8fe..dacb068 100644 --- a/lib/src/foundation/foundation.dart +++ b/lib/src/foundation/foundation.dart @@ -49,9 +49,9 @@ export 'sheet_physics.dart' kDefaultSheetSpring; export 'sheet_position.dart' show - Extent, FixedExtent, ProportionalExtent, + SheetAnchor, SheetMetrics, SheetMetricsSnapshot; export 'sheet_status.dart' show SheetStatus; diff --git a/lib/src/foundation/sheet_activity.dart b/lib/src/foundation/sheet_activity.dart index dee51a2..6c48871 100644 --- a/lib/src/foundation/sheet_activity.dart +++ b/lib/src/foundation/sheet_activity.dart @@ -67,8 +67,8 @@ abstract class SheetActivity { void didChangeViewportDimensions(Size? oldSize, EdgeInsets? oldInsets) {} void didChangeBoundaryConstraints( - Extent? oldMinExtent, - Extent? oldMaxExtent, + SheetAnchor? oldMinExtent, + SheetAnchor? oldMaxExtent, ) {} /// Called when all relevant metrics of the sheet are finalized @@ -129,7 +129,7 @@ abstract class SheetActivity { /// position determined by [destination], using the specified [curve] and /// [duration]. /// -/// This activity accepts the destination position as an [Extent], allowing +/// This activity accepts the destination position as an [SheetAnchor], allowing /// the concrete end position (in pixels) to be updated during the animation /// in response to viewport changes, such as the appearance of the on-screen /// keyboard. @@ -148,7 +148,7 @@ class AnimatedSheetActivity extends SheetActivity required this.curve, }) : assert(duration > Duration.zero); - final Extent destination; + final SheetAnchor destination; final Duration duration; final Curve curve; @@ -327,7 +327,7 @@ class SettlingSheetActivity extends SheetActivity { final Duration? duration; /// The destination position to which the sheet should settle. - final Extent destination; + final SheetAnchor destination; late final Ticker _ticker; @@ -420,7 +420,7 @@ class IdleSheetActivity extends SheetActivity { @override SheetStatus get status => SheetStatus.stable; - /// Updates [SheetMetrics.pixels] to maintain the current [Extent], which + /// Updates [SheetMetrics.pixels] to maintain the current [SheetAnchor], which /// is determined by [SheetPhysics.findSettledExtent] using the metrics of /// the previous frame. @override diff --git a/lib/src/foundation/sheet_content_scaffold.dart b/lib/src/foundation/sheet_content_scaffold.dart index 1f6f4c4..ca69ff8 100644 --- a/lib/src/foundation/sheet_content_scaffold.dart +++ b/lib/src/foundation/sheet_content_scaffold.dart @@ -513,7 +513,7 @@ class _RenderAnimatedBottomBarVisibility extends _RenderBottomBarVisibility { /// getIsVisible: (metrics) => /// metrics.viewportInsets.bottom == 0 && /// metrics.pixels > -/// const Extent.proportional(0.5) +/// const SheetAnchor.proportional(0.5) /// .resolve(metrics.contentSize), /// child: BottomAppBar(), /// ), diff --git a/lib/src/foundation/sheet_controller.dart b/lib/src/foundation/sheet_controller.dart index 3176514..450364a 100644 --- a/lib/src/foundation/sheet_controller.dart +++ b/lib/src/foundation/sheet_controller.dart @@ -73,7 +73,7 @@ class SheetController extends ChangeNotifier } Future animateTo( - Extent to, { + SheetAnchor to, { Duration duration = const Duration(milliseconds: 300), Curve curve = Curves.easeInOut, }) { diff --git a/lib/src/foundation/sheet_extent_scope.dart b/lib/src/foundation/sheet_extent_scope.dart index a55e0d6..334d492 100644 --- a/lib/src/foundation/sheet_extent_scope.dart +++ b/lib/src/foundation/sheet_extent_scope.dart @@ -71,10 +71,10 @@ abstract class SheetExtentScope extends StatefulWidget { final SheetController? controller; /// {@macro SheetExtent.minExtent} - final Extent minExtent; + final SheetAnchor minExtent; /// {@macro SheetExtent.maxExtent} - final Extent maxExtent; + final SheetAnchor maxExtent; /// {@macro SheetExtent.physics} final SheetPhysics physics; diff --git a/lib/src/foundation/sheet_physics.dart b/lib/src/foundation/sheet_physics.dart index 1dc07a4..aa55508 100644 --- a/lib/src/foundation/sheet_physics.dart +++ b/lib/src/foundation/sheet_physics.dart @@ -72,7 +72,7 @@ abstract class SheetPhysics { /// Returns an extent to which a sheet should eventually settle /// based on the current [metrics] and the [velocity] of a sheet. /// {@endtemplate} - Extent findSettledExtent(double velocity, SheetMetrics metrics); + SheetAnchor findSettledExtent(double velocity, SheetMetrics metrics); } /// A mixin that provides default implementations for [SheetPhysics] methods. @@ -143,17 +143,18 @@ mixin SheetPhysicsMixin on SheetPhysics { /// to the current sheet position if it is out of bounds, regardless of the /// [velocity]. Otherwise, it returns the current position. @override - Extent findSettledExtent(double velocity, SheetMetrics metrics) { + SheetAnchor findSettledExtent(double velocity, SheetMetrics metrics) { return _findSettledExtentInternal(velocity, metrics); } - Extent _findSettledExtentInternal(double velocity, SheetMetrics metrics) { + SheetAnchor _findSettledExtentInternal( + double velocity, SheetMetrics metrics) { final pixels = metrics.pixels; final minPixels = metrics.minPixels; final maxPixels = metrics.maxPixels; if (FloatComp.distance(metrics.devicePixelRatio) .isInBoundsExclusive(pixels, minPixels, maxPixels)) { - return Extent.pixels(pixels); + return SheetAnchor.pixels(pixels); } else if ((pixels - minPixels).abs() < (pixels - maxPixels).abs()) { return metrics.minExtent; } else { @@ -167,7 +168,7 @@ abstract interface class SnappingSheetBehavior { /// /// Returning `null` indicates that this behavior has no preference for /// for where the sheet should settle. - Extent? findSettledExtent(double velocity, SheetMetrics metrics); + SheetAnchor? findSettledExtent(double velocity, SheetMetrics metrics); } /// A [SnappingSheetBehavior] that snaps to either [SheetMetrics.minPixels] @@ -199,7 +200,7 @@ class SnapToNearestEdge implements SnappingSheetBehavior { final double minFlingSpeed; @override - Extent? findSettledExtent(double velocity, SheetMetrics metrics) { + SheetAnchor? findSettledExtent(double velocity, SheetMetrics metrics) { assert(minFlingSpeed >= 0); final pixels = metrics.pixels; final minPixels = metrics.minPixels; @@ -230,14 +231,14 @@ class SnapToNearest implements SnappingSheetBehavior { }) : assert(minFlingSpeed >= 0); // TODO: Rename to `detents`. - final List snapTo; + final List snapTo; /// The lowest speed (in logical pixels per second) /// at which a gesture is considered to be a fling. final double minFlingSpeed; @override - Extent? findSettledExtent(double velocity, SheetMetrics metrics) { + SheetAnchor? findSettledExtent(double velocity, SheetMetrics metrics) { if (snapTo.length <= 1) { return snapTo.firstOrNull; } @@ -281,7 +282,7 @@ class SnapToNearest implements SnappingSheetBehavior { } } -typedef _SortedExtentList = List<({Extent extent, double resolved})>; +typedef _SortedExtentList = List<({SheetAnchor extent, double resolved})>; /// Sorts the [extents] based on their resolved values and finds the nearest /// extent to the [pixels]. @@ -290,7 +291,7 @@ typedef _SortedExtentList = List<({Extent extent, double resolved})>; /// Note that the returned list may have a fixed length for better performance. @visibleForTesting (_SortedExtentList, int) sortExtentsAndFindNearest( - List extents, + List extents, double pixels, Size contentSize, ) { @@ -312,10 +313,10 @@ typedef _SortedExtentList = List<({Extent extent, double resolved})>; } } -/// Constant time sorting and nearest neighbor search for two [Extent]s. +/// Constant time sorting and nearest neighbor search for two [SheetAnchor]s. (_SortedExtentList, int) _sortTwoExtentsAndFindNearest( - Extent a, - Extent b, + SheetAnchor a, + SheetAnchor b, double pixels, Size contentSize, ) { @@ -339,11 +340,11 @@ typedef _SortedExtentList = List<({Extent extent, double resolved})>; ); } -/// Constant time sorting and nearest neighbor search for three [Extent]s. +/// Constant time sorting and nearest neighbor search for three [SheetAnchor]s. (_SortedExtentList, int) _sortThreeExtentsAndFindNearest( - Extent a, - Extent b, - Extent c, + SheetAnchor a, + SheetAnchor b, + SheetAnchor c, double pixels, Size contentSize, ) { @@ -434,7 +435,7 @@ class SnappingSheetPhysics extends SheetPhysics with SheetPhysicsMixin { } @override - Extent findSettledExtent(double velocity, SheetMetrics metrics) { + SheetAnchor findSettledExtent(double velocity, SheetMetrics metrics) { return snappingBehavior.findSettledExtent(velocity, metrics) ?? super.findSettledExtent(velocity, metrics); } @@ -491,7 +492,7 @@ abstract class BouncingBehavior { /// /// ```dart /// const physics = BouncingSheetPhysics( -/// behavior: FixedBouncingBehavior(Extent.proportional(0.12)), +/// behavior: FixedBouncingBehavior(SheetAnchor.proportional(0.12)), /// ); /// ``` class FixedBouncingBehavior implements BouncingBehavior { @@ -500,7 +501,7 @@ class FixedBouncingBehavior implements BouncingBehavior { const FixedBouncingBehavior(this.range); /// How much the sheet can bounce beyond the content bounds. - final Extent range; + final SheetAnchor range; @override double computeBounceablePixels(double offset, SheetMetrics metrics) { @@ -519,8 +520,8 @@ class FixedBouncingBehavior implements BouncingBehavior { /// ```dart /// const physics = BouncingSheetPhysics( /// behavior: DirectionAwareBouncingBehavior( -/// upward: Extent.pixels(8), -/// downward: Extent.proportional(0.12), +/// upward: SheetAnchor.pixels(8), +/// downward: SheetAnchor.proportional(0.12), /// ), /// ); /// ``` @@ -528,15 +529,15 @@ class DirectionAwareBouncingBehavior implements BouncingBehavior { /// Creates a [BouncingBehavior] that allows the sheet to bounce by different /// amounts based on the direction of a drag gesture. const DirectionAwareBouncingBehavior({ - this.upward = const Extent.pixels(0), - this.downward = const Extent.pixels(0), + this.upward = const SheetAnchor.pixels(0), + this.downward = const SheetAnchor.pixels(0), }); /// Amount of bounceable pixels when dragged upward. - final Extent upward; + final SheetAnchor upward; /// Amount of bounceable pixels when dragged downward. - final Extent downward; + final SheetAnchor downward; @override double computeBounceablePixels(double offset, SheetMetrics metrics) { @@ -551,7 +552,7 @@ class DirectionAwareBouncingBehavior implements BouncingBehavior { class BouncingSheetPhysics extends SheetPhysics with SheetPhysicsMixin { const BouncingSheetPhysics({ super.parent, - this.behavior = const FixedBouncingBehavior(Extent.proportional(0.12)), + this.behavior = const FixedBouncingBehavior(SheetAnchor.proportional(0.12)), this.frictionCurve = Curves.easeOutSine, this.spring = kDefaultSheetSpring, }); diff --git a/lib/src/foundation/sheet_position.dart b/lib/src/foundation/sheet_position.dart index 434b771..643eaaa 100644 --- a/lib/src/foundation/sheet_position.dart +++ b/lib/src/foundation/sheet_position.dart @@ -16,21 +16,21 @@ import 'sheet_notification.dart'; import 'sheet_physics.dart'; import 'sheet_status.dart'; -/// A representation of a visible height of the sheet. +/// Abstracted representation of a sheet position. /// -/// It is used in a variety of situations, for example, to specify -/// how much area of a sheet is initially visible at first build, +/// It is used in a variety of situations by sheets, for example, +/// to specify how much area of a sheet is initially visible at first build, /// or to limit the range of sheet dragging. /// /// See also: /// - [ProportionalExtent], which is proportional to the content height. /// - [FixedExtent], which is defined by a concrete value in pixels. -abstract interface class Extent { +abstract interface class SheetAnchor { /// {@macro fixed_extent} - const factory Extent.pixels(double pixels) = FixedExtent; + const factory SheetAnchor.pixels(double pixels) = FixedExtent; /// {@macro proportional_extent} - const factory Extent.proportional(double size) = ProportionalExtent; + const factory SheetAnchor.proportional(double size) = ProportionalExtent; /// Resolves the extent to a concrete value in pixels. /// @@ -40,7 +40,7 @@ abstract interface class Extent { } /// An extent that is proportional to the content height. -class ProportionalExtent implements Extent { +class ProportionalExtent implements SheetAnchor { /// {@template proportional_extent} /// Creates an extent that is proportional to the content height. /// @@ -70,7 +70,7 @@ class ProportionalExtent implements Extent { } /// An extent that has an concrete value in pixels. -class FixedExtent implements Extent { +class FixedExtent implements SheetAnchor { /// {@template fixed_extent} /// Creates an extent from a concrete value in pixels. /// {@endtemplate} @@ -128,8 +128,8 @@ abstract class SheetPosition extends ChangeNotifier /// Creates an object that manages the extent of a sheet. SheetPosition({ required this.context, - required Extent minExtent, - required Extent maxExtent, + required SheetAnchor minExtent, + required SheetAnchor maxExtent, required SheetPhysics physics, this.debugLabel, SheetGestureProxyMixin? gestureTamperer, @@ -149,10 +149,10 @@ abstract class SheetPosition extends ChangeNotifier double? get maybePixels => snapshot.maybePixels; @override - Extent? get maybeMinExtent => snapshot.maybeMinExtent; + SheetAnchor? get maybeMinExtent => snapshot.maybeMinExtent; @override - Extent? get maybeMaxExtent => snapshot.maybeMaxExtent; + SheetAnchor? get maybeMaxExtent => snapshot.maybeMaxExtent; @override Size? get maybeContentSize => snapshot.maybeContentSize; @@ -210,8 +210,8 @@ abstract class SheetPosition extends ChangeNotifier /// to ensure that the [SheetMetrics.devicePixelRatio] is always up-to-date. void _updateMetrics({ double? pixels, - Extent? minExtent, - Extent? maxExtent, + SheetAnchor? minExtent, + SheetAnchor? maxExtent, Size? contentSize, Size? viewportSize, EdgeInsets? viewportInsets, @@ -295,7 +295,8 @@ abstract class SheetPosition extends ChangeNotifier } @mustCallSuper - void applyNewBoundaryConstraints(Extent minExtent, Extent maxExtent) { + void applyNewBoundaryConstraints( + SheetAnchor minExtent, SheetAnchor maxExtent) { if (minExtent != this.minExtent || maxExtent != this.maxExtent) { final oldMinExtent = maybeMinExtent; final oldMaxExtent = maybeMaxExtent; @@ -416,7 +417,7 @@ abstract class SheetPosition extends ChangeNotifier beginActivity(BallisticSheetActivity(simulation: simulation)); } - void settleTo(Extent detent, Duration duration) { + void settleTo(SheetAnchor detent, Duration duration) { beginActivity( SettlingSheetActivity.withDuration( duration, @@ -485,7 +486,7 @@ abstract class SheetPosition extends ChangeNotifier /// whether it completed successfully or whether it was /// interrupted prematurely. Future animateTo( - Extent newExtent, { + SheetAnchor newExtent, { Curve curve = Curves.easeInOut, Duration duration = const Duration(milliseconds: 300), }) { @@ -507,8 +508,8 @@ abstract class SheetPosition extends ChangeNotifier @override SheetMetrics copyWith({ double? pixels, - Extent? minExtent, - Extent? maxExtent, + SheetAnchor? minExtent, + SheetAnchor? maxExtent, Size? contentSize, Size? viewportSize, EdgeInsets? viewportInsets, @@ -595,8 +596,8 @@ mixin SheetMetrics { ); double? get maybePixels; - Extent? get maybeMinExtent; - Extent? get maybeMaxExtent; + SheetAnchor? get maybeMinExtent; + SheetAnchor? get maybeMaxExtent; Size? get maybeContentSize; Size? get maybeViewportSize; EdgeInsets? get maybeViewportInsets; @@ -609,8 +610,8 @@ mixin SheetMetrics { /// Creates a copy of the metrics with the given fields replaced. SheetMetrics copyWith({ double? pixels, - Extent? minExtent, - Extent? maxExtent, + SheetAnchor? minExtent, + SheetAnchor? maxExtent, Size? contentSize, Size? viewportSize, EdgeInsets? viewportInsets, @@ -648,13 +649,13 @@ mixin SheetMetrics { } /// The minimum extent of the sheet. - Extent get minExtent { + SheetAnchor get minExtent { assert(_debugAssertHasProperty('minExtent', maybeMinExtent)); return maybeMinExtent!; } /// The maximum extent of the sheet. - Extent get maxExtent { + SheetAnchor get maxExtent { assert(_debugAssertHasProperty('maxExtent', maybeMaxExtent)); return maybeMaxExtent!; } @@ -738,8 +739,8 @@ class SheetMetricsSnapshot with SheetMetrics { /// Creates an immutable snapshot of the state of a sheet. const SheetMetricsSnapshot({ required double? pixels, - required Extent? minExtent, - required Extent? maxExtent, + required SheetAnchor? minExtent, + required SheetAnchor? maxExtent, required Size? contentSize, required Size? viewportSize, required EdgeInsets? viewportInsets, @@ -755,10 +756,10 @@ class SheetMetricsSnapshot with SheetMetrics { final double? maybePixels; @override - final Extent? maybeMinExtent; + final SheetAnchor? maybeMinExtent; @override - final Extent? maybeMaxExtent; + final SheetAnchor? maybeMaxExtent; @override final Size? maybeContentSize; @@ -775,8 +776,8 @@ class SheetMetricsSnapshot with SheetMetrics { @override SheetMetricsSnapshot copyWith({ double? pixels, - Extent? minExtent, - Extent? maxExtent, + SheetAnchor? minExtent, + SheetAnchor? maxExtent, Size? contentSize, Size? viewportSize, EdgeInsets? viewportInsets, diff --git a/lib/src/navigation/navigation_routes.dart b/lib/src/navigation/navigation_routes.dart index 5bcb4ab..352613d 100644 --- a/lib/src/navigation/navigation_routes.dart +++ b/lib/src/navigation/navigation_routes.dart @@ -25,9 +25,9 @@ class _ScrollableNavigationSheetRouteContent extends StatelessWidget { }); final String? debugLabel; - final Extent initialExtent; - final Extent minExtent; - final Extent maxExtent; + final SheetAnchor initialExtent; + final SheetAnchor minExtent; + final SheetAnchor maxExtent; final SheetPhysics? physics; final Widget child; @@ -66,9 +66,9 @@ class _DraggableNavigationSheetRouteContent extends StatelessWidget { }); final String? debugLabel; - final Extent initialExtent; - final Extent minExtent; - final Extent maxExtent; + final SheetAnchor initialExtent; + final SheetAnchor minExtent; + final SheetAnchor maxExtent; final SheetPhysics? physics; final Widget child; @@ -104,17 +104,17 @@ class ScrollableNavigationSheetRoute super.settings, this.maintainState = true, this.transitionDuration = const Duration(milliseconds: 300), - this.initialExtent = const Extent.proportional(1), - this.minExtent = const Extent.proportional(1), - this.maxExtent = const Extent.proportional(1), + this.initialExtent = const SheetAnchor.proportional(1), + this.minExtent = const SheetAnchor.proportional(1), + this.maxExtent = const SheetAnchor.proportional(1), this.physics, this.transitionsBuilder, required this.builder, }); - final Extent initialExtent; - final Extent minExtent; - final Extent maxExtent; + final SheetAnchor initialExtent; + final SheetAnchor minExtent; + final SheetAnchor maxExtent; final SheetPhysics? physics; @override @@ -158,17 +158,17 @@ class DraggableNavigationSheetRoute super.settings, this.maintainState = true, this.transitionDuration = const Duration(milliseconds: 300), - this.initialExtent = const Extent.proportional(1), - this.minExtent = const Extent.proportional(1), - this.maxExtent = const Extent.proportional(1), + this.initialExtent = const SheetAnchor.proportional(1), + this.minExtent = const SheetAnchor.proportional(1), + this.maxExtent = const SheetAnchor.proportional(1), this.physics, this.transitionsBuilder, required this.builder, }); - final Extent initialExtent; - final Extent minExtent; - final Extent maxExtent; + final SheetAnchor initialExtent; + final SheetAnchor minExtent; + final SheetAnchor maxExtent; final SheetPhysics? physics; @override @@ -214,9 +214,9 @@ class ScrollableNavigationSheetPage extends Page { super.restorationId, this.maintainState = true, this.transitionDuration = const Duration(milliseconds: 300), - this.initialExtent = const Extent.proportional(1), - this.minExtent = const Extent.proportional(1), - this.maxExtent = const Extent.proportional(1), + this.initialExtent = const SheetAnchor.proportional(1), + this.minExtent = const SheetAnchor.proportional(1), + this.maxExtent = const SheetAnchor.proportional(1), this.physics, this.transitionsBuilder, required this.child, @@ -227,9 +227,9 @@ class ScrollableNavigationSheetPage extends Page { final Duration transitionDuration; - final Extent initialExtent; - final Extent minExtent; - final Extent maxExtent; + final SheetAnchor initialExtent; + final SheetAnchor minExtent; + final SheetAnchor maxExtent; final SheetPhysics? physics; @@ -294,9 +294,9 @@ class DraggableNavigationSheetPage extends Page { super.restorationId, this.maintainState = true, this.transitionDuration = const Duration(milliseconds: 300), - this.initialExtent = const Extent.proportional(1), - this.minExtent = const Extent.proportional(1), - this.maxExtent = const Extent.proportional(1), + this.initialExtent = const SheetAnchor.proportional(1), + this.minExtent = const SheetAnchor.proportional(1), + this.maxExtent = const SheetAnchor.proportional(1), this.physics, this.transitionsBuilder, required this.child, @@ -307,9 +307,9 @@ class DraggableNavigationSheetPage extends Page { final Duration transitionDuration; - final Extent initialExtent; - final Extent minExtent; - final Extent maxExtent; + final SheetAnchor initialExtent; + final SheetAnchor minExtent; + final SheetAnchor maxExtent; final SheetPhysics? physics; diff --git a/lib/src/navigation/navigation_sheet_extent.dart b/lib/src/navigation/navigation_sheet_extent.dart index c230cc0..19210e5 100644 --- a/lib/src/navigation/navigation_sheet_extent.dart +++ b/lib/src/navigation/navigation_sheet_extent.dart @@ -90,7 +90,7 @@ class NavigationSheetExtent extends SheetPosition { @override Future animateTo( - Extent newExtent, { + SheetAnchor newExtent, { Curve curve = Curves.easeInOut, Duration duration = const Duration(milliseconds: 300), }) { diff --git a/lib/src/navigation/navigation_sheet_extent_scope.dart b/lib/src/navigation/navigation_sheet_extent_scope.dart index 823d600..83b98b6 100644 --- a/lib/src/navigation/navigation_sheet_extent_scope.dart +++ b/lib/src/navigation/navigation_sheet_extent_scope.dart @@ -16,8 +16,8 @@ class NavigationSheetExtentScope extends SheetExtentScope { this.debugLabel, required super.child, }) : super( - minExtent: const Extent.pixels(0), - maxExtent: const Extent.proportional(1), + minExtent: const SheetAnchor.pixels(0), + maxExtent: const SheetAnchor.proportional(1), // TODO: Use more appropriate physics. physics: const ClampingSheetPhysics(), isPrimary: true, diff --git a/lib/src/scrollable/scrollable_sheet.dart b/lib/src/scrollable/scrollable_sheet.dart index ab9d036..c3c9617 100644 --- a/lib/src/scrollable/scrollable_sheet.dart +++ b/lib/src/scrollable/scrollable_sheet.dart @@ -16,22 +16,22 @@ import 'sheet_scrollable.dart'; class ScrollableSheet extends StatefulWidget { const ScrollableSheet({ super.key, - this.initialExtent = const Extent.proportional(1), - this.minExtent = const Extent.proportional(1), - this.maxExtent = const Extent.proportional(1), + this.initialExtent = const SheetAnchor.proportional(1), + this.minExtent = const SheetAnchor.proportional(1), + this.maxExtent = const SheetAnchor.proportional(1), this.physics, this.controller, required this.child, }); /// {@macro ScrollableSheetExtent.initialExtent} - final Extent initialExtent; + final SheetAnchor initialExtent; /// {@macro SheetExtent.minExtent} - final Extent minExtent; + final SheetAnchor minExtent; /// {@macro SheetExtent.maxExtent} - final Extent maxExtent; + final SheetAnchor maxExtent; /// {@macro SheetExtent.physics} final SheetPhysics? physics; diff --git a/lib/src/scrollable/scrollable_sheet_extent.dart b/lib/src/scrollable/scrollable_sheet_extent.dart index 98d7fc8..eeaf112 100644 --- a/lib/src/scrollable/scrollable_sheet_extent.dart +++ b/lib/src/scrollable/scrollable_sheet_extent.dart @@ -29,7 +29,7 @@ class ScrollableSheetExtent extends SheetPosition /// {@template ScrollableSheetExtent.initialExtent} /// The initial extent of the sheet. /// {@endtemplate} - final Extent initialExtent; + final SheetAnchor initialExtent; @override ScrollableSheetPhysics get physics => super.physics as ScrollableSheetPhysics; diff --git a/lib/src/scrollable/scrollable_sheet_extent_scope.dart b/lib/src/scrollable/scrollable_sheet_extent_scope.dart index 506c466..d6e8497 100644 --- a/lib/src/scrollable/scrollable_sheet_extent_scope.dart +++ b/lib/src/scrollable/scrollable_sheet_extent_scope.dart @@ -22,7 +22,7 @@ class ScrollableSheetExtentScope extends SheetExtentScope { }); /// {@macro ScrollableSheetExtent.initialExtent} - final Extent initialExtent; + final SheetAnchor initialExtent; /// {@macro SheetExtent.debugLabel} final String? debugLabel; diff --git a/test/draggable/draggable_sheet_test.dart b/test/draggable/draggable_sheet_test.dart index 027750b..fef47eb 100644 --- a/test/draggable/draggable_sheet_test.dart +++ b/test/draggable/draggable_sheet_test.dart @@ -85,8 +85,8 @@ void main() { child: DraggableSheet( key: sheetKey, controller: controller, - minExtent: const Extent.pixels(200), - initialExtent: const Extent.pixels(200), + minExtent: const SheetAnchor.pixels(200), + initialExtent: const SheetAnchor.pixels(200), child: const Material( child: _TestSheetContent( height: 500, @@ -105,7 +105,7 @@ void main() { // Start animating the sheet to the max extent. unawaited( controller.animateTo( - const Extent.proportional(1), + const SheetAnchor.proportional(1), duration: const Duration(milliseconds: 250), ), ); diff --git a/test/foundation/physics_test.dart b/test/foundation/physics_test.dart index 995043b..3abae29 100644 --- a/test/foundation/physics_test.dart +++ b/test/foundation/physics_test.dart @@ -15,8 +15,8 @@ class _SheetPhysicsWithDefaultConfiguration extends SheetPhysics } const _referenceSheetMetrics = SheetMetricsSnapshot( - minExtent: Extent.pixels(0), - maxExtent: Extent.proportional(1), + minExtent: SheetAnchor.pixels(0), + maxExtent: SheetAnchor.proportional(1), pixels: 600, contentSize: Size(360, 600), viewportSize: Size(360, 700), @@ -164,12 +164,12 @@ void main() { test('findSettledExtent', () { expect( physicsUnderTest.findSettledExtent(0, _positionAtMiddle), - Extent.pixels(_positionAtMiddle.pixels), + SheetAnchor.pixels(_positionAtMiddle.pixels), reason: 'Should return the current position if it is in bounds', ); expect( physicsUnderTest.findSettledExtent(1000, _positionAtMiddle), - Extent.pixels(_positionAtMiddle.pixels), + SheetAnchor.pixels(_positionAtMiddle.pixels), reason: 'The velocity should not affect the result', ); @@ -295,9 +295,9 @@ void main() { behaviorUnderTest = SnapToNearest( minFlingSpeed: 50, snapTo: [ - Extent.pixels(_positionAtBottomEdge.pixels), - Extent.pixels(_positionAtMiddle.pixels), - Extent.pixels(_positionAtTopEdge.pixels), + SheetAnchor.pixels(_positionAtBottomEdge.pixels), + SheetAnchor.pixels(_positionAtMiddle.pixels), + SheetAnchor.pixels(_positionAtTopEdge.pixels), ], ); }); @@ -315,15 +315,15 @@ void main() { expect( behaviorUnderTest.findSettledExtent(0, positionAtNearTopEdge), - Extent.pixels(_referenceSheetMetrics.maxPixels), + SheetAnchor.pixels(_referenceSheetMetrics.maxPixels), ); expect( behaviorUnderTest.findSettledExtent(0, positionAtNearMiddle), - Extent.pixels(_positionAtMiddle.pixels), + SheetAnchor.pixels(_positionAtMiddle.pixels), ); expect( behaviorUnderTest.findSettledExtent(0, positionAtNearBottomEdge), - Extent.pixels(_referenceSheetMetrics.minPixels), + SheetAnchor.pixels(_referenceSheetMetrics.minPixels), ); }); @@ -337,22 +337,22 @@ void main() { // Flings up at the bottom edge expect( behaviorUnderTest.findSettledExtent(50, _positionAtBottomEdge), - Extent.pixels(_positionAtMiddle.pixels), + SheetAnchor.pixels(_positionAtMiddle.pixels), ); // Flings up at the slightly above the middle position expect( behaviorUnderTest.findSettledExtent(50, positionAtAboveMiddle), - Extent.pixels(_positionAtTopEdge.pixels), + SheetAnchor.pixels(_positionAtTopEdge.pixels), ); // Flings down at the top edge expect( behaviorUnderTest.findSettledExtent(-50, _positionAtTopEdge), - Extent.pixels(_positionAtMiddle.pixels), + SheetAnchor.pixels(_positionAtMiddle.pixels), ); // Flings down at the slightly below the middle position expect( behaviorUnderTest.findSettledExtent(-50, positionAtBelowMiddle), - Extent.pixels(_positionAtBottomEdge.pixels), + SheetAnchor.pixels(_positionAtBottomEdge.pixels), ); }); @@ -384,14 +384,14 @@ void main() { test('Boundary condition: flings up exactly at the top detent', () { expect( behaviorUnderTest.findSettledExtent(50, _positionAtTopEdge), - Extent.pixels(_positionAtTopEdge.pixels), + SheetAnchor.pixels(_positionAtTopEdge.pixels), ); }); test('Boundary condition: flings down exactly at the top detent', () { expect( behaviorUnderTest.findSettledExtent(-50, _positionAtTopEdge), - Extent.pixels(_positionAtMiddle.pixels), + SheetAnchor.pixels(_positionAtMiddle.pixels), ); }); @@ -405,14 +405,14 @@ void main() { test('Boundary condition: flings up exactly at the middle detent', () { expect( behaviorUnderTest.findSettledExtent(50, _positionAtMiddle), - Extent.pixels(_positionAtTopEdge.pixels), + SheetAnchor.pixels(_positionAtTopEdge.pixels), ); }); test('Boundary condition: flings down exactly at the middle detent', () { expect( behaviorUnderTest.findSettledExtent(-50, _positionAtMiddle), - Extent.pixels(_positionAtBottomEdge.pixels), + SheetAnchor.pixels(_positionAtBottomEdge.pixels), ); }); @@ -426,26 +426,26 @@ void main() { test('Boundary condition: flings up exactly at the bottom detent', () { expect( behaviorUnderTest.findSettledExtent(50, _positionAtBottomEdge), - Extent.pixels(_positionAtMiddle.pixels), + SheetAnchor.pixels(_positionAtMiddle.pixels), ); }); test('Boundary condition: flings down exactly at the bottom detent', () { expect( behaviorUnderTest.findSettledExtent(-50, _positionAtBottomEdge), - Extent.pixels(_positionAtBottomEdge.pixels), + SheetAnchor.pixels(_positionAtBottomEdge.pixels), ); }); }); test('FixedBouncingBehavior returns same value for same input metrics', () { expect( - const FixedBouncingBehavior(Extent.pixels(100)) + const FixedBouncingBehavior(SheetAnchor.pixels(100)) .computeBounceablePixels(50, _referenceSheetMetrics), 100, ); expect( - const FixedBouncingBehavior(Extent.proportional(0.5)) + const FixedBouncingBehavior(SheetAnchor.proportional(0.5)) .computeBounceablePixels(50, _referenceSheetMetrics), 300, ); @@ -453,8 +453,8 @@ void main() { test('DirectionAwareBouncingBehavior respects gesture direction', () { const behavior = DirectionAwareBouncingBehavior( - upward: Extent.pixels(100), - downward: Extent.pixels(0), + upward: SheetAnchor.pixels(100), + downward: SheetAnchor.pixels(0), ); expect(behavior.computeBounceablePixels(50, _referenceSheetMetrics), 100); expect(behavior.computeBounceablePixels(-50, _referenceSheetMetrics), 0); @@ -463,7 +463,7 @@ void main() { group('BouncingSheetPhysics', () { test('progressively applies friction if position is out of bounds', () { const physics = BouncingSheetPhysics( - behavior: FixedBouncingBehavior(Extent.pixels(50)), + behavior: FixedBouncingBehavior(SheetAnchor.pixels(50)), frictionCurve: Curves.linear, ); @@ -480,7 +480,7 @@ void main() { test('does not allow to go beyond bounceable bounds', () { const physics = BouncingSheetPhysics( - behavior: FixedBouncingBehavior(Extent.pixels(30)), + behavior: FixedBouncingBehavior(SheetAnchor.pixels(30)), frictionCurve: Curves.linear, ); @@ -503,7 +503,7 @@ void main() { test('applies friction even if position is on boundary', () { const physics = BouncingSheetPhysics( - behavior: FixedBouncingBehavior(Extent.pixels(50)), + behavior: FixedBouncingBehavior(SheetAnchor.pixels(50)), frictionCurve: Curves.linear, ); @@ -513,7 +513,7 @@ void main() { test('can apply a reasonable friction to extremely large offset', () { const physics = BouncingSheetPhysics( - behavior: FixedBouncingBehavior(Extent.pixels(50)), + behavior: FixedBouncingBehavior(SheetAnchor.pixels(50)), frictionCurve: Curves.linear, ); @@ -531,13 +531,13 @@ void main() { group('sortExtentsAndFindNearest', () { test('with two extents', () { final (sortedExtents, nearestIndex) = sortExtentsAndFindNearest( - const [Extent.proportional(1), Extent.pixels(0)], + const [SheetAnchor.proportional(1), SheetAnchor.pixels(0)], 250, const Size(400, 600), ); expect(sortedExtents, const [ - (extent: Extent.pixels(0), resolved: 0), - (extent: Extent.proportional(1), resolved: 600), + (extent: SheetAnchor.pixels(0), resolved: 0), + (extent: SheetAnchor.proportional(1), resolved: 600), ]); expect(nearestIndex, 0); }); @@ -545,17 +545,17 @@ void main() { test('with three extents', () { final (sortedExtents, nearestIndex) = sortExtentsAndFindNearest( const [ - Extent.proportional(1), - Extent.proportional(0.5), - Extent.pixels(0), + SheetAnchor.proportional(1), + SheetAnchor.proportional(0.5), + SheetAnchor.pixels(0), ], 250, const Size(400, 600), ); expect(sortedExtents, const [ - (extent: Extent.pixels(0), resolved: 0), - (extent: Extent.proportional(0.5), resolved: 300), - (extent: Extent.proportional(1), resolved: 600), + (extent: SheetAnchor.pixels(0), resolved: 0), + (extent: SheetAnchor.proportional(0.5), resolved: 300), + (extent: SheetAnchor.proportional(1), resolved: 600), ]); expect(nearestIndex, 1); }); @@ -563,21 +563,21 @@ void main() { test('with more than three extents', () { final (sortedExtents, nearestIndex) = sortExtentsAndFindNearest( const [ - Extent.proportional(0.25), - Extent.proportional(0.5), - Extent.proportional(0.75), - Extent.pixels(0), - Extent.proportional(1), + SheetAnchor.proportional(0.25), + SheetAnchor.proportional(0.5), + SheetAnchor.proportional(0.75), + SheetAnchor.pixels(0), + SheetAnchor.proportional(1), ], 500, const Size(400, 600), ); expect(sortedExtents, const [ - (extent: Extent.pixels(0), resolved: 0), - (extent: Extent.proportional(0.25), resolved: 150), - (extent: Extent.proportional(0.5), resolved: 300), - (extent: Extent.proportional(0.75), resolved: 450), - (extent: Extent.proportional(1), resolved: 600), + (extent: SheetAnchor.pixels(0), resolved: 0), + (extent: SheetAnchor.proportional(0.25), resolved: 150), + (extent: SheetAnchor.proportional(0.5), resolved: 300), + (extent: SheetAnchor.proportional(0.75), resolved: 450), + (extent: SheetAnchor.proportional(1), resolved: 600), ]); expect(nearestIndex, 3); }); diff --git a/test/foundation/sheet_activity_test.dart b/test/foundation/sheet_activity_test.dart index 5edfecd..ef30620 100644 --- a/test/foundation/sheet_activity_test.dart +++ b/test/foundation/sheet_activity_test.dart @@ -43,8 +43,8 @@ void main() { test('should animate to the destination', () { final (ownerMetrics, owner) = createMockSheetExtent( pixels: 300, - minExtent: const Extent.pixels(300), - maxExtent: const Extent.pixels(700), + minExtent: const SheetAnchor.pixels(300), + maxExtent: const SheetAnchor.pixels(700), contentSize: const Size(400, 700), viewportSize: const Size(400, 900), viewportInsets: EdgeInsets.zero, @@ -53,7 +53,7 @@ void main() { final activity = _TestAnimatedSheetActivity( controller: controller, - destination: const Extent.pixels(700), + destination: const SheetAnchor.pixels(700), duration: const Duration(milliseconds: 300), curve: Curves.linear, )..init(owner); @@ -82,8 +82,8 @@ void main() { test('should absorb viewport changes', () { final (ownerMetrics, owner) = createMockSheetExtent( pixels: 300, - minExtent: const Extent.pixels(300), - maxExtent: const Extent.proportional(1), + minExtent: const SheetAnchor.pixels(300), + maxExtent: const SheetAnchor.proportional(1), contentSize: const Size(400, 900), viewportSize: const Size(400, 900), viewportInsets: EdgeInsets.zero, @@ -92,7 +92,7 @@ void main() { final activity = _TestAnimatedSheetActivity( controller: controller, - destination: const Extent.proportional(1), + destination: const SheetAnchor.proportional(1), duration: const Duration(milliseconds: 300), curve: Curves.linear, )..init(owner); @@ -127,7 +127,7 @@ void main() { expect(ownerMetrics.viewPixels, 450, reason: 'Visual position should not change when viewport changes.'); verify(owner.settleTo( - const Extent.proportional(1), + const SheetAnchor.proportional(1), const Duration(milliseconds: 225), )); }); @@ -142,8 +142,8 @@ void main() { setUp(() { (ownerMetrics, owner) = createMockSheetExtent( pixels: 300, - minExtent: const Extent.proportional(0.5), - maxExtent: const Extent.proportional(1), + minExtent: const SheetAnchor.proportional(0.5), + maxExtent: const SheetAnchor.proportional(1), contentSize: const Size(400, 600), viewportSize: const Size(400, 900), viewportInsets: EdgeInsets.zero, @@ -167,11 +167,11 @@ void main() { test('Create with velocity', () { final activity = SettlingSheetActivity( - destination: const Extent.pixels(0), + destination: const SheetAnchor.pixels(0), velocity: 100, ); - expect(activity.destination, const Extent.pixels(0)); + expect(activity.destination, const SheetAnchor.pixels(0)); expect(activity.duration, isNull); expect(activity.velocity, 100); expect(activity.shouldIgnorePointer, isFalse); @@ -180,10 +180,10 @@ void main() { test('Create with duration', () { final activity = SettlingSheetActivity.withDuration( const Duration(milliseconds: 300), - destination: const Extent.pixels(0), + destination: const SheetAnchor.pixels(0), ); - expect(activity.destination, const Extent.pixels(0)); + expect(activity.destination, const SheetAnchor.pixels(0)); expect(activity.duration, const Duration(milliseconds: 300)); expect(activity.shouldIgnorePointer, isFalse); expect(() => activity.velocity, isNotInitialized); @@ -194,7 +194,7 @@ void main() { () { final activity = SettlingSheetActivity.withDuration( const Duration(milliseconds: 300), - destination: const Extent.proportional(1), + destination: const SheetAnchor.proportional(1), ); expect(() => activity.velocity, isNotInitialized); @@ -205,7 +205,7 @@ void main() { test('Progressively updates current position toward destination', () { final activity = SettlingSheetActivity( - destination: const Extent.proportional(1), + destination: const SheetAnchor.proportional(1), velocity: 300, ); @@ -232,7 +232,7 @@ void main() { 'Should start an idle activity when it reaches destination', () { final _ = SettlingSheetActivity( - destination: const Extent.proportional(1), + destination: const SheetAnchor.proportional(1), velocity: 300, )..init(owner); @@ -245,7 +245,7 @@ void main() { test('Should absorb viewport changes', () { final activity = SettlingSheetActivity.withDuration( const Duration(milliseconds: 300), - destination: const Extent.proportional(1), + destination: const SheetAnchor.proportional(1), )..init(owner); expect(activity.velocity, 1000); // (300 pixels / 0.3s) = 1000 pixels/s @@ -274,8 +274,8 @@ void main() { test('should maintain previous extent when keyboard appears', () { final (ownerMetrics, owner) = createMockSheetExtent( pixels: 450, - minExtent: const Extent.proportional(0.5), - maxExtent: const Extent.proportional(1), + minExtent: const SheetAnchor.proportional(0.5), + maxExtent: const SheetAnchor.proportional(1), contentSize: const Size(400, 850), viewportSize: const Size(400, 900), viewportInsets: const EdgeInsets.only(bottom: 50), @@ -299,8 +299,8 @@ void main() { () { final (ownerMetrics, owner) = createMockSheetExtent( pixels: 300, - minExtent: const Extent.proportional(0.5), - maxExtent: const Extent.proportional(1), + minExtent: const SheetAnchor.proportional(0.5), + maxExtent: const SheetAnchor.proportional(1), contentSize: const Size(400, 580), viewportSize: const Size(400, 900), viewportInsets: EdgeInsets.zero, @@ -325,8 +325,8 @@ void main() { () { final (ownerMetrics, owner) = createMockSheetExtent( pixels: 300, - minExtent: const Extent.proportional(0.5), - maxExtent: const Extent.proportional(1), + minExtent: const SheetAnchor.proportional(0.5), + maxExtent: const SheetAnchor.proportional(1), contentSize: const Size(400, 500), viewportSize: const Size(400, 900), viewportInsets: EdgeInsets.zero, @@ -342,7 +342,7 @@ void main() { expect(ownerMetrics.pixels, 300); verify( owner.animateTo( - const Extent.proportional(0.5), + const SheetAnchor.proportional(0.5), duration: anyNamed('duration'), curve: anyNamed('curve'), ), diff --git a/test/foundation/sheet_notification_test.dart b/test/foundation/sheet_notification_test.dart index 3406b25..d1443dd 100644 --- a/test/foundation/sheet_notification_test.dart +++ b/test/foundation/sheet_notification_test.dart @@ -24,7 +24,7 @@ void main() { return false; }, child: DraggableSheet( - minExtent: const Extent.pixels(0), + minExtent: const SheetAnchor.pixels(0), // Disable the snapping effect physics: const ClampingSheetPhysics(), child: Container( @@ -168,7 +168,7 @@ void main() { }, child: DraggableSheet( controller: controller, - minExtent: const Extent.pixels(0), + minExtent: const SheetAnchor.pixels(0), // Disable the snapping effect physics: const ClampingSheetPhysics(), child: Container( @@ -182,7 +182,7 @@ void main() { unawaited( controller.animateTo( - const Extent.pixels(0), + const SheetAnchor.pixels(0), duration: const Duration(milliseconds: 300), curve: Curves.linear, ), @@ -244,8 +244,8 @@ void main() { }, child: DraggableSheet( // Make sure the sheet can't be dragged - minExtent: const Extent.proportional(1), - maxExtent: const Extent.proportional(1), + minExtent: const SheetAnchor.proportional(1), + maxExtent: const SheetAnchor.proportional(1), // Disable the snapping effect physics: const ClampingSheetPhysics(), child: Container( @@ -319,7 +319,7 @@ void main() { return false; }, child: DraggableSheet( - minExtent: const Extent.pixels(0), + minExtent: const SheetAnchor.pixels(0), // Disable the snapping effect physics: const ClampingSheetPhysics(), child: Container( diff --git a/test/foundation/sheet_viewport_test.dart b/test/foundation/sheet_viewport_test.dart index af24f21..4b996da 100644 --- a/test/foundation/sheet_viewport_test.dart +++ b/test/foundation/sheet_viewport_test.dart @@ -41,8 +41,8 @@ class _FakeSheetExtent extends SheetPosition { this.createIdleActivity, }) : super( context: _FakeSheetContext(), - minExtent: const Extent.proportional(0.5), - maxExtent: const Extent.proportional(1), + minExtent: const SheetAnchor.proportional(0.5), + maxExtent: const SheetAnchor.proportional(1), physics: const ClampingSheetPhysics(), ); diff --git a/test/navigation/navigation_sheet_test.dart b/test/navigation/navigation_sheet_test.dart index 7ce74be..3726272 100644 --- a/test/navigation/navigation_sheet_test.dart +++ b/test/navigation/navigation_sheet_test.dart @@ -123,8 +123,8 @@ class _TestDraggablePageWidget extends StatelessWidget { required String label, required double height, String? nextRoute, - Extent initialExtent = const Extent.proportional(1), - Extent minExtent = const Extent.proportional(1), + SheetAnchor initialExtent = const SheetAnchor.proportional(1), + SheetAnchor minExtent = const SheetAnchor.proportional(1), Duration transitionDuration = const Duration(milliseconds: 300), SheetPhysics? physics, }) { @@ -202,8 +202,8 @@ class _TestScrollablePageWidget extends StatelessWidget { double? height, int itemCount = 30, String? nextRoute, - Extent initialExtent = const Extent.proportional(1), - Extent minExtent = const Extent.proportional(1), + SheetAnchor initialExtent = const SheetAnchor.proportional(1), + SheetAnchor minExtent = const SheetAnchor.proportional(1), Duration transitionDuration = const Duration(milliseconds: 300), SheetPhysics? physics, void Function(int index)? onTapItem, @@ -255,7 +255,7 @@ void main() { key: const Key('First'), label: 'First', height: 300, - minExtent: const Extent.pixels(0), + minExtent: const SheetAnchor.pixels(0), // Disable the snapping effect. physics: const ClampingSheetPhysics(), ), @@ -302,13 +302,13 @@ void main() { label: 'First', nextRoute: 'second', height: 300, - minExtent: const Extent.proportional(1), + minExtent: const SheetAnchor.proportional(1), ), 'second': () => _TestDraggablePageWidget.createRoute( key: const Key('Second'), label: 'Second', height: 500, - minExtent: const Extent.pixels(200), + minExtent: const SheetAnchor.pixels(200), transitionDuration: const Duration(milliseconds: 300), ), }, @@ -360,7 +360,7 @@ void main() { key: const Key('First'), label: 'First', height: 300, - minExtent: const Extent.pixels(0), + minExtent: const SheetAnchor.pixels(0), physics: const ClampingSheetPhysics(), ), }, @@ -458,8 +458,8 @@ void main() { 'first': () => _TestDraggablePageWidget.createRoute( label: 'First', height: 500, - minExtent: const Extent.pixels(200), - initialExtent: const Extent.pixels(200), + minExtent: const SheetAnchor.pixels(200), + initialExtent: const SheetAnchor.pixels(200), ), }, contentBuilder: (context, child) { @@ -483,7 +483,7 @@ void main() { // Start animating the sheet to the max extent. unawaited( controller.animateTo( - const Extent.proportional(1), + const SheetAnchor.proportional(1), duration: const Duration(milliseconds: 250), ), ); diff --git a/test/scrollable/scrollable_sheet_test.dart b/test/scrollable/scrollable_sheet_test.dart index 5f4769b..6073094 100644 --- a/test/scrollable/scrollable_sheet_test.dart +++ b/test/scrollable/scrollable_sheet_test.dart @@ -106,8 +106,8 @@ void main() { child: ScrollableSheet( key: sheetKey, controller: controller, - minExtent: const Extent.pixels(200), - initialExtent: const Extent.pixels(200), + minExtent: const SheetAnchor.pixels(200), + initialExtent: const SheetAnchor.pixels(200), child: const _TestSheetContent(height: 500), ), ), @@ -122,7 +122,7 @@ void main() { // Start animating the sheet to the max extent. unawaited( controller.animateTo( - const Extent.proportional(1), + const SheetAnchor.proportional(1), duration: const Duration(milliseconds: 250), ), ); diff --git a/test/src/stubbing.dart b/test/src/stubbing.dart index 9964d6a..75a494b 100644 --- a/test/src/stubbing.dart +++ b/test/src/stubbing.dart @@ -33,10 +33,10 @@ class MutableSheetMetrics with SheetMetrics { double devicePixelRatio; @override - Extent? maybeMaxExtent; + SheetAnchor? maybeMaxExtent; @override - Extent? maybeMinExtent; + SheetAnchor? maybeMinExtent; @override double? maybePixels; @@ -53,8 +53,8 @@ class MutableSheetMetrics with SheetMetrics { @override SheetMetrics copyWith({ double? pixels, - Extent? minExtent, - Extent? maxExtent, + SheetAnchor? minExtent, + SheetAnchor? maxExtent, Size? contentSize, Size? viewportSize, EdgeInsets? viewportInsets, @@ -74,8 +74,8 @@ class MutableSheetMetrics with SheetMetrics { (MutableSheetMetrics, MockSheetExtent) createMockSheetExtent({ required double pixels, - required Extent minExtent, - required Extent maxExtent, + required SheetAnchor minExtent, + required SheetAnchor maxExtent, required Size contentSize, required Size viewportSize, required EdgeInsets viewportInsets, @@ -127,8 +127,8 @@ class MutableSheetMetrics with SheetMetrics { }); when(extent.applyNewBoundaryConstraints(any, any)).thenAnswer((invocation) { metricsRegistry - ..maybeMinExtent = invocation.positionalArguments.first as Extent - ..maybeMaxExtent = invocation.positionalArguments.last as Extent; + ..maybeMinExtent = invocation.positionalArguments.first as SheetAnchor + ..maybeMaxExtent = invocation.positionalArguments.last as SheetAnchor; }); when(extent.copyWith( pixels: anyNamed('pixels'), @@ -141,8 +141,8 @@ class MutableSheetMetrics with SheetMetrics { )).thenAnswer((invocation) { return metricsRegistry.copyWith( pixels: invocation.namedArguments[#pixels] as double?, - minExtent: invocation.namedArguments[#minExtent] as Extent?, - maxExtent: invocation.namedArguments[#maxExtent] as Extent?, + minExtent: invocation.namedArguments[#minExtent] as SheetAnchor?, + maxExtent: invocation.namedArguments[#maxExtent] as SheetAnchor?, contentSize: invocation.namedArguments[#contentSize] as Size?, viewportSize: invocation.namedArguments[#viewportSize] as Size?, viewportInsets: invocation.namedArguments[#viewportInsets] as EdgeInsets?, diff --git a/test/src/stubbing.mocks.dart b/test/src/stubbing.mocks.dart index d16f001..01fe974 100644 --- a/test/src/stubbing.mocks.dart +++ b/test/src/stubbing.mocks.dart @@ -76,7 +76,7 @@ class _FakeSheetMetrics_3 extends _i1.SmartFake implements _i4.SheetMetrics { ); } -class _FakeExtent_4 extends _i1.SmartFake implements _i4.Extent { +class _FakeExtent_4 extends _i1.SmartFake implements _i4.SheetAnchor { _FakeExtent_4( Object parent, Invocation parentInvocation, @@ -296,7 +296,7 @@ class MockSheetExtent extends _i1.Mock implements _i4.SheetPosition { ) as double); @override - _i4.Extent get minExtent => (super.noSuchMethod( + _i4.SheetAnchor get minExtent => (super.noSuchMethod( Invocation.getter(#minExtent), returnValue: _FakeExtent_4( this, @@ -306,10 +306,10 @@ class MockSheetExtent extends _i1.Mock implements _i4.SheetPosition { this, Invocation.getter(#minExtent), ), - ) as _i4.Extent); + ) as _i4.SheetAnchor); @override - _i4.Extent get maxExtent => (super.noSuchMethod( + _i4.SheetAnchor get maxExtent => (super.noSuchMethod( Invocation.getter(#maxExtent), returnValue: _FakeExtent_4( this, @@ -319,7 +319,7 @@ class MockSheetExtent extends _i1.Mock implements _i4.SheetPosition { this, Invocation.getter(#maxExtent), ), - ) as _i4.Extent); + ) as _i4.SheetAnchor); @override _i6.Size get contentSize => (super.noSuchMethod( @@ -457,8 +457,8 @@ class MockSheetExtent extends _i1.Mock implements _i4.SheetPosition { @override void applyNewBoundaryConstraints( - _i4.Extent? minExtent, - _i4.Extent? maxExtent, + _i4.SheetAnchor? minExtent, + _i4.SheetAnchor? maxExtent, ) => super.noSuchMethod( Invocation.method( @@ -537,7 +537,7 @@ class MockSheetExtent extends _i1.Mock implements _i4.SheetPosition { @override void settleTo( - _i4.Extent? detent, + _i4.SheetAnchor? detent, Duration? duration, ) => super.noSuchMethod( @@ -615,7 +615,7 @@ class MockSheetExtent extends _i1.Mock implements _i4.SheetPosition { @override _i9.Future animateTo( - _i4.Extent? newExtent, { + _i4.SheetAnchor? newExtent, { _i7.Curve? curve = _i7.Curves.easeInOut, Duration? duration = const Duration(milliseconds: 300), }) => @@ -635,8 +635,8 @@ class MockSheetExtent extends _i1.Mock implements _i4.SheetPosition { @override _i4.SheetMetrics copyWith({ double? pixels, - _i4.Extent? minExtent, - _i4.Extent? maxExtent, + _i4.SheetAnchor? minExtent, + _i4.SheetAnchor? maxExtent, _i6.Size? contentSize, _i6.Size? viewportSize, _i7.EdgeInsets? viewportInsets, From df508fa56c885715c3e28270d2accd90f7cce0ee Mon Sep 17 00:00:00 2001 From: fujidaiti Date: Thu, 26 Sep 2024 22:00:09 +0900 Subject: [PATCH 08/22] Rename ProportionalExtent to ProportionalSheetAnchor --- lib/src/foundation/foundation.dart | 2 +- lib/src/foundation/sheet_position.dart | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/src/foundation/foundation.dart b/lib/src/foundation/foundation.dart index dacb068..ac6c8c8 100644 --- a/lib/src/foundation/foundation.dart +++ b/lib/src/foundation/foundation.dart @@ -50,7 +50,7 @@ export 'sheet_physics.dart' export 'sheet_position.dart' show FixedExtent, - ProportionalExtent, + ProportionalSheetAnchor, SheetAnchor, SheetMetrics, SheetMetricsSnapshot; diff --git a/lib/src/foundation/sheet_position.dart b/lib/src/foundation/sheet_position.dart index 643eaaa..c12006d 100644 --- a/lib/src/foundation/sheet_position.dart +++ b/lib/src/foundation/sheet_position.dart @@ -23,14 +23,14 @@ import 'sheet_status.dart'; /// or to limit the range of sheet dragging. /// /// See also: -/// - [ProportionalExtent], which is proportional to the content height. +/// - [ProportionalSheetAnchor], which is proportional to the content height. /// - [FixedExtent], which is defined by a concrete value in pixels. abstract interface class SheetAnchor { /// {@macro fixed_extent} const factory SheetAnchor.pixels(double pixels) = FixedExtent; /// {@macro proportional_extent} - const factory SheetAnchor.proportional(double size) = ProportionalExtent; + const factory SheetAnchor.proportional(double size) = ProportionalSheetAnchor; /// Resolves the extent to a concrete value in pixels. /// @@ -39,15 +39,15 @@ abstract interface class SheetAnchor { double resolve(Size contentSize); } -/// An extent that is proportional to the content height. -class ProportionalExtent implements SheetAnchor { +/// An [SheetAnchor] that is proportional to the content height. +class ProportionalSheetAnchor implements SheetAnchor { /// {@template proportional_extent} /// Creates an extent that is proportional to the content height. /// /// The [factor] must be greater than or equal to 0. /// This extent will resolve to `contentSize.height * factor`. /// {@endtemplate} - const ProportionalExtent(this.factor) : assert(factor >= 0); + const ProportionalSheetAnchor(this.factor) : assert(factor >= 0); /// The fraction of the content height. final double factor; @@ -58,7 +58,7 @@ class ProportionalExtent implements SheetAnchor { @override bool operator ==(Object other) => identical(this, other) || - (other is ProportionalExtent && + (other is ProportionalSheetAnchor && runtimeType == other.runtimeType && factor == other.factor); @@ -66,7 +66,7 @@ class ProportionalExtent implements SheetAnchor { int get hashCode => Object.hash(runtimeType, factor); @override - String toString() => '$ProportionalExtent(factor: $factor)'; + String toString() => '$ProportionalSheetAnchor(factor: $factor)'; } /// An extent that has an concrete value in pixels. From 638a9ac1d1d2f6c1f33be1fd4ae733a64787c5b1 Mon Sep 17 00:00:00 2001 From: fujidaiti Date: Thu, 26 Sep 2024 22:01:15 +0900 Subject: [PATCH 09/22] Rename FixedExtent to FixedSheetAnchor --- lib/src/foundation/foundation.dart | 2 +- lib/src/foundation/sheet_position.dart | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/src/foundation/foundation.dart b/lib/src/foundation/foundation.dart index ac6c8c8..c86520a 100644 --- a/lib/src/foundation/foundation.dart +++ b/lib/src/foundation/foundation.dart @@ -49,7 +49,7 @@ export 'sheet_physics.dart' kDefaultSheetSpring; export 'sheet_position.dart' show - FixedExtent, + FixedSheetAnchor, ProportionalSheetAnchor, SheetAnchor, SheetMetrics, diff --git a/lib/src/foundation/sheet_position.dart b/lib/src/foundation/sheet_position.dart index c12006d..9696c61 100644 --- a/lib/src/foundation/sheet_position.dart +++ b/lib/src/foundation/sheet_position.dart @@ -24,10 +24,10 @@ import 'sheet_status.dart'; /// /// See also: /// - [ProportionalSheetAnchor], which is proportional to the content height. -/// - [FixedExtent], which is defined by a concrete value in pixels. +/// - [FixedSheetAnchor], which is defined by a concrete value in pixels. abstract interface class SheetAnchor { - /// {@macro fixed_extent} - const factory SheetAnchor.pixels(double pixels) = FixedExtent; + /// {@macro FixedSheetAnchor} + const factory SheetAnchor.pixels(double pixels) = FixedSheetAnchor; /// {@macro proportional_extent} const factory SheetAnchor.proportional(double size) = ProportionalSheetAnchor; @@ -69,12 +69,12 @@ class ProportionalSheetAnchor implements SheetAnchor { String toString() => '$ProportionalSheetAnchor(factor: $factor)'; } -/// An extent that has an concrete value in pixels. -class FixedExtent implements SheetAnchor { - /// {@template fixed_extent} - /// Creates an extent from a concrete value in pixels. +/// A [SheetAnchor] that has a concrete value in pixels. +class FixedSheetAnchor implements SheetAnchor { + /// {@template FixedSheetAnchor} + /// Creates an anchor from a concrete value in pixels. /// {@endtemplate} - const FixedExtent(this.pixels) : assert(pixels >= 0); + const FixedSheetAnchor(this.pixels) : assert(pixels >= 0); /// The value in pixels. final double pixels; @@ -85,7 +85,7 @@ class FixedExtent implements SheetAnchor { @override bool operator ==(Object other) => identical(this, other) || - (other is FixedExtent && + (other is FixedSheetAnchor && runtimeType == other.runtimeType && pixels == other.pixels); @@ -93,7 +93,7 @@ class FixedExtent implements SheetAnchor { int get hashCode => Object.hash(runtimeType, pixels); @override - String toString() => '$FixedExtent(pixels: $pixels)'; + String toString() => '$FixedSheetAnchor(pixels: $pixels)'; } /// Manages the extent of a sheet. From 155739e567cd32cc41fbb2d66aafe9ad1aa94d87 Mon Sep 17 00:00:00 2001 From: fujidaiti Date: Thu, 26 Sep 2024 23:27:19 +0900 Subject: [PATCH 10/22] Replace "extent"s in comments with "position"s --- lib/src/foundation/sheet_extent_scope.dart | 2 +- lib/src/foundation/sheet_position.dart | 82 +++++++++++++--------- lib/src/scrollable/scrollable_sheet.dart | 2 +- 3 files changed, 49 insertions(+), 37 deletions(-) diff --git a/lib/src/foundation/sheet_extent_scope.dart b/lib/src/foundation/sheet_extent_scope.dart index 334d492..362b29b 100644 --- a/lib/src/foundation/sheet_extent_scope.dart +++ b/lib/src/foundation/sheet_extent_scope.dart @@ -76,7 +76,7 @@ abstract class SheetExtentScope extends StatefulWidget { /// {@macro SheetExtent.maxExtent} final SheetAnchor maxExtent; - /// {@macro SheetExtent.physics} + /// {@macro SheetPosition.physics} final SheetPhysics physics; /// {@macro SheetExtent.gestureTamperer} diff --git a/lib/src/foundation/sheet_position.dart b/lib/src/foundation/sheet_position.dart index 9696c61..7daca69 100644 --- a/lib/src/foundation/sheet_position.dart +++ b/lib/src/foundation/sheet_position.dart @@ -16,40 +16,48 @@ import 'sheet_notification.dart'; import 'sheet_physics.dart'; import 'sheet_status.dart'; -/// Abstracted representation of a sheet position. +/// An abstract representation of a sheet's position. /// -/// It is used in a variety of situations by sheets, for example, -/// to specify how much area of a sheet is initially visible at first build, -/// or to limit the range of sheet dragging. +/// It is used in various contexts by sheets, for example, +/// to define how much of the sheet is initially visible at the first build +/// or to limit the range within which the sheet can be dragged. /// /// See also: -/// - [ProportionalSheetAnchor], which is proportional to the content height. -/// - [FixedSheetAnchor], which is defined by a concrete value in pixels. +/// - [ProportionalSheetAnchor], which defines the position +/// proportionally to the sheet's content height. +/// - [FixedSheetAnchor], which defines the position +/// using a fixed value in pixels. abstract interface class SheetAnchor { /// {@macro FixedSheetAnchor} const factory SheetAnchor.pixels(double pixels) = FixedSheetAnchor; - /// {@macro proportional_extent} + /// {@macro ProportionalSheetAnchor} const factory SheetAnchor.proportional(double size) = ProportionalSheetAnchor; - /// Resolves the extent to a concrete value in pixels. + /// Resolves the position to an actual value in pixels. /// - /// Do not cache the value of [contentSize] because - /// it may change over time. + /// The [contentSize] parameter should not be cached + /// as it may change over time. double resolve(Size contentSize); } -/// An [SheetAnchor] that is proportional to the content height. +/// A [SheetAnchor] that represents a position proportional +/// to the content height of the sheet. class ProportionalSheetAnchor implements SheetAnchor { - /// {@template proportional_extent} - /// Creates an extent that is proportional to the content height. + /// {@template ProportionalSheetAnchor} + /// Creates an anchor that positions the sheet + /// proportionally to its content height. /// /// The [factor] must be greater than or equal to 0. - /// This extent will resolve to `contentSize.height * factor`. + /// This anchor resolves to `contentSize.height * factor`. + /// For example, `ProportionalSheetAnchor(0.6)` represents a position + /// where 60% of the sheet content is visible. /// {@endtemplate} const ProportionalSheetAnchor(this.factor) : assert(factor >= 0); - /// The fraction of the content height. + /// The proportion of the sheet's content height. + /// + /// This value is a fraction (e.g., 0.6 for 60% visibility). final double factor; @override @@ -69,14 +77,17 @@ class ProportionalSheetAnchor implements SheetAnchor { String toString() => '$ProportionalSheetAnchor(factor: $factor)'; } -/// A [SheetAnchor] that has a concrete value in pixels. +/// A [SheetAnchor] that represents a position with a fixed value in pixels. class FixedSheetAnchor implements SheetAnchor { /// {@template FixedSheetAnchor} - /// Creates an anchor from a concrete value in pixels. + /// Creates an anchor that represents a fixed position in pixels. + /// + /// For example, `FixedSheetAnchor(200)` represents a position + /// where 200 pixels from the top of the sheet content are visible. /// {@endtemplate} const FixedSheetAnchor(this.pixels) : assert(pixels >= 0); - /// The value in pixels. + /// The position in pixels. final double pixels; @override @@ -96,13 +107,13 @@ class FixedSheetAnchor implements SheetAnchor { String toString() => '$FixedSheetAnchor(pixels: $pixels)'; } -/// Manages the extent of a sheet. +/// Manages the position of a sheet. /// /// This object is much like [ScrollPosition] for scrollable widgets. -/// The [SheetMetrics.pixels] value determines the visible height of a sheet. +/// The [SheetPosition.pixels] value determines the visible height of a sheet. /// As this value changes, the sheet translates its position, which changes the -/// visible area of the content. The [SheetMetrics.minPixels] and -/// [SheetMetrics.maxPixels] values limit the range of the *pixels*, but it can +/// visible area of the content. The [SheetPosition.minPixels] and +/// [SheetPosition.maxPixels] values limit the range of the *pixels*, but it can /// be outside of the range if the [SheetPosition.physics] allows it. /// /// The current [activity] is responsible for how the *pixels* changes @@ -111,13 +122,14 @@ class FixedSheetAnchor implements SheetAnchor { /// [SheetPosition] starts with [IdleSheetActivity] as the initial activity, /// and it can be changed by calling [beginActivity]. /// -/// This object is [Listenable] that notifies its listeners when *pixels* +/// This object is a [Listenable] that notifies its listeners when the *pixels* /// changes, even during build or layout phase. For listeners that can cause /// any widget to rebuild, consider using [SheetController], which is also -/// [Listenable] of the extent, but only notifies its listeners between frames. +/// [Listenable] of the *pixels*, but avoids notifying listeners during a build. /// /// See also: -/// - [SheetController], which can be attached to a sheet to control its extent. +/// - [SheetController], which can be attached to a sheet to observe and control +/// its position. /// - [SheetExtentScope], which creates a [SheetPosition], manages its lifecycle /// and exposes it to the descendant widgets. @internal @@ -125,7 +137,7 @@ class FixedSheetAnchor implements SheetAnchor { abstract class SheetPosition extends ChangeNotifier with SheetMetrics implements ValueListenable { - /// Creates an object that manages the extent of a sheet. + /// Creates an object that manages the position of a sheet. SheetPosition({ required this.context, required SheetAnchor minExtent, @@ -171,8 +183,8 @@ abstract class SheetPosition extends ChangeNotifier /// A handle to the owner of this object. final SheetContext context; - /// {@template SheetExtent.physics} - /// How the sheet extent should respond to user input. + /// {@template SheetPosition.physics} + /// How the sheet position should respond to user input. /// /// This determines how the sheet will behave when over-dragged or /// under-dragged, or when the user stops dragging. @@ -235,7 +247,7 @@ abstract class SheetPosition extends ChangeNotifier activity.dispose(); _activity = other.activity; // This is necessary to prevent the activity from being disposed of - // when `other` extent is disposed of. + // when `other` is disposed of. other._activity = null; activity.updateOwner(this); @@ -480,7 +492,7 @@ abstract class SheetPosition extends ChangeNotifier } } - /// Animates the extent to the given value. + /// Animates the sheet position to the given value. /// /// The returned future completes when the animation ends, /// whether it completed successfully or whether it was @@ -630,31 +642,31 @@ mixin SheetMetrics { _ => null, }; - /// The current extent of the sheet in pixels. + /// The current position of the sheet in pixels. double get pixels { assert(_debugAssertHasProperty('pixels', maybePixels)); return maybePixels!; } - /// The minimum extent of the sheet in pixels. + /// The minimum position of the sheet in pixels. double get minPixels { assert(_debugAssertHasProperty('minPixels', maybeMinPixels)); return maybeMinPixels!; } - /// The maximum extent of the sheet in pixels. + /// The maximum position of the sheet in pixels. double get maxPixels { assert(_debugAssertHasProperty('maxPixels', maybeMaxPixels)); return maybeMaxPixels!; } - /// The minimum extent of the sheet. + /// The minimum position of the sheet. SheetAnchor get minExtent { assert(_debugAssertHasProperty('minExtent', maybeMinExtent)); return maybeMinExtent!; } - /// The maximum extent of the sheet. + /// The maximum position of the sheet. SheetAnchor get maxExtent { assert(_debugAssertHasProperty('maxExtent', maybeMaxExtent)); return maybeMaxExtent!; diff --git a/lib/src/scrollable/scrollable_sheet.dart b/lib/src/scrollable/scrollable_sheet.dart index c3c9617..37ccd57 100644 --- a/lib/src/scrollable/scrollable_sheet.dart +++ b/lib/src/scrollable/scrollable_sheet.dart @@ -33,7 +33,7 @@ class ScrollableSheet extends StatefulWidget { /// {@macro SheetExtent.maxExtent} final SheetAnchor maxExtent; - /// {@macro SheetExtent.physics} + /// {@macro SheetPosition.physics} final SheetPhysics? physics; /// An object that can be used to control and observe the sheet height. From 06b3b12bb17e2ca3d553b5188870b5ad35f272d0 Mon Sep 17 00:00:00 2001 From: fujidaiti Date: Fri, 27 Sep 2024 00:12:47 +0900 Subject: [PATCH 11/22] Rename "minExtent"s to "maxExtent"s --- .../lib/showcase/ai_playlist_generator.dart | 2 +- example/lib/showcase/airbnb_mobile_app.dart | 2 +- example/lib/showcase/safari/menu.dart | 2 +- .../lib/tutorial/bottom_bar_visibility.dart | 2 +- .../lib/tutorial/cupertino_modal_sheet.dart | 2 +- .../lib/tutorial/extent_driven_animation.dart | 6 +- .../lib/tutorial/imperative_modal_sheet.dart | 2 +- example/lib/tutorial/scrollable_sheet.dart | 2 +- .../lib/tutorial/sheet_content_scaffold.dart | 2 +- example/lib/tutorial/sheet_controller.dart | 2 +- example/lib/tutorial/sheet_draggable.dart | 6 +- example/lib/tutorial/sheet_physics.dart | 6 +- .../textfield_with_multiple_stops.dart | 2 +- lib/src/draggable/draggable_sheet.dart | 8 +-- lib/src/draggable/draggable_sheet_extent.dart | 2 +- .../draggable_sheet_extent_scope.dart | 4 +- lib/src/foundation/sheet_activity.dart | 2 +- lib/src/foundation/sheet_extent_scope.dart | 10 +-- lib/src/foundation/sheet_notification.dart | 2 +- lib/src/foundation/sheet_physics.dart | 15 ++--- lib/src/foundation/sheet_position.dart | 62 +++++++++---------- lib/src/navigation/navigation_routes.dart | 36 +++++------ .../navigation/navigation_sheet_activity.dart | 2 +- .../navigation/navigation_sheet_extent.dart | 2 +- .../navigation_sheet_extent_scope.dart | 4 +- lib/src/scrollable/scrollable_sheet.dart | 8 +-- .../scrollable/scrollable_sheet_extent.dart | 2 +- .../scrollable_sheet_extent_scope.dart | 4 +- test/draggable/draggable_sheet_test.dart | 2 +- test/foundation/physics_test.dart | 14 ++--- test/foundation/sheet_activity_test.dart | 14 ++--- test/foundation/sheet_notification_test.dart | 8 +-- test/foundation/sheet_viewport_test.dart | 2 +- test/navigation/navigation_sheet_test.dart | 18 +++--- test/scrollable/scrollable_sheet_test.dart | 2 +- test/src/stubbing.dart | 27 ++++---- test/src/stubbing.mocks.dart | 36 +++++------ 37 files changed, 163 insertions(+), 161 deletions(-) diff --git a/example/lib/showcase/ai_playlist_generator.dart b/example/lib/showcase/ai_playlist_generator.dart index 83ae83f..8f2cb14 100644 --- a/example/lib/showcase/ai_playlist_generator.dart +++ b/example/lib/showcase/ai_playlist_generator.dart @@ -105,7 +105,7 @@ final _confirmRoute = GoRoute( pageBuilder: (context, state) { return const ScrollableNavigationSheetPage( initialExtent: SheetAnchor.proportional(0.7), - minExtent: SheetAnchor.proportional(0.7), + minPosition: SheetAnchor.proportional(0.7), physics: BouncingSheetPhysics( parent: SnappingSheetPhysics(), ), diff --git a/example/lib/showcase/airbnb_mobile_app.dart b/example/lib/showcase/airbnb_mobile_app.dart index 863cd73..73a3bcc 100644 --- a/example/lib/showcase/airbnb_mobile_app.dart +++ b/example/lib/showcase/airbnb_mobile_app.dart @@ -177,7 +177,7 @@ class _ContentSheet extends StatelessWidget { return ScrollableSheet( physics: sheetPhysics, - minExtent: minSheetExtent, + minPosition: minSheetExtent, child: SizedBox( height: sheetHeight, child: const Card( diff --git a/example/lib/showcase/safari/menu.dart b/example/lib/showcase/safari/menu.dart index ba0452e..1a81d31 100644 --- a/example/lib/showcase/safari/menu.dart +++ b/example/lib/showcase/safari/menu.dart @@ -25,7 +25,7 @@ class MenuSheet extends StatelessWidget { const halfWayExtent = SheetAnchor.proportional(0.5); return ScrollableSheet( initialExtent: halfWayExtent, - minExtent: halfWayExtent, + minPosition: halfWayExtent, physics: const BouncingSheetPhysics( parent: SnappingSheetPhysics(), ), diff --git a/example/lib/tutorial/bottom_bar_visibility.dart b/example/lib/tutorial/bottom_bar_visibility.dart index 857dfa3..3b978fa 100644 --- a/example/lib/tutorial/bottom_bar_visibility.dart +++ b/example/lib/tutorial/bottom_bar_visibility.dart @@ -148,7 +148,7 @@ class _ExampleSheet extends StatelessWidget { return SafeArea( bottom: false, child: DraggableSheet( - minExtent: minSize, + minPosition: minSize, initialExtent: halfSize, physics: multiStopPhysics, child: SheetContentScaffold( diff --git a/example/lib/tutorial/cupertino_modal_sheet.dart b/example/lib/tutorial/cupertino_modal_sheet.dart index 7a3e6f5..97e6b79 100644 --- a/example/lib/tutorial/cupertino_modal_sheet.dart +++ b/example/lib/tutorial/cupertino_modal_sheet.dart @@ -73,7 +73,7 @@ class _HalfScreenSheet extends StatelessWidget { // the visible height of a modal sheet (the extent) exceeds 50% of the screen height. return const DraggableSheet( initialExtent: SheetAnchor.proportional(0.5), - minExtent: SheetAnchor.proportional(0.5), + minPosition: SheetAnchor.proportional(0.5), physics: BouncingSheetPhysics( parent: SnappingSheetPhysics(), ), diff --git a/example/lib/tutorial/extent_driven_animation.dart b/example/lib/tutorial/extent_driven_animation.dart index 7dd33ff..79e3ae0 100644 --- a/example/lib/tutorial/extent_driven_animation.dart +++ b/example/lib/tutorial/extent_driven_animation.dart @@ -48,18 +48,18 @@ class _ExampleSheet extends StatelessWidget { @override Widget build(BuildContext context) { final bottomPadding = MediaQuery.of(context).padding.bottom; - final minExtent = SheetAnchor.pixels(56 + bottomPadding); + final minPosition = SheetAnchor.pixels(56 + bottomPadding); final physics = BouncingSheetPhysics( parent: SnappingSheetPhysics( snappingBehavior: SnapToNearest( - snapTo: [minExtent, const SheetAnchor.proportional(1)], + snapTo: [minPosition, const SheetAnchor.proportional(1)], ), ), ); return DraggableSheet( - minExtent: minExtent, + minPosition: minPosition, physics: physics, child: Card( margin: EdgeInsets.zero, diff --git a/example/lib/tutorial/imperative_modal_sheet.dart b/example/lib/tutorial/imperative_modal_sheet.dart index fcd899f..13aea69 100644 --- a/example/lib/tutorial/imperative_modal_sheet.dart +++ b/example/lib/tutorial/imperative_modal_sheet.dart @@ -67,7 +67,7 @@ class _ExampleSheet extends StatelessWidget { } }, child: DraggableSheet( - minExtent: const SheetAnchor.proportional(0.5), + minPosition: const SheetAnchor.proportional(0.5), child: Card( color: Theme.of(context).colorScheme.secondaryContainer, margin: EdgeInsets.zero, diff --git a/example/lib/tutorial/scrollable_sheet.dart b/example/lib/tutorial/scrollable_sheet.dart index 6ed0d3c..503f4e1 100644 --- a/example/lib/tutorial/scrollable_sheet.dart +++ b/example/lib/tutorial/scrollable_sheet.dart @@ -45,7 +45,7 @@ class _MySheet extends StatelessWidget { child: buildSheetBackground(context, content), // Optional: Comment out the following lines to add multiple stop positions. // - // minExtent: const SheetAnchor.proportional(0.2), + // minPosition: const SheetAnchor.proportional(0.2), // physics: BouncingSheetPhysics( // parent: SnappingSheetPhysics( // snappingBehavior: SnapToNearest( diff --git a/example/lib/tutorial/sheet_content_scaffold.dart b/example/lib/tutorial/sheet_content_scaffold.dart index ff6ca82..e082175 100644 --- a/example/lib/tutorial/sheet_content_scaffold.dart +++ b/example/lib/tutorial/sheet_content_scaffold.dart @@ -65,7 +65,7 @@ class _ExampleSheet extends StatelessWidget { return DraggableSheet( physics: physics, - minExtent: const SheetAnchor.pixels(0), + minPosition: const SheetAnchor.pixels(0), child: Card( clipBehavior: Clip.antiAlias, margin: EdgeInsets.zero, diff --git a/example/lib/tutorial/sheet_controller.dart b/example/lib/tutorial/sheet_controller.dart index 2e13cef..0a7d562 100644 --- a/example/lib/tutorial/sheet_controller.dart +++ b/example/lib/tutorial/sheet_controller.dart @@ -88,7 +88,7 @@ class _ExampleSheet extends StatelessWidget { Widget build(BuildContext context) { return DraggableSheet( controller: controller, - minExtent: const SheetAnchor.proportional(0.5), + minPosition: const SheetAnchor.proportional(0.5), physics: const BouncingSheetPhysics( parent: SnappingSheetPhysics(), ), diff --git a/example/lib/tutorial/sheet_draggable.dart b/example/lib/tutorial/sheet_draggable.dart index 3a718be..ab29a4c 100644 --- a/example/lib/tutorial/sheet_draggable.dart +++ b/example/lib/tutorial/sheet_draggable.dart @@ -65,7 +65,7 @@ class _ExampleSheet extends StatelessWidget { ], ); - const minExtent = SheetAnchor.proportional(0.5); + const minPosition = SheetAnchor.proportional(0.5); const physics = BouncingSheetPhysics( parent: SnappingSheetPhysics(), ); @@ -74,8 +74,8 @@ class _ExampleSheet extends StatelessWidget { bottom: false, child: ScrollableSheet( physics: physics, - minExtent: minExtent, - initialExtent: minExtent, + minPosition: minPosition, + initialExtent: minPosition, child: Card( margin: EdgeInsets.zero, color: Theme.of(context).colorScheme.secondaryContainer, diff --git a/example/lib/tutorial/sheet_physics.dart b/example/lib/tutorial/sheet_physics.dart index 5f914f9..70abe94 100644 --- a/example/lib/tutorial/sheet_physics.dart +++ b/example/lib/tutorial/sheet_physics.dart @@ -95,7 +95,7 @@ class _MySheet extends StatelessWidget { ], ), // Tips: The above configuration can be replaced with a 'SnapToNearestEdge', - // which will snap to either the 'minExtent' or 'maxExtent' of the sheet: + // which will snap to either the 'minPosition' or 'maxExtent' of the sheet: // snappingBehavior: const SnapToNearestEdge(), ); @@ -113,13 +113,13 @@ class _MySheet extends StatelessWidget { @override Widget build(BuildContext context) { return DraggableSheet( - // The 'minExtent' and 'maxExtent' properties determine + // The 'minPosition' and 'maxExtent' properties determine // how far the sheet can be dragged. Note that "extent" // refers to the visible height of the sheet. For example, // the configuration below ensures that the sheet is fully visible // at first and can then be dragged down to (_halfwayFraction * 100)% // of the sheet height at minimum. - minExtent: const SheetAnchor.proportional(_halfwayFraction), + minPosition: const SheetAnchor.proportional(_halfwayFraction), maxExtent: const SheetAnchor.proportional(1), // Default initialExtent: const SheetAnchor.proportional(1), // Default // 'physics' determines how the sheet will behave when the user reaches diff --git a/example/lib/tutorial/textfield_with_multiple_stops.dart b/example/lib/tutorial/textfield_with_multiple_stops.dart index 248c6fe..243c902 100644 --- a/example/lib/tutorial/textfield_with_multiple_stops.dart +++ b/example/lib/tutorial/textfield_with_multiple_stops.dart @@ -16,7 +16,7 @@ class TextFieldWithMultipleStops extends StatelessWidget { const Scaffold(), ScrollableSheet( initialExtent: const SheetAnchor.proportional(0.7), - minExtent: const SheetAnchor.proportional(0.4), + minPosition: const SheetAnchor.proportional(0.4), physics: const BouncingSheetPhysics( parent: SnappingSheetPhysics( snappingBehavior: SnapToNearest( diff --git a/lib/src/draggable/draggable_sheet.dart b/lib/src/draggable/draggable_sheet.dart index 20071f7..52b687d 100644 --- a/lib/src/draggable/draggable_sheet.dart +++ b/lib/src/draggable/draggable_sheet.dart @@ -33,7 +33,7 @@ class DraggableSheet extends StatefulWidget { super.key, this.hitTestBehavior = HitTestBehavior.translucent, this.initialExtent = const SheetAnchor.proportional(1), - this.minExtent = const SheetAnchor.proportional(1), + this.minPosition = const SheetAnchor.proportional(1), this.maxExtent = const SheetAnchor.proportional(1), this.physics, required this.child, @@ -42,8 +42,8 @@ class DraggableSheet extends StatefulWidget { final SheetAnchor initialExtent; - /// {@macro SheetExtentConfig.minExtent} - final SheetAnchor minExtent; + /// {@macro SheetExtentConfig.minPosition} + final SheetAnchor minPosition; /// {@macro SheetExtentConfig.maxExtent} final SheetAnchor maxExtent; @@ -80,7 +80,7 @@ class _DraggableSheetState extends State context: this, controller: controller, initialExtent: widget.initialExtent, - minExtent: widget.minExtent, + minPosition: widget.minPosition, maxExtent: widget.maxExtent, physics: physics, gestureTamperer: gestureTamper, diff --git a/lib/src/draggable/draggable_sheet_extent.dart b/lib/src/draggable/draggable_sheet_extent.dart index 622bf09..cb24742 100644 --- a/lib/src/draggable/draggable_sheet_extent.dart +++ b/lib/src/draggable/draggable_sheet_extent.dart @@ -8,7 +8,7 @@ import '../foundation/sheet_position.dart'; class DraggableSheetExtent extends SheetPosition { DraggableSheetExtent({ required super.context, - required super.minExtent, + required super.minPosition, required super.maxExtent, required this.initialExtent, required super.physics, diff --git a/lib/src/draggable/draggable_sheet_extent_scope.dart b/lib/src/draggable/draggable_sheet_extent_scope.dart index 898e5b9..a8b92df 100644 --- a/lib/src/draggable/draggable_sheet_extent_scope.dart +++ b/lib/src/draggable/draggable_sheet_extent_scope.dart @@ -13,7 +13,7 @@ class DraggableSheetExtentScope extends SheetExtentScope { super.isPrimary, required super.context, required this.initialExtent, - required super.minExtent, + required super.minPosition, required super.maxExtent, required super.physics, super.gestureTamperer, @@ -47,7 +47,7 @@ class _DraggableSheetExtentScopeState extends SheetExtentScopeState< return DraggableSheetExtent( context: context, initialExtent: widget.initialExtent, - minExtent: widget.minExtent, + minPosition: widget.minPosition, maxExtent: widget.maxExtent, physics: widget.physics, gestureTamperer: widget.gestureTamperer, diff --git a/lib/src/foundation/sheet_activity.dart b/lib/src/foundation/sheet_activity.dart index 6c48871..7374cc9 100644 --- a/lib/src/foundation/sheet_activity.dart +++ b/lib/src/foundation/sheet_activity.dart @@ -67,7 +67,7 @@ abstract class SheetActivity { void didChangeViewportDimensions(Size? oldSize, EdgeInsets? oldInsets) {} void didChangeBoundaryConstraints( - SheetAnchor? oldMinExtent, + SheetAnchor? oldMinPosition, SheetAnchor? oldMaxExtent, ) {} diff --git a/lib/src/foundation/sheet_extent_scope.dart b/lib/src/foundation/sheet_extent_scope.dart index 362b29b..c65f5d0 100644 --- a/lib/src/foundation/sheet_extent_scope.dart +++ b/lib/src/foundation/sheet_extent_scope.dart @@ -57,7 +57,7 @@ abstract class SheetExtentScope extends StatefulWidget { required this.context, this.controller, this.isPrimary = true, - required this.minExtent, + required this.minPosition, required this.maxExtent, required this.physics, this.gestureTamperer, @@ -70,8 +70,8 @@ abstract class SheetExtentScope extends StatefulWidget { /// The [SheetController] attached to the [SheetPosition]. final SheetController? controller; - /// {@macro SheetExtent.minExtent} - final SheetAnchor minExtent; + /// {@macro SheetExtent.minPosition} + final SheetAnchor minPosition; /// {@macro SheetExtent.maxExtent} final SheetAnchor maxExtent; @@ -178,9 +178,9 @@ abstract class SheetExtentScopeState snapshot.maybePixels; @override - SheetAnchor? get maybeMinExtent => snapshot.maybeMinExtent; + SheetAnchor? get maybeMinPosition => snapshot.maybeMinPosition; @override SheetAnchor? get maybeMaxExtent => snapshot.maybeMaxExtent; @@ -222,7 +222,7 @@ abstract class SheetPosition extends ChangeNotifier /// to ensure that the [SheetMetrics.devicePixelRatio] is always up-to-date. void _updateMetrics({ double? pixels, - SheetAnchor? minExtent, + SheetAnchor? minPosition, SheetAnchor? maxExtent, Size? contentSize, Size? viewportSize, @@ -230,7 +230,7 @@ abstract class SheetPosition extends ChangeNotifier }) { _snapshot = SheetMetricsSnapshot( pixels: pixels ?? maybePixels, - minExtent: minExtent ?? maybeMinExtent, + minPosition: minPosition ?? maybeMinPosition, maxExtent: maxExtent ?? maybeMaxExtent, contentSize: contentSize ?? maybeContentSize, viewportSize: viewportSize ?? maybeViewportSize, @@ -262,7 +262,7 @@ abstract class SheetPosition extends ChangeNotifier if (other.maybePixels case final pixels?) { correctPixels(pixels); } - applyNewBoundaryConstraints(other.minExtent, other.maxExtent); + applyNewBoundaryConstraints(other.minPosition, other.maxExtent); applyNewViewportDimensions( other.viewportSize, other.viewportInsets, @@ -308,12 +308,12 @@ abstract class SheetPosition extends ChangeNotifier @mustCallSuper void applyNewBoundaryConstraints( - SheetAnchor minExtent, SheetAnchor maxExtent) { - if (minExtent != this.minExtent || maxExtent != this.maxExtent) { - final oldMinExtent = maybeMinExtent; + SheetAnchor minPosition, SheetAnchor maxExtent) { + if (minPosition != this.minPosition || maxExtent != this.maxExtent) { + final oldMinPosition = maybeMinPosition; final oldMaxExtent = maybeMaxExtent; - _updateMetrics(minExtent: minExtent, maxExtent: maxExtent); - activity.didChangeBoundaryConstraints(oldMinExtent, oldMaxExtent); + _updateMetrics(minPosition: minPosition, maxExtent: maxExtent); + activity.didChangeBoundaryConstraints(oldMinPosition, oldMaxExtent); } } @@ -520,7 +520,7 @@ abstract class SheetPosition extends ChangeNotifier @override SheetMetrics copyWith({ double? pixels, - SheetAnchor? minExtent, + SheetAnchor? minPosition, SheetAnchor? maxExtent, Size? contentSize, Size? viewportSize, @@ -529,7 +529,7 @@ abstract class SheetPosition extends ChangeNotifier }) { return snapshot.copyWith( pixels: pixels, - minExtent: minExtent, + minPosition: minPosition, maxExtent: maxExtent, contentSize: contentSize, viewportSize: viewportSize, @@ -600,7 +600,7 @@ mixin SheetMetrics { /// An empty metrics object with all values set to null. static const SheetMetrics empty = SheetMetricsSnapshot( pixels: null, - minExtent: null, + minPosition: null, maxExtent: null, contentSize: null, viewportSize: null, @@ -608,7 +608,7 @@ mixin SheetMetrics { ); double? get maybePixels; - SheetAnchor? get maybeMinExtent; + SheetAnchor? get maybeMinPosition; SheetAnchor? get maybeMaxExtent; Size? get maybeContentSize; Size? get maybeViewportSize; @@ -622,7 +622,7 @@ mixin SheetMetrics { /// Creates a copy of the metrics with the given fields replaced. SheetMetrics copyWith({ double? pixels, - SheetAnchor? minExtent, + SheetAnchor? minPosition, SheetAnchor? maxExtent, Size? contentSize, Size? viewportSize, @@ -630,9 +630,9 @@ mixin SheetMetrics { double? devicePixelRatio, }); - double? get maybeMinPixels => switch ((maybeMinExtent, maybeContentSize)) { - (final minExtent?, final contentSize?) => - minExtent.resolve(contentSize), + double? get maybeMinPixels => switch ((maybeMinPosition, maybeContentSize)) { + (final minPosition?, final contentSize?) => + minPosition.resolve(contentSize), _ => null, }; @@ -661,9 +661,9 @@ mixin SheetMetrics { } /// The minimum position of the sheet. - SheetAnchor get minExtent { - assert(_debugAssertHasProperty('minExtent', maybeMinExtent)); - return maybeMinExtent!; + SheetAnchor get minPosition { + assert(_debugAssertHasProperty('minPosition', maybeMinPosition)); + return maybeMinPosition!; } /// The maximum position of the sheet. @@ -713,7 +713,7 @@ mixin SheetMetrics { /// null. bool get hasDimensions => maybePixels != null && - maybeMinExtent != null && + maybeMinPosition != null && maybeMaxExtent != null && maybeContentSize != null && maybeViewportSize != null && @@ -751,14 +751,14 @@ class SheetMetricsSnapshot with SheetMetrics { /// Creates an immutable snapshot of the state of a sheet. const SheetMetricsSnapshot({ required double? pixels, - required SheetAnchor? minExtent, + required SheetAnchor? minPosition, required SheetAnchor? maxExtent, required Size? contentSize, required Size? viewportSize, required EdgeInsets? viewportInsets, this.devicePixelRatio = 1.0, }) : maybePixels = pixels, - maybeMinExtent = minExtent, + maybeMinPosition = minPosition, maybeMaxExtent = maxExtent, maybeContentSize = contentSize, maybeViewportSize = viewportSize, @@ -768,7 +768,7 @@ class SheetMetricsSnapshot with SheetMetrics { final double? maybePixels; @override - final SheetAnchor? maybeMinExtent; + final SheetAnchor? maybeMinPosition; @override final SheetAnchor? maybeMaxExtent; @@ -788,7 +788,7 @@ class SheetMetricsSnapshot with SheetMetrics { @override SheetMetricsSnapshot copyWith({ double? pixels, - SheetAnchor? minExtent, + SheetAnchor? minPosition, SheetAnchor? maxExtent, Size? contentSize, Size? viewportSize, @@ -797,7 +797,7 @@ class SheetMetricsSnapshot with SheetMetrics { }) { return SheetMetricsSnapshot( pixels: pixels ?? maybePixels, - minExtent: minExtent ?? maybeMinExtent, + minPosition: minPosition ?? maybeMinPosition, maxExtent: maxExtent ?? maybeMaxExtent, contentSize: contentSize ?? maybeContentSize, viewportSize: viewportSize ?? maybeViewportSize, @@ -812,7 +812,7 @@ class SheetMetricsSnapshot with SheetMetrics { (other is SheetMetrics && runtimeType == other.runtimeType && maybePixels == other.maybePixels && - maybeMinExtent == other.maybeMinExtent && + maybeMinPosition == other.maybeMinPosition && maybeMaxExtent == other.maybeMaxExtent && maybeContentSize == other.maybeContentSize && maybeViewportSize == other.maybeViewportSize && @@ -823,7 +823,7 @@ class SheetMetricsSnapshot with SheetMetrics { int get hashCode => Object.hash( runtimeType, maybePixels, - maybeMinExtent, + maybeMinPosition, maybeMaxExtent, maybeContentSize, maybeViewportSize, @@ -840,7 +840,7 @@ class SheetMetricsSnapshot with SheetMetrics { viewPixels: maybeViewPixels, minViewPixels: maybeMinViewPixels, maxViewPixels: maybeMaxViewPixels, - minExtent: maybeMinExtent, + minPosition: maybeMinPosition, maxExtent: maybeMaxExtent, contentSize: maybeContentSize, viewportSize: maybeViewportSize, diff --git a/lib/src/navigation/navigation_routes.dart b/lib/src/navigation/navigation_routes.dart index 352613d..47c27bb 100644 --- a/lib/src/navigation/navigation_routes.dart +++ b/lib/src/navigation/navigation_routes.dart @@ -18,7 +18,7 @@ class _ScrollableNavigationSheetRouteContent extends StatelessWidget { const _ScrollableNavigationSheetRouteContent({ this.debugLabel, required this.initialExtent, - required this.minExtent, + required this.minPosition, required this.maxExtent, required this.physics, required this.child, @@ -26,7 +26,7 @@ class _ScrollableNavigationSheetRouteContent extends StatelessWidget { final String? debugLabel; final SheetAnchor initialExtent; - final SheetAnchor minExtent; + final SheetAnchor minPosition; final SheetAnchor maxExtent; final SheetPhysics? physics; final Widget child; @@ -43,7 +43,7 @@ class _ScrollableNavigationSheetRouteContent extends StatelessWidget { context: context, isPrimary: false, initialExtent: initialExtent, - minExtent: minExtent, + minPosition: minPosition, maxExtent: maxExtent, physics: physics ?? theme?.physics ?? kDefaultSheetPhysics, gestureTamperer: gestureTamper, @@ -59,7 +59,7 @@ class _DraggableNavigationSheetRouteContent extends StatelessWidget { const _DraggableNavigationSheetRouteContent({ this.debugLabel, required this.initialExtent, - required this.minExtent, + required this.minPosition, required this.maxExtent, required this.physics, required this.child, @@ -67,7 +67,7 @@ class _DraggableNavigationSheetRouteContent extends StatelessWidget { final String? debugLabel; final SheetAnchor initialExtent; - final SheetAnchor minExtent; + final SheetAnchor minPosition; final SheetAnchor maxExtent; final SheetPhysics? physics; final Widget child; @@ -85,7 +85,7 @@ class _DraggableNavigationSheetRouteContent extends StatelessWidget { context: context, isPrimary: false, initialExtent: initialExtent, - minExtent: minExtent, + minPosition: minPosition, maxExtent: maxExtent, physics: physics, gestureTamperer: gestureTamper, @@ -105,7 +105,7 @@ class ScrollableNavigationSheetRoute this.maintainState = true, this.transitionDuration = const Duration(milliseconds: 300), this.initialExtent = const SheetAnchor.proportional(1), - this.minExtent = const SheetAnchor.proportional(1), + this.minPosition = const SheetAnchor.proportional(1), this.maxExtent = const SheetAnchor.proportional(1), this.physics, this.transitionsBuilder, @@ -113,7 +113,7 @@ class ScrollableNavigationSheetRoute }); final SheetAnchor initialExtent; - final SheetAnchor minExtent; + final SheetAnchor minPosition; final SheetAnchor maxExtent; final SheetPhysics? physics; @@ -144,7 +144,7 @@ class ScrollableNavigationSheetRoute return _ScrollableNavigationSheetRouteContent( debugLabel: '$ScrollableNavigationSheetRoute(${settings.name})', initialExtent: initialExtent, - minExtent: minExtent, + minPosition: minPosition, maxExtent: maxExtent, physics: physics, child: builder(context), @@ -159,7 +159,7 @@ class DraggableNavigationSheetRoute this.maintainState = true, this.transitionDuration = const Duration(milliseconds: 300), this.initialExtent = const SheetAnchor.proportional(1), - this.minExtent = const SheetAnchor.proportional(1), + this.minPosition = const SheetAnchor.proportional(1), this.maxExtent = const SheetAnchor.proportional(1), this.physics, this.transitionsBuilder, @@ -167,7 +167,7 @@ class DraggableNavigationSheetRoute }); final SheetAnchor initialExtent; - final SheetAnchor minExtent; + final SheetAnchor minPosition; final SheetAnchor maxExtent; final SheetPhysics? physics; @@ -198,7 +198,7 @@ class DraggableNavigationSheetRoute return _DraggableNavigationSheetRouteContent( debugLabel: '$DraggableNavigationSheetRoute(${settings.name})', initialExtent: initialExtent, - minExtent: minExtent, + minPosition: minPosition, maxExtent: maxExtent, physics: physics, child: builder(context), @@ -215,7 +215,7 @@ class ScrollableNavigationSheetPage extends Page { this.maintainState = true, this.transitionDuration = const Duration(milliseconds: 300), this.initialExtent = const SheetAnchor.proportional(1), - this.minExtent = const SheetAnchor.proportional(1), + this.minPosition = const SheetAnchor.proportional(1), this.maxExtent = const SheetAnchor.proportional(1), this.physics, this.transitionsBuilder, @@ -228,7 +228,7 @@ class ScrollableNavigationSheetPage extends Page { final Duration transitionDuration; final SheetAnchor initialExtent; - final SheetAnchor minExtent; + final SheetAnchor minPosition; final SheetAnchor maxExtent; final SheetPhysics? physics; @@ -278,7 +278,7 @@ class _PageBasedScrollableNavigationSheetRoute return _ScrollableNavigationSheetRouteContent( debugLabel: '$ScrollableNavigationSheetPage(${page.name})', initialExtent: page.initialExtent, - minExtent: page.minExtent, + minPosition: page.minPosition, maxExtent: page.maxExtent, physics: page.physics, child: page.child, @@ -295,7 +295,7 @@ class DraggableNavigationSheetPage extends Page { this.maintainState = true, this.transitionDuration = const Duration(milliseconds: 300), this.initialExtent = const SheetAnchor.proportional(1), - this.minExtent = const SheetAnchor.proportional(1), + this.minPosition = const SheetAnchor.proportional(1), this.maxExtent = const SheetAnchor.proportional(1), this.physics, this.transitionsBuilder, @@ -308,7 +308,7 @@ class DraggableNavigationSheetPage extends Page { final Duration transitionDuration; final SheetAnchor initialExtent; - final SheetAnchor minExtent; + final SheetAnchor minPosition; final SheetAnchor maxExtent; final SheetPhysics? physics; @@ -358,7 +358,7 @@ class _PageBasedDraggableNavigationSheetRoute return _DraggableNavigationSheetRouteContent( debugLabel: '$DraggableNavigationSheetPage(${page.name})', initialExtent: page.initialExtent, - minExtent: page.minExtent, + minPosition: page.minPosition, maxExtent: page.maxExtent, physics: page.physics, child: page.child, diff --git a/lib/src/navigation/navigation_sheet_activity.dart b/lib/src/navigation/navigation_sheet_activity.dart index b50f512..2fb8359 100644 --- a/lib/src/navigation/navigation_sheet_activity.dart +++ b/lib/src/navigation/navigation_sheet_activity.dart @@ -105,7 +105,7 @@ class ProxySheetActivity extends NavigationSheetActivity { final localExtent = route.scopeKey.currentExtent; final localMetrics = localExtent.snapshot; owner.applyNewBoundaryConstraints( - localExtent.minExtent, + localExtent.minPosition, localExtent.maxExtent, ); if (localMetrics.maybeContentSize case final contentSize?) { diff --git a/lib/src/navigation/navigation_sheet_extent.dart b/lib/src/navigation/navigation_sheet_extent.dart index 19210e5..3b524fc 100644 --- a/lib/src/navigation/navigation_sheet_extent.dart +++ b/lib/src/navigation/navigation_sheet_extent.dart @@ -12,7 +12,7 @@ import 'navigation_sheet_activity.dart'; class NavigationSheetExtent extends SheetPosition { NavigationSheetExtent({ required super.context, - required super.minExtent, + required super.minPosition, required super.maxExtent, required super.physics, super.gestureTamperer, diff --git a/lib/src/navigation/navigation_sheet_extent_scope.dart b/lib/src/navigation/navigation_sheet_extent_scope.dart index 83b98b6..7388cf2 100644 --- a/lib/src/navigation/navigation_sheet_extent_scope.dart +++ b/lib/src/navigation/navigation_sheet_extent_scope.dart @@ -16,7 +16,7 @@ class NavigationSheetExtentScope extends SheetExtentScope { this.debugLabel, required super.child, }) : super( - minExtent: const SheetAnchor.pixels(0), + minPosition: const SheetAnchor.pixels(0), maxExtent: const SheetAnchor.proportional(1), // TODO: Use more appropriate physics. physics: const ClampingSheetPhysics(), @@ -44,7 +44,7 @@ class _NavigationSheetExtentScopeState extends SheetExtentScopeState< NavigationSheetExtent buildExtent(SheetContext context) { return NavigationSheetExtent( context: context, - minExtent: widget.minExtent, + minPosition: widget.minPosition, maxExtent: widget.maxExtent, physics: widget.physics, gestureTamperer: widget.gestureTamperer, diff --git a/lib/src/scrollable/scrollable_sheet.dart b/lib/src/scrollable/scrollable_sheet.dart index 37ccd57..da3dd3f 100644 --- a/lib/src/scrollable/scrollable_sheet.dart +++ b/lib/src/scrollable/scrollable_sheet.dart @@ -17,7 +17,7 @@ class ScrollableSheet extends StatefulWidget { const ScrollableSheet({ super.key, this.initialExtent = const SheetAnchor.proportional(1), - this.minExtent = const SheetAnchor.proportional(1), + this.minPosition = const SheetAnchor.proportional(1), this.maxExtent = const SheetAnchor.proportional(1), this.physics, this.controller, @@ -27,8 +27,8 @@ class ScrollableSheet extends StatefulWidget { /// {@macro ScrollableSheetExtent.initialExtent} final SheetAnchor initialExtent; - /// {@macro SheetExtent.minExtent} - final SheetAnchor minExtent; + /// {@macro SheetExtent.minPosition} + final SheetAnchor minPosition; /// {@macro SheetExtent.maxExtent} final SheetAnchor maxExtent; @@ -60,7 +60,7 @@ class _ScrollableSheetState extends State context: this, controller: controller, initialExtent: widget.initialExtent, - minExtent: widget.minExtent, + minPosition: widget.minPosition, maxExtent: widget.maxExtent, physics: physics, gestureTamperer: gestureTamper, diff --git a/lib/src/scrollable/scrollable_sheet_extent.dart b/lib/src/scrollable/scrollable_sheet_extent.dart index eeaf112..5fbf3de 100644 --- a/lib/src/scrollable/scrollable_sheet_extent.dart +++ b/lib/src/scrollable/scrollable_sheet_extent.dart @@ -19,7 +19,7 @@ class ScrollableSheetExtent extends SheetPosition ScrollableSheetExtent({ required super.context, required this.initialExtent, - required super.minExtent, + required super.minPosition, required super.maxExtent, required SheetPhysics physics, super.gestureTamperer, diff --git a/lib/src/scrollable/scrollable_sheet_extent_scope.dart b/lib/src/scrollable/scrollable_sheet_extent_scope.dart index d6e8497..0e66c63 100644 --- a/lib/src/scrollable/scrollable_sheet_extent_scope.dart +++ b/lib/src/scrollable/scrollable_sheet_extent_scope.dart @@ -13,7 +13,7 @@ class ScrollableSheetExtentScope extends SheetExtentScope { super.isPrimary, required super.context, required this.initialExtent, - required super.minExtent, + required super.minPosition, required super.maxExtent, required super.physics, super.gestureTamperer, @@ -47,7 +47,7 @@ class _ScrollableSheetExtentScopeState extends SheetExtentScopeState< return ScrollableSheetExtent( context: context, initialExtent: widget.initialExtent, - minExtent: widget.minExtent, + minPosition: widget.minPosition, maxExtent: widget.maxExtent, physics: widget.physics, gestureTamperer: widget.gestureTamperer, diff --git a/test/draggable/draggable_sheet_test.dart b/test/draggable/draggable_sheet_test.dart index fef47eb..65fcda2 100644 --- a/test/draggable/draggable_sheet_test.dart +++ b/test/draggable/draggable_sheet_test.dart @@ -85,7 +85,7 @@ void main() { child: DraggableSheet( key: sheetKey, controller: controller, - minExtent: const SheetAnchor.pixels(200), + minPosition: const SheetAnchor.pixels(200), initialExtent: const SheetAnchor.pixels(200), child: const Material( child: _TestSheetContent( diff --git a/test/foundation/physics_test.dart b/test/foundation/physics_test.dart index 3abae29..1d145a5 100644 --- a/test/foundation/physics_test.dart +++ b/test/foundation/physics_test.dart @@ -15,7 +15,7 @@ class _SheetPhysicsWithDefaultConfiguration extends SheetPhysics } const _referenceSheetMetrics = SheetMetricsSnapshot( - minExtent: SheetAnchor.pixels(0), + minPosition: SheetAnchor.pixels(0), maxExtent: SheetAnchor.proportional(1), pixels: 600, contentSize: Size(360, 600), @@ -193,13 +193,13 @@ void main() { ); expect( physicsUnderTest.findSettledExtent(0, underDraggedPosition), - _referenceSheetMetrics.minExtent, + _referenceSheetMetrics.minPosition, reason: 'Should return the min extent if the position ' 'is out of the lower bound', ); expect( physicsUnderTest.findSettledExtent(1000, underDraggedPosition), - _referenceSheetMetrics.minExtent, + _referenceSheetMetrics.minPosition, reason: 'The velocity should not affect the result', ); @@ -212,7 +212,7 @@ void main() { ); expect( physicsUnderTest.findSettledExtent(1000, _positionAtBottomEdge), - _referenceSheetMetrics.minExtent, + _referenceSheetMetrics.minPosition, reason: 'Should return the min extent if the position is at the lower bound', ); @@ -240,7 +240,7 @@ void main() { ); expect( behaviorUnderTest.findSettledExtent(0, positionAtNearBottomEdge), - _referenceSheetMetrics.minExtent, + _referenceSheetMetrics.minPosition, ); }); @@ -251,7 +251,7 @@ void main() { ); expect( behaviorUnderTest.findSettledExtent(-50, _positionAtTopEdge), - _referenceSheetMetrics.minExtent, + _referenceSheetMetrics.minPosition, ); }); @@ -280,7 +280,7 @@ void main() { isNull); expect( behaviorUnderTest.findSettledExtent(-50, _positionAtTopEdge), - _referenceSheetMetrics.minExtent, + _referenceSheetMetrics.minPosition, ); expect( behaviorUnderTest.findSettledExtent(50, _positionAtBottomEdge), diff --git a/test/foundation/sheet_activity_test.dart b/test/foundation/sheet_activity_test.dart index ef30620..dd0032f 100644 --- a/test/foundation/sheet_activity_test.dart +++ b/test/foundation/sheet_activity_test.dart @@ -43,7 +43,7 @@ void main() { test('should animate to the destination', () { final (ownerMetrics, owner) = createMockSheetExtent( pixels: 300, - minExtent: const SheetAnchor.pixels(300), + minPosition: const SheetAnchor.pixels(300), maxExtent: const SheetAnchor.pixels(700), contentSize: const Size(400, 700), viewportSize: const Size(400, 900), @@ -82,7 +82,7 @@ void main() { test('should absorb viewport changes', () { final (ownerMetrics, owner) = createMockSheetExtent( pixels: 300, - minExtent: const SheetAnchor.pixels(300), + minPosition: const SheetAnchor.pixels(300), maxExtent: const SheetAnchor.proportional(1), contentSize: const Size(400, 900), viewportSize: const Size(400, 900), @@ -134,7 +134,7 @@ void main() { }); group('SettlingSheetActivity', () { - late MockSheetExtent owner; + late MockSheetPosition owner; late MutableSheetMetrics ownerMetrics; late MockTicker internalTicker; late TickerCallback? internalOnTickCallback; @@ -142,7 +142,7 @@ void main() { setUp(() { (ownerMetrics, owner) = createMockSheetExtent( pixels: 300, - minExtent: const SheetAnchor.proportional(0.5), + minPosition: const SheetAnchor.proportional(0.5), maxExtent: const SheetAnchor.proportional(1), contentSize: const Size(400, 600), viewportSize: const Size(400, 900), @@ -274,7 +274,7 @@ void main() { test('should maintain previous extent when keyboard appears', () { final (ownerMetrics, owner) = createMockSheetExtent( pixels: 450, - minExtent: const SheetAnchor.proportional(0.5), + minPosition: const SheetAnchor.proportional(0.5), maxExtent: const SheetAnchor.proportional(1), contentSize: const Size(400, 850), viewportSize: const Size(400, 900), @@ -299,7 +299,7 @@ void main() { () { final (ownerMetrics, owner) = createMockSheetExtent( pixels: 300, - minExtent: const SheetAnchor.proportional(0.5), + minPosition: const SheetAnchor.proportional(0.5), maxExtent: const SheetAnchor.proportional(1), contentSize: const Size(400, 580), viewportSize: const Size(400, 900), @@ -325,7 +325,7 @@ void main() { () { final (ownerMetrics, owner) = createMockSheetExtent( pixels: 300, - minExtent: const SheetAnchor.proportional(0.5), + minPosition: const SheetAnchor.proportional(0.5), maxExtent: const SheetAnchor.proportional(1), contentSize: const Size(400, 500), viewportSize: const Size(400, 900), diff --git a/test/foundation/sheet_notification_test.dart b/test/foundation/sheet_notification_test.dart index d1443dd..61cd417 100644 --- a/test/foundation/sheet_notification_test.dart +++ b/test/foundation/sheet_notification_test.dart @@ -24,7 +24,7 @@ void main() { return false; }, child: DraggableSheet( - minExtent: const SheetAnchor.pixels(0), + minPosition: const SheetAnchor.pixels(0), // Disable the snapping effect physics: const ClampingSheetPhysics(), child: Container( @@ -168,7 +168,7 @@ void main() { }, child: DraggableSheet( controller: controller, - minExtent: const SheetAnchor.pixels(0), + minPosition: const SheetAnchor.pixels(0), // Disable the snapping effect physics: const ClampingSheetPhysics(), child: Container( @@ -244,7 +244,7 @@ void main() { }, child: DraggableSheet( // Make sure the sheet can't be dragged - minExtent: const SheetAnchor.proportional(1), + minPosition: const SheetAnchor.proportional(1), maxExtent: const SheetAnchor.proportional(1), // Disable the snapping effect physics: const ClampingSheetPhysics(), @@ -319,7 +319,7 @@ void main() { return false; }, child: DraggableSheet( - minExtent: const SheetAnchor.pixels(0), + minPosition: const SheetAnchor.pixels(0), // Disable the snapping effect physics: const ClampingSheetPhysics(), child: Container( diff --git a/test/foundation/sheet_viewport_test.dart b/test/foundation/sheet_viewport_test.dart index 4b996da..c7ea9ca 100644 --- a/test/foundation/sheet_viewport_test.dart +++ b/test/foundation/sheet_viewport_test.dart @@ -41,7 +41,7 @@ class _FakeSheetExtent extends SheetPosition { this.createIdleActivity, }) : super( context: _FakeSheetContext(), - minExtent: const SheetAnchor.proportional(0.5), + minPosition: const SheetAnchor.proportional(0.5), maxExtent: const SheetAnchor.proportional(1), physics: const ClampingSheetPhysics(), ); diff --git a/test/navigation/navigation_sheet_test.dart b/test/navigation/navigation_sheet_test.dart index 3726272..3555a78 100644 --- a/test/navigation/navigation_sheet_test.dart +++ b/test/navigation/navigation_sheet_test.dart @@ -124,14 +124,14 @@ class _TestDraggablePageWidget extends StatelessWidget { required double height, String? nextRoute, SheetAnchor initialExtent = const SheetAnchor.proportional(1), - SheetAnchor minExtent = const SheetAnchor.proportional(1), + SheetAnchor minPosition = const SheetAnchor.proportional(1), Duration transitionDuration = const Duration(milliseconds: 300), SheetPhysics? physics, }) { return DraggableNavigationSheetRoute( physics: physics, initialExtent: initialExtent, - minExtent: minExtent, + minPosition: minPosition, transitionDuration: transitionDuration, builder: (context) => _TestDraggablePageWidget( key: key, @@ -203,7 +203,7 @@ class _TestScrollablePageWidget extends StatelessWidget { int itemCount = 30, String? nextRoute, SheetAnchor initialExtent = const SheetAnchor.proportional(1), - SheetAnchor minExtent = const SheetAnchor.proportional(1), + SheetAnchor minPosition = const SheetAnchor.proportional(1), Duration transitionDuration = const Duration(milliseconds: 300), SheetPhysics? physics, void Function(int index)? onTapItem, @@ -211,7 +211,7 @@ class _TestScrollablePageWidget extends StatelessWidget { return ScrollableNavigationSheetRoute( physics: physics, initialExtent: initialExtent, - minExtent: minExtent, + minPosition: minPosition, transitionDuration: transitionDuration, builder: (context) => _TestScrollablePageWidget( key: ValueKey(label), @@ -255,7 +255,7 @@ void main() { key: const Key('First'), label: 'First', height: 300, - minExtent: const SheetAnchor.pixels(0), + minPosition: const SheetAnchor.pixels(0), // Disable the snapping effect. physics: const ClampingSheetPhysics(), ), @@ -302,13 +302,13 @@ void main() { label: 'First', nextRoute: 'second', height: 300, - minExtent: const SheetAnchor.proportional(1), + minPosition: const SheetAnchor.proportional(1), ), 'second': () => _TestDraggablePageWidget.createRoute( key: const Key('Second'), label: 'Second', height: 500, - minExtent: const SheetAnchor.pixels(200), + minPosition: const SheetAnchor.pixels(200), transitionDuration: const Duration(milliseconds: 300), ), }, @@ -360,7 +360,7 @@ void main() { key: const Key('First'), label: 'First', height: 300, - minExtent: const SheetAnchor.pixels(0), + minPosition: const SheetAnchor.pixels(0), physics: const ClampingSheetPhysics(), ), }, @@ -458,7 +458,7 @@ void main() { 'first': () => _TestDraggablePageWidget.createRoute( label: 'First', height: 500, - minExtent: const SheetAnchor.pixels(200), + minPosition: const SheetAnchor.pixels(200), initialExtent: const SheetAnchor.pixels(200), ), }, diff --git a/test/scrollable/scrollable_sheet_test.dart b/test/scrollable/scrollable_sheet_test.dart index 6073094..5e734ac 100644 --- a/test/scrollable/scrollable_sheet_test.dart +++ b/test/scrollable/scrollable_sheet_test.dart @@ -106,7 +106,7 @@ void main() { child: ScrollableSheet( key: sheetKey, controller: controller, - minExtent: const SheetAnchor.pixels(200), + minPosition: const SheetAnchor.pixels(200), initialExtent: const SheetAnchor.pixels(200), child: const _TestSheetContent(height: 500), ), diff --git a/test/src/stubbing.dart b/test/src/stubbing.dart index 75a494b..86dc973 100644 --- a/test/src/stubbing.dart +++ b/test/src/stubbing.dart @@ -21,7 +21,7 @@ export 'stubbing.mocks.dart'; class MutableSheetMetrics with SheetMetrics { MutableSheetMetrics({ required this.maybePixels, - required this.maybeMinExtent, + required this.maybeMinPosition, required this.maybeMaxExtent, required this.maybeContentSize, required this.maybeViewportSize, @@ -36,7 +36,7 @@ class MutableSheetMetrics with SheetMetrics { SheetAnchor? maybeMaxExtent; @override - SheetAnchor? maybeMinExtent; + SheetAnchor? maybeMinPosition; @override double? maybePixels; @@ -53,7 +53,7 @@ class MutableSheetMetrics with SheetMetrics { @override SheetMetrics copyWith({ double? pixels, - SheetAnchor? minExtent, + SheetAnchor? minPosition, SheetAnchor? maxExtent, Size? contentSize, Size? viewportSize, @@ -62,7 +62,7 @@ class MutableSheetMetrics with SheetMetrics { }) { return SheetMetricsSnapshot( pixels: pixels ?? maybePixels, - minExtent: minExtent ?? maybeMinExtent, + minPosition: minPosition ?? maybeMinPosition, maxExtent: maxExtent ?? maybeMaxExtent, contentSize: contentSize ?? maybeContentSize, viewportSize: viewportSize ?? maybeViewportSize, @@ -72,9 +72,9 @@ class MutableSheetMetrics with SheetMetrics { } } -(MutableSheetMetrics, MockSheetExtent) createMockSheetExtent({ +(MutableSheetMetrics, MockSheetPosition) createMockSheetExtent({ required double pixels, - required SheetAnchor minExtent, + required SheetAnchor minPosition, required SheetAnchor maxExtent, required Size contentSize, required Size viewportSize, @@ -84,7 +84,7 @@ class MutableSheetMetrics with SheetMetrics { }) { final metricsRegistry = MutableSheetMetrics( maybePixels: pixels, - maybeMinExtent: minExtent, + maybeMinPosition: minPosition, maybeMaxExtent: maxExtent, maybeContentSize: contentSize, maybeViewportSize: viewportSize, @@ -92,11 +92,12 @@ class MutableSheetMetrics with SheetMetrics { devicePixelRatio: devicePixelRatio, ); - final extent = MockSheetExtent(); + final extent = MockSheetPosition(); when(extent.pixels).thenAnswer((_) => metricsRegistry.pixels); when(extent.maybePixels).thenAnswer((_) => metricsRegistry.maybePixels); - when(extent.minExtent).thenAnswer((_) => metricsRegistry.minExtent); - when(extent.maybeMinExtent).thenAnswer((_) => metricsRegistry.maybeMinExtent); + when(extent.minPosition).thenAnswer((_) => metricsRegistry.minPosition); + when(extent.maybeMinPosition) + .thenAnswer((_) => metricsRegistry.maybeMinPosition); when(extent.maxExtent).thenAnswer((_) => metricsRegistry.maxExtent); when(extent.maybeMaxExtent).thenAnswer((_) => metricsRegistry.maybeMaxExtent); when(extent.contentSize).thenAnswer((_) => metricsRegistry.contentSize); @@ -127,12 +128,12 @@ class MutableSheetMetrics with SheetMetrics { }); when(extent.applyNewBoundaryConstraints(any, any)).thenAnswer((invocation) { metricsRegistry - ..maybeMinExtent = invocation.positionalArguments.first as SheetAnchor + ..maybeMinPosition = invocation.positionalArguments.first as SheetAnchor ..maybeMaxExtent = invocation.positionalArguments.last as SheetAnchor; }); when(extent.copyWith( pixels: anyNamed('pixels'), - minExtent: anyNamed('minExtent'), + minPosition: anyNamed('minPosition'), maxExtent: anyNamed('maxExtent'), contentSize: anyNamed('contentSize'), viewportSize: anyNamed('viewportSize'), @@ -141,7 +142,7 @@ class MutableSheetMetrics with SheetMetrics { )).thenAnswer((invocation) { return metricsRegistry.copyWith( pixels: invocation.namedArguments[#pixels] as double?, - minExtent: invocation.namedArguments[#minExtent] as SheetAnchor?, + minPosition: invocation.namedArguments[#minPosition] as SheetAnchor?, maxExtent: invocation.namedArguments[#maxExtent] as SheetAnchor?, contentSize: invocation.namedArguments[#contentSize] as Size?, viewportSize: invocation.namedArguments[#viewportSize] as Size?, diff --git a/test/src/stubbing.mocks.dart b/test/src/stubbing.mocks.dart index 01fe974..c65e852 100644 --- a/test/src/stubbing.mocks.dart +++ b/test/src/stubbing.mocks.dart @@ -76,8 +76,8 @@ class _FakeSheetMetrics_3 extends _i1.SmartFake implements _i4.SheetMetrics { ); } -class _FakeExtent_4 extends _i1.SmartFake implements _i4.SheetAnchor { - _FakeExtent_4( +class _FakeSheetAnchor_4 extends _i1.SmartFake implements _i4.SheetAnchor { + _FakeSheetAnchor_4( Object parent, Invocation parentInvocation, ) : super( @@ -188,10 +188,10 @@ class _FakeTicker_13 extends _i1.SmartFake implements _i11.Ticker { String toString({bool? debugIncludeStack = false}) => super.toString(); } -/// A class which mocks [SheetExtent]. +/// A class which mocks [SheetPosition]. /// /// See the documentation for Mockito's code generation for more information. -class MockSheetExtent extends _i1.Mock implements _i4.SheetPosition { +class MockSheetPosition extends _i1.Mock implements _i4.SheetPosition { @override _i2.SheetContext get context => (super.noSuchMethod( Invocation.getter(#context), @@ -296,26 +296,26 @@ class MockSheetExtent extends _i1.Mock implements _i4.SheetPosition { ) as double); @override - _i4.SheetAnchor get minExtent => (super.noSuchMethod( - Invocation.getter(#minExtent), - returnValue: _FakeExtent_4( + _i4.SheetAnchor get minPosition => (super.noSuchMethod( + Invocation.getter(#minPosition), + returnValue: _FakeSheetAnchor_4( this, - Invocation.getter(#minExtent), + Invocation.getter(#minPosition), ), - returnValueForMissingStub: _FakeExtent_4( + returnValueForMissingStub: _FakeSheetAnchor_4( this, - Invocation.getter(#minExtent), + Invocation.getter(#minPosition), ), ) as _i4.SheetAnchor); @override _i4.SheetAnchor get maxExtent => (super.noSuchMethod( Invocation.getter(#maxExtent), - returnValue: _FakeExtent_4( + returnValue: _FakeSheetAnchor_4( this, Invocation.getter(#maxExtent), ), - returnValueForMissingStub: _FakeExtent_4( + returnValueForMissingStub: _FakeSheetAnchor_4( this, Invocation.getter(#maxExtent), ), @@ -457,14 +457,14 @@ class MockSheetExtent extends _i1.Mock implements _i4.SheetPosition { @override void applyNewBoundaryConstraints( - _i4.SheetAnchor? minExtent, + _i4.SheetAnchor? minPosition, _i4.SheetAnchor? maxExtent, ) => super.noSuchMethod( Invocation.method( #applyNewBoundaryConstraints, [ - minExtent, + minPosition, maxExtent, ], ), @@ -635,7 +635,7 @@ class MockSheetExtent extends _i1.Mock implements _i4.SheetPosition { @override _i4.SheetMetrics copyWith({ double? pixels, - _i4.SheetAnchor? minExtent, + _i4.SheetAnchor? minPosition, _i4.SheetAnchor? maxExtent, _i6.Size? contentSize, _i6.Size? viewportSize, @@ -648,7 +648,7 @@ class MockSheetExtent extends _i1.Mock implements _i4.SheetPosition { [], { #pixels: pixels, - #minExtent: minExtent, + #minPosition: minPosition, #maxExtent: maxExtent, #contentSize: contentSize, #viewportSize: viewportSize, @@ -663,7 +663,7 @@ class MockSheetExtent extends _i1.Mock implements _i4.SheetPosition { [], { #pixels: pixels, - #minExtent: minExtent, + #minPosition: minPosition, #maxExtent: maxExtent, #contentSize: contentSize, #viewportSize: viewportSize, @@ -679,7 +679,7 @@ class MockSheetExtent extends _i1.Mock implements _i4.SheetPosition { [], { #pixels: pixels, - #minExtent: minExtent, + #minPosition: minPosition, #maxExtent: maxExtent, #contentSize: contentSize, #viewportSize: viewportSize, From 952ab92d75656022db11f739a7c190998f63fb14 Mon Sep 17 00:00:00 2001 From: fujidaiti Date: Fri, 27 Sep 2024 11:50:30 +0900 Subject: [PATCH 12/22] Rename "maxExtent"s to "maxPosition"s --- example/lib/tutorial/sheet_physics.dart | 6 +- lib/src/draggable/draggable_sheet.dart | 8 +-- lib/src/draggable/draggable_sheet_extent.dart | 2 +- .../draggable_sheet_extent_scope.dart | 4 +- lib/src/foundation/sheet_activity.dart | 2 +- lib/src/foundation/sheet_extent_scope.dart | 11 ++-- lib/src/foundation/sheet_notification.dart | 2 +- lib/src/foundation/sheet_physics.dart | 10 +-- lib/src/foundation/sheet_position.dart | 62 +++++++++---------- lib/src/navigation/navigation_routes.dart | 36 +++++------ .../navigation/navigation_sheet_activity.dart | 2 +- .../navigation/navigation_sheet_extent.dart | 2 +- .../navigation_sheet_extent_scope.dart | 4 +- lib/src/scrollable/scrollable_sheet.dart | 8 +-- .../scrollable/scrollable_sheet_extent.dart | 2 +- .../scrollable_sheet_extent_scope.dart | 4 +- test/foundation/physics_test.dart | 14 ++--- test/foundation/sheet_activity_test.dart | 12 ++-- test/foundation/sheet_notification_test.dart | 2 +- test/foundation/sheet_viewport_test.dart | 4 +- test/src/stubbing.dart | 23 +++---- test/src/stubbing.mocks.dart | 20 +++--- 22 files changed, 121 insertions(+), 119 deletions(-) diff --git a/example/lib/tutorial/sheet_physics.dart b/example/lib/tutorial/sheet_physics.dart index 70abe94..4285a7e 100644 --- a/example/lib/tutorial/sheet_physics.dart +++ b/example/lib/tutorial/sheet_physics.dart @@ -95,7 +95,7 @@ class _MySheet extends StatelessWidget { ], ), // Tips: The above configuration can be replaced with a 'SnapToNearestEdge', - // which will snap to either the 'minPosition' or 'maxExtent' of the sheet: + // which will snap to either the 'minPosition' or 'maxPosition' of the sheet: // snappingBehavior: const SnapToNearestEdge(), ); @@ -113,14 +113,14 @@ class _MySheet extends StatelessWidget { @override Widget build(BuildContext context) { return DraggableSheet( - // The 'minPosition' and 'maxExtent' properties determine + // The 'minPosition' and 'maxPosition' properties determine // how far the sheet can be dragged. Note that "extent" // refers to the visible height of the sheet. For example, // the configuration below ensures that the sheet is fully visible // at first and can then be dragged down to (_halfwayFraction * 100)% // of the sheet height at minimum. minPosition: const SheetAnchor.proportional(_halfwayFraction), - maxExtent: const SheetAnchor.proportional(1), // Default + maxPosition: const SheetAnchor.proportional(1), // Default initialExtent: const SheetAnchor.proportional(1), // Default // 'physics' determines how the sheet will behave when the user reaches // the maximum or minimum extent, or when the user stops dragging. diff --git a/lib/src/draggable/draggable_sheet.dart b/lib/src/draggable/draggable_sheet.dart index 52b687d..37b480b 100644 --- a/lib/src/draggable/draggable_sheet.dart +++ b/lib/src/draggable/draggable_sheet.dart @@ -34,7 +34,7 @@ class DraggableSheet extends StatefulWidget { this.hitTestBehavior = HitTestBehavior.translucent, this.initialExtent = const SheetAnchor.proportional(1), this.minPosition = const SheetAnchor.proportional(1), - this.maxExtent = const SheetAnchor.proportional(1), + this.maxPosition = const SheetAnchor.proportional(1), this.physics, required this.child, this.controller, @@ -45,8 +45,8 @@ class DraggableSheet extends StatefulWidget { /// {@macro SheetExtentConfig.minPosition} final SheetAnchor minPosition; - /// {@macro SheetExtentConfig.maxExtent} - final SheetAnchor maxExtent; + /// {@macro SheetExtentConfig.maxPosition} + final SheetAnchor maxPosition; /// {@macro SheetExtentConfig.physics} final SheetPhysics? physics; @@ -81,7 +81,7 @@ class _DraggableSheetState extends State controller: controller, initialExtent: widget.initialExtent, minPosition: widget.minPosition, - maxExtent: widget.maxExtent, + maxPosition: widget.maxPosition, physics: physics, gestureTamperer: gestureTamper, debugLabel: kDebugMode ? 'DraggableSheet' : null, diff --git a/lib/src/draggable/draggable_sheet_extent.dart b/lib/src/draggable/draggable_sheet_extent.dart index cb24742..2a232a9 100644 --- a/lib/src/draggable/draggable_sheet_extent.dart +++ b/lib/src/draggable/draggable_sheet_extent.dart @@ -9,7 +9,7 @@ class DraggableSheetExtent extends SheetPosition { DraggableSheetExtent({ required super.context, required super.minPosition, - required super.maxExtent, + required super.maxPosition, required this.initialExtent, required super.physics, super.gestureTamperer, diff --git a/lib/src/draggable/draggable_sheet_extent_scope.dart b/lib/src/draggable/draggable_sheet_extent_scope.dart index a8b92df..3520108 100644 --- a/lib/src/draggable/draggable_sheet_extent_scope.dart +++ b/lib/src/draggable/draggable_sheet_extent_scope.dart @@ -14,7 +14,7 @@ class DraggableSheetExtentScope extends SheetExtentScope { required super.context, required this.initialExtent, required super.minPosition, - required super.maxExtent, + required super.maxPosition, required super.physics, super.gestureTamperer, this.debugLabel, @@ -48,7 +48,7 @@ class _DraggableSheetExtentScopeState extends SheetExtentScopeState< context: context, initialExtent: widget.initialExtent, minPosition: widget.minPosition, - maxExtent: widget.maxExtent, + maxPosition: widget.maxPosition, physics: widget.physics, gestureTamperer: widget.gestureTamperer, debugLabel: widget.debugLabel, diff --git a/lib/src/foundation/sheet_activity.dart b/lib/src/foundation/sheet_activity.dart index 7374cc9..e7f8a1c 100644 --- a/lib/src/foundation/sheet_activity.dart +++ b/lib/src/foundation/sheet_activity.dart @@ -68,7 +68,7 @@ abstract class SheetActivity { void didChangeBoundaryConstraints( SheetAnchor? oldMinPosition, - SheetAnchor? oldMaxExtent, + SheetAnchor? oldMaxPosition, ) {} /// Called when all relevant metrics of the sheet are finalized diff --git a/lib/src/foundation/sheet_extent_scope.dart b/lib/src/foundation/sheet_extent_scope.dart index c65f5d0..5d4f077 100644 --- a/lib/src/foundation/sheet_extent_scope.dart +++ b/lib/src/foundation/sheet_extent_scope.dart @@ -58,7 +58,7 @@ abstract class SheetExtentScope extends StatefulWidget { this.controller, this.isPrimary = true, required this.minPosition, - required this.maxExtent, + required this.maxPosition, required this.physics, this.gestureTamperer, required this.child, @@ -73,8 +73,8 @@ abstract class SheetExtentScope extends StatefulWidget { /// {@macro SheetExtent.minPosition} final SheetAnchor minPosition; - /// {@macro SheetExtent.maxExtent} - final SheetAnchor maxExtent; + /// {@macro SheetExtent.maxPosition} + final SheetAnchor maxPosition; /// {@macro SheetPosition.physics} final SheetPhysics physics; @@ -179,8 +179,9 @@ abstract class SheetExtentScopeState= minFlingSpeed) { - return metrics.maxExtent; + return metrics.maxPosition; } if (velocity <= -minFlingSpeed) { return metrics.minPosition; @@ -221,7 +221,7 @@ class SnapToNearestEdge implements SnappingSheetBehavior { } return (pixels - minPixels).abs() < (pixels - maxPixels).abs() ? metrics.minPosition - : metrics.maxExtent; + : metrics.maxPosition; } } diff --git a/lib/src/foundation/sheet_position.dart b/lib/src/foundation/sheet_position.dart index dff555d..0582aa2 100644 --- a/lib/src/foundation/sheet_position.dart +++ b/lib/src/foundation/sheet_position.dart @@ -141,7 +141,7 @@ abstract class SheetPosition extends ChangeNotifier SheetPosition({ required this.context, required SheetAnchor minPosition, - required SheetAnchor maxExtent, + required SheetAnchor maxPosition, required SheetPhysics physics, this.debugLabel, SheetGestureProxyMixin? gestureTamperer, @@ -149,7 +149,7 @@ abstract class SheetPosition extends ChangeNotifier _gestureTamperer = gestureTamperer, _snapshot = SheetMetrics.empty.copyWith( minPosition: minPosition, - maxExtent: maxExtent, + maxPosition: maxPosition, ) { goIdle(); } @@ -164,7 +164,7 @@ abstract class SheetPosition extends ChangeNotifier SheetAnchor? get maybeMinPosition => snapshot.maybeMinPosition; @override - SheetAnchor? get maybeMaxExtent => snapshot.maybeMaxExtent; + SheetAnchor? get maybeMaxPosition => snapshot.maybeMaxPosition; @override Size? get maybeContentSize => snapshot.maybeContentSize; @@ -223,7 +223,7 @@ abstract class SheetPosition extends ChangeNotifier void _updateMetrics({ double? pixels, SheetAnchor? minPosition, - SheetAnchor? maxExtent, + SheetAnchor? maxPosition, Size? contentSize, Size? viewportSize, EdgeInsets? viewportInsets, @@ -231,7 +231,7 @@ abstract class SheetPosition extends ChangeNotifier _snapshot = SheetMetricsSnapshot( pixels: pixels ?? maybePixels, minPosition: minPosition ?? maybeMinPosition, - maxExtent: maxExtent ?? maybeMaxExtent, + maxPosition: maxPosition ?? maybeMaxPosition, contentSize: contentSize ?? maybeContentSize, viewportSize: viewportSize ?? maybeViewportSize, viewportInsets: viewportInsets ?? maybeViewportInsets, @@ -262,7 +262,7 @@ abstract class SheetPosition extends ChangeNotifier if (other.maybePixels case final pixels?) { correctPixels(pixels); } - applyNewBoundaryConstraints(other.minPosition, other.maxExtent); + applyNewBoundaryConstraints(other.minPosition, other.maxPosition); applyNewViewportDimensions( other.viewportSize, other.viewportInsets, @@ -308,12 +308,12 @@ abstract class SheetPosition extends ChangeNotifier @mustCallSuper void applyNewBoundaryConstraints( - SheetAnchor minPosition, SheetAnchor maxExtent) { - if (minPosition != this.minPosition || maxExtent != this.maxExtent) { + SheetAnchor minPosition, SheetAnchor maxPosition) { + if (minPosition != this.minPosition || maxPosition != this.maxPosition) { final oldMinPosition = maybeMinPosition; - final oldMaxExtent = maybeMaxExtent; - _updateMetrics(minPosition: minPosition, maxExtent: maxExtent); - activity.didChangeBoundaryConstraints(oldMinPosition, oldMaxExtent); + final oldMaxPosition = maybeMaxPosition; + _updateMetrics(minPosition: minPosition, maxPosition: maxPosition); + activity.didChangeBoundaryConstraints(oldMinPosition, oldMaxPosition); } } @@ -521,7 +521,7 @@ abstract class SheetPosition extends ChangeNotifier SheetMetrics copyWith({ double? pixels, SheetAnchor? minPosition, - SheetAnchor? maxExtent, + SheetAnchor? maxPosition, Size? contentSize, Size? viewportSize, EdgeInsets? viewportInsets, @@ -530,7 +530,7 @@ abstract class SheetPosition extends ChangeNotifier return snapshot.copyWith( pixels: pixels, minPosition: minPosition, - maxExtent: maxExtent, + maxPosition: maxPosition, contentSize: contentSize, viewportSize: viewportSize, viewportInsets: viewportInsets, @@ -601,7 +601,7 @@ mixin SheetMetrics { static const SheetMetrics empty = SheetMetricsSnapshot( pixels: null, minPosition: null, - maxExtent: null, + maxPosition: null, contentSize: null, viewportSize: null, viewportInsets: null, @@ -609,7 +609,7 @@ mixin SheetMetrics { double? get maybePixels; SheetAnchor? get maybeMinPosition; - SheetAnchor? get maybeMaxExtent; + SheetAnchor? get maybeMaxPosition; Size? get maybeContentSize; Size? get maybeViewportSize; EdgeInsets? get maybeViewportInsets; @@ -623,7 +623,7 @@ mixin SheetMetrics { SheetMetrics copyWith({ double? pixels, SheetAnchor? minPosition, - SheetAnchor? maxExtent, + SheetAnchor? maxPosition, Size? contentSize, Size? viewportSize, EdgeInsets? viewportInsets, @@ -636,9 +636,9 @@ mixin SheetMetrics { _ => null, }; - double? get maybeMaxPixels => switch ((maybeMaxExtent, maybeContentSize)) { - (final maxExtent?, final contentSize?) => - maxExtent.resolve(contentSize), + double? get maybeMaxPixels => switch ((maybeMaxPosition, maybeContentSize)) { + (final maxPosition?, final contentSize?) => + maxPosition.resolve(contentSize), _ => null, }; @@ -667,9 +667,9 @@ mixin SheetMetrics { } /// The maximum position of the sheet. - SheetAnchor get maxExtent { - assert(_debugAssertHasProperty('maxExtent', maybeMaxExtent)); - return maybeMaxExtent!; + SheetAnchor get maxPosition { + assert(_debugAssertHasProperty('maxPosition', maybeMaxPosition)); + return maybeMaxPosition!; } /// The size of the sheet's content. @@ -714,7 +714,7 @@ mixin SheetMetrics { bool get hasDimensions => maybePixels != null && maybeMinPosition != null && - maybeMaxExtent != null && + maybeMaxPosition != null && maybeContentSize != null && maybeViewportSize != null && maybeViewportInsets != null; @@ -752,14 +752,14 @@ class SheetMetricsSnapshot with SheetMetrics { const SheetMetricsSnapshot({ required double? pixels, required SheetAnchor? minPosition, - required SheetAnchor? maxExtent, + required SheetAnchor? maxPosition, required Size? contentSize, required Size? viewportSize, required EdgeInsets? viewportInsets, this.devicePixelRatio = 1.0, }) : maybePixels = pixels, maybeMinPosition = minPosition, - maybeMaxExtent = maxExtent, + maybeMaxPosition = maxPosition, maybeContentSize = contentSize, maybeViewportSize = viewportSize, maybeViewportInsets = viewportInsets; @@ -771,7 +771,7 @@ class SheetMetricsSnapshot with SheetMetrics { final SheetAnchor? maybeMinPosition; @override - final SheetAnchor? maybeMaxExtent; + final SheetAnchor? maybeMaxPosition; @override final Size? maybeContentSize; @@ -789,7 +789,7 @@ class SheetMetricsSnapshot with SheetMetrics { SheetMetricsSnapshot copyWith({ double? pixels, SheetAnchor? minPosition, - SheetAnchor? maxExtent, + SheetAnchor? maxPosition, Size? contentSize, Size? viewportSize, EdgeInsets? viewportInsets, @@ -798,7 +798,7 @@ class SheetMetricsSnapshot with SheetMetrics { return SheetMetricsSnapshot( pixels: pixels ?? maybePixels, minPosition: minPosition ?? maybeMinPosition, - maxExtent: maxExtent ?? maybeMaxExtent, + maxPosition: maxPosition ?? maybeMaxPosition, contentSize: contentSize ?? maybeContentSize, viewportSize: viewportSize ?? maybeViewportSize, viewportInsets: viewportInsets ?? maybeViewportInsets, @@ -813,7 +813,7 @@ class SheetMetricsSnapshot with SheetMetrics { runtimeType == other.runtimeType && maybePixels == other.maybePixels && maybeMinPosition == other.maybeMinPosition && - maybeMaxExtent == other.maybeMaxExtent && + maybeMaxPosition == other.maybeMaxPosition && maybeContentSize == other.maybeContentSize && maybeViewportSize == other.maybeViewportSize && maybeViewportInsets == other.maybeViewportInsets && @@ -824,7 +824,7 @@ class SheetMetricsSnapshot with SheetMetrics { runtimeType, maybePixels, maybeMinPosition, - maybeMaxExtent, + maybeMaxPosition, maybeContentSize, maybeViewportSize, maybeViewportInsets, @@ -841,7 +841,7 @@ class SheetMetricsSnapshot with SheetMetrics { minViewPixels: maybeMinViewPixels, maxViewPixels: maybeMaxViewPixels, minPosition: maybeMinPosition, - maxExtent: maybeMaxExtent, + maxPosition: maybeMaxPosition, contentSize: maybeContentSize, viewportSize: maybeViewportSize, viewportInsets: maybeViewportInsets, diff --git a/lib/src/navigation/navigation_routes.dart b/lib/src/navigation/navigation_routes.dart index 47c27bb..7430955 100644 --- a/lib/src/navigation/navigation_routes.dart +++ b/lib/src/navigation/navigation_routes.dart @@ -19,7 +19,7 @@ class _ScrollableNavigationSheetRouteContent extends StatelessWidget { this.debugLabel, required this.initialExtent, required this.minPosition, - required this.maxExtent, + required this.maxPosition, required this.physics, required this.child, }); @@ -27,7 +27,7 @@ class _ScrollableNavigationSheetRouteContent extends StatelessWidget { final String? debugLabel; final SheetAnchor initialExtent; final SheetAnchor minPosition; - final SheetAnchor maxExtent; + final SheetAnchor maxPosition; final SheetPhysics? physics; final Widget child; @@ -44,7 +44,7 @@ class _ScrollableNavigationSheetRouteContent extends StatelessWidget { isPrimary: false, initialExtent: initialExtent, minPosition: minPosition, - maxExtent: maxExtent, + maxPosition: maxPosition, physics: physics ?? theme?.physics ?? kDefaultSheetPhysics, gestureTamperer: gestureTamper, child: child, @@ -60,7 +60,7 @@ class _DraggableNavigationSheetRouteContent extends StatelessWidget { this.debugLabel, required this.initialExtent, required this.minPosition, - required this.maxExtent, + required this.maxPosition, required this.physics, required this.child, }); @@ -68,7 +68,7 @@ class _DraggableNavigationSheetRouteContent extends StatelessWidget { final String? debugLabel; final SheetAnchor initialExtent; final SheetAnchor minPosition; - final SheetAnchor maxExtent; + final SheetAnchor maxPosition; final SheetPhysics? physics; final Widget child; @@ -86,7 +86,7 @@ class _DraggableNavigationSheetRouteContent extends StatelessWidget { isPrimary: false, initialExtent: initialExtent, minPosition: minPosition, - maxExtent: maxExtent, + maxPosition: maxPosition, physics: physics, gestureTamperer: gestureTamper, debugLabel: debugLabel, @@ -106,7 +106,7 @@ class ScrollableNavigationSheetRoute this.transitionDuration = const Duration(milliseconds: 300), this.initialExtent = const SheetAnchor.proportional(1), this.minPosition = const SheetAnchor.proportional(1), - this.maxExtent = const SheetAnchor.proportional(1), + this.maxPosition = const SheetAnchor.proportional(1), this.physics, this.transitionsBuilder, required this.builder, @@ -114,7 +114,7 @@ class ScrollableNavigationSheetRoute final SheetAnchor initialExtent; final SheetAnchor minPosition; - final SheetAnchor maxExtent; + final SheetAnchor maxPosition; final SheetPhysics? physics; @override @@ -145,7 +145,7 @@ class ScrollableNavigationSheetRoute debugLabel: '$ScrollableNavigationSheetRoute(${settings.name})', initialExtent: initialExtent, minPosition: minPosition, - maxExtent: maxExtent, + maxPosition: maxPosition, physics: physics, child: builder(context), ); @@ -160,7 +160,7 @@ class DraggableNavigationSheetRoute this.transitionDuration = const Duration(milliseconds: 300), this.initialExtent = const SheetAnchor.proportional(1), this.minPosition = const SheetAnchor.proportional(1), - this.maxExtent = const SheetAnchor.proportional(1), + this.maxPosition = const SheetAnchor.proportional(1), this.physics, this.transitionsBuilder, required this.builder, @@ -168,7 +168,7 @@ class DraggableNavigationSheetRoute final SheetAnchor initialExtent; final SheetAnchor minPosition; - final SheetAnchor maxExtent; + final SheetAnchor maxPosition; final SheetPhysics? physics; @override @@ -199,7 +199,7 @@ class DraggableNavigationSheetRoute debugLabel: '$DraggableNavigationSheetRoute(${settings.name})', initialExtent: initialExtent, minPosition: minPosition, - maxExtent: maxExtent, + maxPosition: maxPosition, physics: physics, child: builder(context), ); @@ -216,7 +216,7 @@ class ScrollableNavigationSheetPage extends Page { this.transitionDuration = const Duration(milliseconds: 300), this.initialExtent = const SheetAnchor.proportional(1), this.minPosition = const SheetAnchor.proportional(1), - this.maxExtent = const SheetAnchor.proportional(1), + this.maxPosition = const SheetAnchor.proportional(1), this.physics, this.transitionsBuilder, required this.child, @@ -229,7 +229,7 @@ class ScrollableNavigationSheetPage extends Page { final SheetAnchor initialExtent; final SheetAnchor minPosition; - final SheetAnchor maxExtent; + final SheetAnchor maxPosition; final SheetPhysics? physics; @@ -279,7 +279,7 @@ class _PageBasedScrollableNavigationSheetRoute debugLabel: '$ScrollableNavigationSheetPage(${page.name})', initialExtent: page.initialExtent, minPosition: page.minPosition, - maxExtent: page.maxExtent, + maxPosition: page.maxPosition, physics: page.physics, child: page.child, ); @@ -296,7 +296,7 @@ class DraggableNavigationSheetPage extends Page { this.transitionDuration = const Duration(milliseconds: 300), this.initialExtent = const SheetAnchor.proportional(1), this.minPosition = const SheetAnchor.proportional(1), - this.maxExtent = const SheetAnchor.proportional(1), + this.maxPosition = const SheetAnchor.proportional(1), this.physics, this.transitionsBuilder, required this.child, @@ -309,7 +309,7 @@ class DraggableNavigationSheetPage extends Page { final SheetAnchor initialExtent; final SheetAnchor minPosition; - final SheetAnchor maxExtent; + final SheetAnchor maxPosition; final SheetPhysics? physics; @@ -359,7 +359,7 @@ class _PageBasedDraggableNavigationSheetRoute debugLabel: '$DraggableNavigationSheetPage(${page.name})', initialExtent: page.initialExtent, minPosition: page.minPosition, - maxExtent: page.maxExtent, + maxPosition: page.maxPosition, physics: page.physics, child: page.child, ); diff --git a/lib/src/navigation/navigation_sheet_activity.dart b/lib/src/navigation/navigation_sheet_activity.dart index 2fb8359..694b4b8 100644 --- a/lib/src/navigation/navigation_sheet_activity.dart +++ b/lib/src/navigation/navigation_sheet_activity.dart @@ -106,7 +106,7 @@ class ProxySheetActivity extends NavigationSheetActivity { final localMetrics = localExtent.snapshot; owner.applyNewBoundaryConstraints( localExtent.minPosition, - localExtent.maxExtent, + localExtent.maxPosition, ); if (localMetrics.maybeContentSize case final contentSize?) { owner.applyNewContentSize(contentSize); diff --git a/lib/src/navigation/navigation_sheet_extent.dart b/lib/src/navigation/navigation_sheet_extent.dart index 3b524fc..b05983f 100644 --- a/lib/src/navigation/navigation_sheet_extent.dart +++ b/lib/src/navigation/navigation_sheet_extent.dart @@ -13,7 +13,7 @@ class NavigationSheetExtent extends SheetPosition { NavigationSheetExtent({ required super.context, required super.minPosition, - required super.maxExtent, + required super.maxPosition, required super.physics, super.gestureTamperer, super.debugLabel, diff --git a/lib/src/navigation/navigation_sheet_extent_scope.dart b/lib/src/navigation/navigation_sheet_extent_scope.dart index 7388cf2..65fb87a 100644 --- a/lib/src/navigation/navigation_sheet_extent_scope.dart +++ b/lib/src/navigation/navigation_sheet_extent_scope.dart @@ -17,7 +17,7 @@ class NavigationSheetExtentScope extends SheetExtentScope { required super.child, }) : super( minPosition: const SheetAnchor.pixels(0), - maxExtent: const SheetAnchor.proportional(1), + maxPosition: const SheetAnchor.proportional(1), // TODO: Use more appropriate physics. physics: const ClampingSheetPhysics(), isPrimary: true, @@ -45,7 +45,7 @@ class _NavigationSheetExtentScopeState extends SheetExtentScopeState< return NavigationSheetExtent( context: context, minPosition: widget.minPosition, - maxExtent: widget.maxExtent, + maxPosition: widget.maxPosition, physics: widget.physics, gestureTamperer: widget.gestureTamperer, debugLabel: widget.debugLabel, diff --git a/lib/src/scrollable/scrollable_sheet.dart b/lib/src/scrollable/scrollable_sheet.dart index da3dd3f..f949611 100644 --- a/lib/src/scrollable/scrollable_sheet.dart +++ b/lib/src/scrollable/scrollable_sheet.dart @@ -18,7 +18,7 @@ class ScrollableSheet extends StatefulWidget { super.key, this.initialExtent = const SheetAnchor.proportional(1), this.minPosition = const SheetAnchor.proportional(1), - this.maxExtent = const SheetAnchor.proportional(1), + this.maxPosition = const SheetAnchor.proportional(1), this.physics, this.controller, required this.child, @@ -30,8 +30,8 @@ class ScrollableSheet extends StatefulWidget { /// {@macro SheetExtent.minPosition} final SheetAnchor minPosition; - /// {@macro SheetExtent.maxExtent} - final SheetAnchor maxExtent; + /// {@macro SheetExtent.maxPosition} + final SheetAnchor maxPosition; /// {@macro SheetPosition.physics} final SheetPhysics? physics; @@ -61,7 +61,7 @@ class _ScrollableSheetState extends State controller: controller, initialExtent: widget.initialExtent, minPosition: widget.minPosition, - maxExtent: widget.maxExtent, + maxPosition: widget.maxPosition, physics: physics, gestureTamperer: gestureTamper, debugLabel: kDebugMode ? 'ScrollableSheet' : null, diff --git a/lib/src/scrollable/scrollable_sheet_extent.dart b/lib/src/scrollable/scrollable_sheet_extent.dart index 5fbf3de..121cd6a 100644 --- a/lib/src/scrollable/scrollable_sheet_extent.dart +++ b/lib/src/scrollable/scrollable_sheet_extent.dart @@ -20,7 +20,7 @@ class ScrollableSheetExtent extends SheetPosition required super.context, required this.initialExtent, required super.minPosition, - required super.maxExtent, + required super.maxPosition, required SheetPhysics physics, super.gestureTamperer, super.debugLabel, diff --git a/lib/src/scrollable/scrollable_sheet_extent_scope.dart b/lib/src/scrollable/scrollable_sheet_extent_scope.dart index 0e66c63..ad2084d 100644 --- a/lib/src/scrollable/scrollable_sheet_extent_scope.dart +++ b/lib/src/scrollable/scrollable_sheet_extent_scope.dart @@ -14,7 +14,7 @@ class ScrollableSheetExtentScope extends SheetExtentScope { required super.context, required this.initialExtent, required super.minPosition, - required super.maxExtent, + required super.maxPosition, required super.physics, super.gestureTamperer, this.debugLabel, @@ -48,7 +48,7 @@ class _ScrollableSheetExtentScopeState extends SheetExtentScopeState< context: context, initialExtent: widget.initialExtent, minPosition: widget.minPosition, - maxExtent: widget.maxExtent, + maxPosition: widget.maxPosition, physics: widget.physics, gestureTamperer: widget.gestureTamperer, debugLabel: widget.debugLabel, diff --git a/test/foundation/physics_test.dart b/test/foundation/physics_test.dart index 1d145a5..a03c6a6 100644 --- a/test/foundation/physics_test.dart +++ b/test/foundation/physics_test.dart @@ -16,7 +16,7 @@ class _SheetPhysicsWithDefaultConfiguration extends SheetPhysics const _referenceSheetMetrics = SheetMetricsSnapshot( minPosition: SheetAnchor.pixels(0), - maxExtent: SheetAnchor.proportional(1), + maxPosition: SheetAnchor.proportional(1), pixels: 600, contentSize: Size(360, 600), viewportSize: Size(360, 700), @@ -178,13 +178,13 @@ void main() { ); expect( physicsUnderTest.findSettledExtent(0, overDraggedPosition), - _referenceSheetMetrics.maxExtent, + _referenceSheetMetrics.maxPosition, reason: 'Should return the max extent if the position ' 'is out of the upper bound', ); expect( physicsUnderTest.findSettledExtent(1000, overDraggedPosition), - _referenceSheetMetrics.maxExtent, + _referenceSheetMetrics.maxPosition, reason: 'The velocity should not affect the result', ); @@ -206,7 +206,7 @@ void main() { // Boundary conditions expect( physicsUnderTest.findSettledExtent(1000, _positionAtTopEdge), - _referenceSheetMetrics.maxExtent, + _referenceSheetMetrics.maxPosition, reason: 'Should return the max extent if the position is at the upper bound', ); @@ -236,7 +236,7 @@ void main() { expect( behaviorUnderTest.findSettledExtent(0, positionAtNearTopEdge), - _referenceSheetMetrics.maxExtent, + _referenceSheetMetrics.maxPosition, ); expect( behaviorUnderTest.findSettledExtent(0, positionAtNearBottomEdge), @@ -247,7 +247,7 @@ void main() { test('is aware of fling gesture direction', () { expect( behaviorUnderTest.findSettledExtent(50, _positionAtBottomEdge), - _referenceSheetMetrics.maxExtent, + _referenceSheetMetrics.maxPosition, ); expect( behaviorUnderTest.findSettledExtent(-50, _positionAtTopEdge), @@ -284,7 +284,7 @@ void main() { ); expect( behaviorUnderTest.findSettledExtent(50, _positionAtBottomEdge), - _referenceSheetMetrics.maxExtent, + _referenceSheetMetrics.maxPosition, ); }); }); diff --git a/test/foundation/sheet_activity_test.dart b/test/foundation/sheet_activity_test.dart index dd0032f..0a3c0c4 100644 --- a/test/foundation/sheet_activity_test.dart +++ b/test/foundation/sheet_activity_test.dart @@ -44,7 +44,7 @@ void main() { final (ownerMetrics, owner) = createMockSheetExtent( pixels: 300, minPosition: const SheetAnchor.pixels(300), - maxExtent: const SheetAnchor.pixels(700), + maxPosition: const SheetAnchor.pixels(700), contentSize: const Size(400, 700), viewportSize: const Size(400, 900), viewportInsets: EdgeInsets.zero, @@ -83,7 +83,7 @@ void main() { final (ownerMetrics, owner) = createMockSheetExtent( pixels: 300, minPosition: const SheetAnchor.pixels(300), - maxExtent: const SheetAnchor.proportional(1), + maxPosition: const SheetAnchor.proportional(1), contentSize: const Size(400, 900), viewportSize: const Size(400, 900), viewportInsets: EdgeInsets.zero, @@ -143,7 +143,7 @@ void main() { (ownerMetrics, owner) = createMockSheetExtent( pixels: 300, minPosition: const SheetAnchor.proportional(0.5), - maxExtent: const SheetAnchor.proportional(1), + maxPosition: const SheetAnchor.proportional(1), contentSize: const Size(400, 600), viewportSize: const Size(400, 900), viewportInsets: EdgeInsets.zero, @@ -275,7 +275,7 @@ void main() { final (ownerMetrics, owner) = createMockSheetExtent( pixels: 450, minPosition: const SheetAnchor.proportional(0.5), - maxExtent: const SheetAnchor.proportional(1), + maxPosition: const SheetAnchor.proportional(1), contentSize: const Size(400, 850), viewportSize: const Size(400, 900), viewportInsets: const EdgeInsets.only(bottom: 50), @@ -300,7 +300,7 @@ void main() { final (ownerMetrics, owner) = createMockSheetExtent( pixels: 300, minPosition: const SheetAnchor.proportional(0.5), - maxExtent: const SheetAnchor.proportional(1), + maxPosition: const SheetAnchor.proportional(1), contentSize: const Size(400, 580), viewportSize: const Size(400, 900), viewportInsets: EdgeInsets.zero, @@ -326,7 +326,7 @@ void main() { final (ownerMetrics, owner) = createMockSheetExtent( pixels: 300, minPosition: const SheetAnchor.proportional(0.5), - maxExtent: const SheetAnchor.proportional(1), + maxPosition: const SheetAnchor.proportional(1), contentSize: const Size(400, 500), viewportSize: const Size(400, 900), viewportInsets: EdgeInsets.zero, diff --git a/test/foundation/sheet_notification_test.dart b/test/foundation/sheet_notification_test.dart index 61cd417..a260afa 100644 --- a/test/foundation/sheet_notification_test.dart +++ b/test/foundation/sheet_notification_test.dart @@ -245,7 +245,7 @@ void main() { child: DraggableSheet( // Make sure the sheet can't be dragged minPosition: const SheetAnchor.proportional(1), - maxExtent: const SheetAnchor.proportional(1), + maxPosition: const SheetAnchor.proportional(1), // Disable the snapping effect physics: const ClampingSheetPhysics(), child: Container( diff --git a/test/foundation/sheet_viewport_test.dart b/test/foundation/sheet_viewport_test.dart index c7ea9ca..1691acf 100644 --- a/test/foundation/sheet_viewport_test.dart +++ b/test/foundation/sheet_viewport_test.dart @@ -42,7 +42,7 @@ class _FakeSheetExtent extends SheetPosition { }) : super( context: _FakeSheetContext(), minPosition: const SheetAnchor.proportional(0.5), - maxExtent: const SheetAnchor.proportional(1), + maxPosition: const SheetAnchor.proportional(1), physics: const ClampingSheetPhysics(), ); @@ -52,7 +52,7 @@ class _FakeSheetExtent extends SheetPosition { void applyNewContentSize(Size contentSize) { super.applyNewContentSize(contentSize); if (maybePixels == null) { - setPixels(maxExtent.resolve(contentSize)); + setPixels(maxPosition.resolve(contentSize)); } } diff --git a/test/src/stubbing.dart b/test/src/stubbing.dart index 86dc973..ed9daed 100644 --- a/test/src/stubbing.dart +++ b/test/src/stubbing.dart @@ -22,7 +22,7 @@ class MutableSheetMetrics with SheetMetrics { MutableSheetMetrics({ required this.maybePixels, required this.maybeMinPosition, - required this.maybeMaxExtent, + required this.maybeMaxPosition, required this.maybeContentSize, required this.maybeViewportSize, required this.maybeViewportInsets, @@ -33,7 +33,7 @@ class MutableSheetMetrics with SheetMetrics { double devicePixelRatio; @override - SheetAnchor? maybeMaxExtent; + SheetAnchor? maybeMaxPosition; @override SheetAnchor? maybeMinPosition; @@ -54,7 +54,7 @@ class MutableSheetMetrics with SheetMetrics { SheetMetrics copyWith({ double? pixels, SheetAnchor? minPosition, - SheetAnchor? maxExtent, + SheetAnchor? maxPosition, Size? contentSize, Size? viewportSize, EdgeInsets? viewportInsets, @@ -63,7 +63,7 @@ class MutableSheetMetrics with SheetMetrics { return SheetMetricsSnapshot( pixels: pixels ?? maybePixels, minPosition: minPosition ?? maybeMinPosition, - maxExtent: maxExtent ?? maybeMaxExtent, + maxPosition: maxPosition ?? maybeMaxPosition, contentSize: contentSize ?? maybeContentSize, viewportSize: viewportSize ?? maybeViewportSize, viewportInsets: viewportInsets ?? maybeViewportInsets, @@ -75,7 +75,7 @@ class MutableSheetMetrics with SheetMetrics { (MutableSheetMetrics, MockSheetPosition) createMockSheetExtent({ required double pixels, required SheetAnchor minPosition, - required SheetAnchor maxExtent, + required SheetAnchor maxPosition, required Size contentSize, required Size viewportSize, required EdgeInsets viewportInsets, @@ -85,7 +85,7 @@ class MutableSheetMetrics with SheetMetrics { final metricsRegistry = MutableSheetMetrics( maybePixels: pixels, maybeMinPosition: minPosition, - maybeMaxExtent: maxExtent, + maybeMaxPosition: maxPosition, maybeContentSize: contentSize, maybeViewportSize: viewportSize, maybeViewportInsets: viewportInsets, @@ -98,8 +98,9 @@ class MutableSheetMetrics with SheetMetrics { when(extent.minPosition).thenAnswer((_) => metricsRegistry.minPosition); when(extent.maybeMinPosition) .thenAnswer((_) => metricsRegistry.maybeMinPosition); - when(extent.maxExtent).thenAnswer((_) => metricsRegistry.maxExtent); - when(extent.maybeMaxExtent).thenAnswer((_) => metricsRegistry.maybeMaxExtent); + when(extent.maxPosition).thenAnswer((_) => metricsRegistry.maxPosition); + when(extent.maybeMaxPosition) + .thenAnswer((_) => metricsRegistry.maybeMaxPosition); when(extent.contentSize).thenAnswer((_) => metricsRegistry.contentSize); when(extent.maybeContentSize) .thenAnswer((_) => metricsRegistry.maybeContentSize); @@ -129,12 +130,12 @@ class MutableSheetMetrics with SheetMetrics { when(extent.applyNewBoundaryConstraints(any, any)).thenAnswer((invocation) { metricsRegistry ..maybeMinPosition = invocation.positionalArguments.first as SheetAnchor - ..maybeMaxExtent = invocation.positionalArguments.last as SheetAnchor; + ..maybeMaxPosition = invocation.positionalArguments.last as SheetAnchor; }); when(extent.copyWith( pixels: anyNamed('pixels'), minPosition: anyNamed('minPosition'), - maxExtent: anyNamed('maxExtent'), + maxPosition: anyNamed('maxPosition'), contentSize: anyNamed('contentSize'), viewportSize: anyNamed('viewportSize'), viewportInsets: anyNamed('viewportInsets'), @@ -143,7 +144,7 @@ class MutableSheetMetrics with SheetMetrics { return metricsRegistry.copyWith( pixels: invocation.namedArguments[#pixels] as double?, minPosition: invocation.namedArguments[#minPosition] as SheetAnchor?, - maxExtent: invocation.namedArguments[#maxExtent] as SheetAnchor?, + maxPosition: invocation.namedArguments[#maxPosition] as SheetAnchor?, contentSize: invocation.namedArguments[#contentSize] as Size?, viewportSize: invocation.namedArguments[#viewportSize] as Size?, viewportInsets: invocation.namedArguments[#viewportInsets] as EdgeInsets?, diff --git a/test/src/stubbing.mocks.dart b/test/src/stubbing.mocks.dart index c65e852..30cba95 100644 --- a/test/src/stubbing.mocks.dart +++ b/test/src/stubbing.mocks.dart @@ -309,15 +309,15 @@ class MockSheetPosition extends _i1.Mock implements _i4.SheetPosition { ) as _i4.SheetAnchor); @override - _i4.SheetAnchor get maxExtent => (super.noSuchMethod( - Invocation.getter(#maxExtent), + _i4.SheetAnchor get maxPosition => (super.noSuchMethod( + Invocation.getter(#maxPosition), returnValue: _FakeSheetAnchor_4( this, - Invocation.getter(#maxExtent), + Invocation.getter(#maxPosition), ), returnValueForMissingStub: _FakeSheetAnchor_4( this, - Invocation.getter(#maxExtent), + Invocation.getter(#maxPosition), ), ) as _i4.SheetAnchor); @@ -458,14 +458,14 @@ class MockSheetPosition extends _i1.Mock implements _i4.SheetPosition { @override void applyNewBoundaryConstraints( _i4.SheetAnchor? minPosition, - _i4.SheetAnchor? maxExtent, + _i4.SheetAnchor? maxPosition, ) => super.noSuchMethod( Invocation.method( #applyNewBoundaryConstraints, [ minPosition, - maxExtent, + maxPosition, ], ), returnValueForMissingStub: null, @@ -636,7 +636,7 @@ class MockSheetPosition extends _i1.Mock implements _i4.SheetPosition { _i4.SheetMetrics copyWith({ double? pixels, _i4.SheetAnchor? minPosition, - _i4.SheetAnchor? maxExtent, + _i4.SheetAnchor? maxPosition, _i6.Size? contentSize, _i6.Size? viewportSize, _i7.EdgeInsets? viewportInsets, @@ -649,7 +649,7 @@ class MockSheetPosition extends _i1.Mock implements _i4.SheetPosition { { #pixels: pixels, #minPosition: minPosition, - #maxExtent: maxExtent, + #maxPosition: maxPosition, #contentSize: contentSize, #viewportSize: viewportSize, #viewportInsets: viewportInsets, @@ -664,7 +664,7 @@ class MockSheetPosition extends _i1.Mock implements _i4.SheetPosition { { #pixels: pixels, #minPosition: minPosition, - #maxExtent: maxExtent, + #maxPosition: maxPosition, #contentSize: contentSize, #viewportSize: viewportSize, #viewportInsets: viewportInsets, @@ -680,7 +680,7 @@ class MockSheetPosition extends _i1.Mock implements _i4.SheetPosition { { #pixels: pixels, #minPosition: minPosition, - #maxExtent: maxExtent, + #maxPosition: maxPosition, #contentSize: contentSize, #viewportSize: viewportSize, #viewportInsets: viewportInsets, From 9140c8f01bf6144f2708f78f3bdef0901605cf87 Mon Sep 17 00:00:00 2001 From: fujidaiti Date: Fri, 27 Sep 2024 21:36:56 +0900 Subject: [PATCH 13/22] Rename ExtentDrivenAnimation to SheetPositionDrivenAnimation --- example/lib/showcase/airbnb_mobile_app.dart | 6 +++--- example/lib/tutorial/extent_driven_animation.dart | 4 ++-- lib/src/foundation/foundation.dart | 2 +- ..._animation.dart => sheet_position_driven_animation.dart} | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) rename lib/src/foundation/{extent_driven_animation.dart => sheet_position_driven_animation.dart} (93%) diff --git a/example/lib/showcase/airbnb_mobile_app.dart b/example/lib/showcase/airbnb_mobile_app.dart index 73a3bcc..1b1a10c 100644 --- a/example/lib/showcase/airbnb_mobile_app.dart +++ b/example/lib/showcase/airbnb_mobile_app.dart @@ -101,7 +101,7 @@ class _MapButton extends StatelessWidget { // by using 'ExtentDrivenAnimation', a special kind of // 'Animation' whose value changes from 0 to 1 as // the sheet extent changes from 'startExtent' to 'endExtent'. - final animation = ExtentDrivenAnimation( + final animation = SheetPositionDrivenAnimation( controller: DefaultSheetController.of(context), // The initial value of the animation is required // since the sheet extent is not available at the first build. @@ -261,7 +261,7 @@ class _HouseList extends StatelessWidget { // Hide the list when the sheet is dragged down. return FadeTransition( - opacity: ExtentDrivenAnimation( + opacity: SheetPositionDrivenAnimation( controller: DefaultSheetController.of(context), initialValue: 1, ).drive( @@ -453,7 +453,7 @@ class _BottomNavigationBar extends StatelessWidget { // Hide the navigation bar when the sheet is dragged down. return SlideTransition( - position: ExtentDrivenAnimation( + position: SheetPositionDrivenAnimation( controller: DefaultSheetController.of(context), initialValue: 1, ).drive( diff --git a/example/lib/tutorial/extent_driven_animation.dart b/example/lib/tutorial/extent_driven_animation.dart index 79e3ae0..7519bf4 100644 --- a/example/lib/tutorial/extent_driven_animation.dart +++ b/example/lib/tutorial/extent_driven_animation.dart @@ -88,7 +88,7 @@ class _BottomAppBar extends StatelessWidget { // by using 'ExtentDrivenAnimation', a special kind of // 'Animation' whose value changes from 0 to 1 as // the sheet extent changes from 'startExtent' to 'endExtent'. - final animation = ExtentDrivenAnimation( + final animation = SheetPositionDrivenAnimation( controller: controller, // The initial value of the animation is required // since the sheet extent is not available at the first build. @@ -134,7 +134,7 @@ class _RotatedFlutterLogo extends StatelessWidget { @override Widget build(BuildContext context) { final logo = RotationTransition( - turns: ExtentDrivenAnimation( + turns: SheetPositionDrivenAnimation( controller: DefaultSheetController.of(context), initialValue: 1, ), diff --git a/lib/src/foundation/foundation.dart b/lib/src/foundation/foundation.dart index c86520a..f59bb80 100644 --- a/lib/src/foundation/foundation.dart +++ b/lib/src/foundation/foundation.dart @@ -1,4 +1,3 @@ -export 'extent_driven_animation.dart' show ExtentDrivenAnimation; export 'keyboard_dismissible.dart' show DragDownSheetKeyboardDismissBehavior, @@ -54,5 +53,6 @@ export 'sheet_position.dart' SheetAnchor, SheetMetrics, SheetMetricsSnapshot; +export 'sheet_position_driven_animation.dart' show SheetPositionDrivenAnimation; export 'sheet_status.dart' show SheetStatus; export 'sheet_theme.dart' show SheetTheme, SheetThemeData; diff --git a/lib/src/foundation/extent_driven_animation.dart b/lib/src/foundation/sheet_position_driven_animation.dart similarity index 93% rename from lib/src/foundation/extent_driven_animation.dart rename to lib/src/foundation/sheet_position_driven_animation.dart index dde104f..c5c63c4 100644 --- a/lib/src/foundation/extent_driven_animation.dart +++ b/lib/src/foundation/sheet_position_driven_animation.dart @@ -3,8 +3,8 @@ import 'package:flutter/animation.dart'; import 'sheet_controller.dart'; import 'sheet_position.dart'; -class ExtentDrivenAnimation extends Animation { - ExtentDrivenAnimation({ +class SheetPositionDrivenAnimation extends Animation { + SheetPositionDrivenAnimation({ required SheetController controller, required this.initialValue, this.startExtent, From 3722d6bf28c600581b1fc7b2575bba889d2e528c Mon Sep 17 00:00:00 2001 From: fujidaiti Date: Fri, 27 Sep 2024 21:47:11 +0900 Subject: [PATCH 14/22] Rename sheet_extent_scope to sheet_position_scope --- .../draggable_sheet_extent_scope.dart | 8 ++-- lib/src/draggable/sheet_draggable.dart | 4 +- .../foundation/sheet_content_scaffold.dart | 24 +++++----- lib/src/foundation/sheet_position.dart | 14 ++++-- ...t_scope.dart => sheet_position_scope.dart} | 44 +++++++++---------- lib/src/foundation/sheet_viewport.dart | 14 ++++-- lib/src/navigation/navigation_route.dart | 40 ++++++++--------- lib/src/navigation/navigation_routes.dart | 18 ++++---- lib/src/navigation/navigation_sheet.dart | 4 +- .../navigation_sheet_extent_scope.dart | 8 ++-- .../navigation/navigation_sheet_viewport.dart | 10 +++-- .../scrollable_sheet_extent_scope.dart | 8 ++-- lib/src/scrollable/sheet_scrollable.dart | 4 +- test/foundation/sheet_viewport_test.dart | 8 ++-- test/scrollable/scrollable_sheet_test.dart | 4 +- 15 files changed, 117 insertions(+), 95 deletions(-) rename lib/src/foundation/{sheet_extent_scope.dart => sheet_position_scope.dart} (81%) diff --git a/lib/src/draggable/draggable_sheet_extent_scope.dart b/lib/src/draggable/draggable_sheet_extent_scope.dart index 3520108..02b4363 100644 --- a/lib/src/draggable/draggable_sheet_extent_scope.dart +++ b/lib/src/draggable/draggable_sheet_extent_scope.dart @@ -1,12 +1,12 @@ import 'package:meta/meta.dart'; import '../foundation/sheet_context.dart'; -import '../foundation/sheet_extent_scope.dart'; import '../foundation/sheet_position.dart'; +import '../foundation/sheet_position_scope.dart'; import 'draggable_sheet_extent.dart'; @internal -class DraggableSheetExtentScope extends SheetExtentScope { +class DraggableSheetExtentScope extends SheetPositionScope { const DraggableSheetExtentScope({ super.key, super.controller, @@ -28,12 +28,12 @@ class DraggableSheetExtentScope extends SheetExtentScope { final String? debugLabel; @override - SheetExtentScopeState createState() { + SheetPositionScopeState createState() { return _DraggableSheetExtentScopeState(); } } -class _DraggableSheetExtentScopeState extends SheetExtentScopeState< +class _DraggableSheetExtentScopeState extends SheetPositionScopeState< DraggableSheetExtent, DraggableSheetExtentScope> { @override bool shouldRebuildExtent(DraggableSheetExtent oldExtent) { diff --git a/lib/src/draggable/sheet_draggable.dart b/lib/src/draggable/sheet_draggable.dart index 6d354db..9dc1a8e 100644 --- a/lib/src/draggable/sheet_draggable.dart +++ b/lib/src/draggable/sheet_draggable.dart @@ -2,8 +2,8 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/widgets.dart'; -import '../foundation/sheet_extent_scope.dart'; import '../foundation/sheet_position.dart'; +import '../foundation/sheet_position_scope.dart'; import '../scrollable/scrollable_sheet.dart'; import 'draggable_sheet.dart'; @@ -47,7 +47,7 @@ class _SheetDraggableState extends State { @override void didChangeDependencies() { super.didChangeDependencies(); - _extent = SheetExtentScope.maybeOf(context); + _extent = SheetPositionScope.maybeOf(context); } @override diff --git a/lib/src/foundation/sheet_content_scaffold.dart b/lib/src/foundation/sheet_content_scaffold.dart index ca69ff8..b48d05d 100644 --- a/lib/src/foundation/sheet_content_scaffold.dart +++ b/lib/src/foundation/sheet_content_scaffold.dart @@ -4,8 +4,8 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import '../draggable/sheet_draggable.dart'; -import 'sheet_extent_scope.dart'; import 'sheet_position.dart'; +import 'sheet_position_scope.dart'; import 'sheet_viewport.dart'; class SheetContentScaffold extends StatelessWidget { @@ -108,8 +108,8 @@ sealed class ResizeScaffoldBehavior { bool maintainBottomBar, }) = _AvoidBottomInset; - // TODO: Implement ResizeScaffoldBehavior.doNotResize - // static const ResizeScaffoldBehavior doNotResize = _DoNotResize(); +// TODO: Implement ResizeScaffoldBehavior.doNotResize +// static const ResizeScaffoldBehavior doNotResize = _DoNotResize(); } // class _DoNotResize extends ResizeScaffoldBehavior { @@ -229,6 +229,7 @@ abstract class _RenderBottomBarVisibility extends RenderTransform { } SheetPosition _extent; + // ignore: avoid_setters_without_getters set extent(SheetPosition value) { if (_extent != value) { @@ -299,7 +300,7 @@ class FixedBottomBarVisibility extends SingleChildRenderObjectWidget @override RenderObject createRenderObject(BuildContext context) { return _RenderFixedBottomBarVisibility( - extent: SheetExtentScope.of(context), + extent: SheetPositionScope.of(context), resizeBehavior: _ResizeScaffoldBehaviorScope.of(context), ); } @@ -308,7 +309,7 @@ class FixedBottomBarVisibility extends SingleChildRenderObjectWidget void updateRenderObject(BuildContext context, RenderObject renderObject) { super.updateRenderObject(context, renderObject); (renderObject as _RenderFixedBottomBarVisibility) - ..extent = SheetExtentScope.of(context) + ..extent = SheetPositionScope.of(context) ..resizeBehavior = _ResizeScaffoldBehaviorScope.of(context); } } @@ -320,6 +321,7 @@ class _RenderFixedBottomBarVisibility extends _RenderBottomBarVisibility { }) : _resizeBehavior = resizeBehavior; ResizeScaffoldBehavior _resizeBehavior; + // ignore: avoid_setters_without_getters set resizeBehavior(ResizeScaffoldBehavior value) { if (_resizeBehavior != value) { @@ -387,7 +389,7 @@ class StickyBottomBarVisibility extends SingleChildRenderObjectWidget @override RenderObject createRenderObject(BuildContext context) { return _RenderStickyBottomBarVisibility( - extent: SheetExtentScope.of(context), + extent: SheetPositionScope.of(context), resizeBehavior: _ResizeScaffoldBehaviorScope.of(context), ); } @@ -396,7 +398,7 @@ class StickyBottomBarVisibility extends SingleChildRenderObjectWidget void updateRenderObject(BuildContext context, RenderObject renderObject) { super.updateRenderObject(context, renderObject); (renderObject as _RenderStickyBottomBarVisibility) - ..extent = SheetExtentScope.of(context) + ..extent = SheetPositionScope.of(context) ..resizeBehavior = _ResizeScaffoldBehaviorScope.of(context); } } @@ -408,6 +410,7 @@ class _RenderStickyBottomBarVisibility extends _RenderBottomBarVisibility { }) : _resizeBehavior = resizeBehavior; ResizeScaffoldBehavior _resizeBehavior; + // ignore: avoid_setters_without_getters set resizeBehavior(ResizeScaffoldBehavior value) { if (_resizeBehavior != value) { @@ -450,7 +453,7 @@ class AnimatedBottomBarVisibility extends SingleChildRenderObjectWidget @override RenderObject createRenderObject(BuildContext context) { return _RenderAnimatedBottomBarVisibility( - extent: SheetExtentScope.of(context), + extent: SheetPositionScope.of(context), visibility: visibility, ); } @@ -459,7 +462,7 @@ class AnimatedBottomBarVisibility extends SingleChildRenderObjectWidget void updateRenderObject(BuildContext context, RenderObject renderObject) { super.updateRenderObject(context, renderObject); (renderObject as _RenderAnimatedBottomBarVisibility) - ..extent = SheetExtentScope.of(context) + ..extent = SheetPositionScope.of(context) ..visibility = visibility; } } @@ -473,6 +476,7 @@ class _RenderAnimatedBottomBarVisibility extends _RenderBottomBarVisibility { } Animation _visibility; + // ignore: avoid_setters_without_getters set visibility(Animation value) { if (_visibility != value) { @@ -582,7 +586,7 @@ class _ConditionalStickyBottomBarVisibilityState @override void didChangeDependencies() { super.didChangeDependencies(); - final extent = SheetExtentScope.of(context); + final extent = SheetPositionScope.of(context); if (_extent != extent) { _extent?.removeListener(_didSheetMetricsChanged); _extent = extent..addListener(_didSheetMetricsChanged); diff --git a/lib/src/foundation/sheet_position.dart b/lib/src/foundation/sheet_position.dart index 0582aa2..011736a 100644 --- a/lib/src/foundation/sheet_position.dart +++ b/lib/src/foundation/sheet_position.dart @@ -10,10 +10,10 @@ import 'sheet_activity.dart'; import 'sheet_context.dart'; import 'sheet_controller.dart'; import 'sheet_drag.dart'; -import 'sheet_extent_scope.dart'; import 'sheet_gesture_tamperer.dart'; import 'sheet_notification.dart'; import 'sheet_physics.dart'; +import 'sheet_position_scope.dart'; import 'sheet_status.dart'; /// An abstract representation of a sheet's position. @@ -130,8 +130,8 @@ class FixedSheetAnchor implements SheetAnchor { /// See also: /// - [SheetController], which can be attached to a sheet to observe and control /// its position. -/// - [SheetExtentScope], which creates a [SheetPosition], manages its lifecycle -/// and exposes it to the descendant widgets. +/// - [SheetPositionScope], which creates a [SheetPosition], manages its +/// lifecycle and exposes it to the descendant widgets. @internal @optionalTypeArgs abstract class SheetPosition extends ChangeNotifier @@ -608,10 +608,15 @@ mixin SheetMetrics { ); double? get maybePixels; + SheetAnchor? get maybeMinPosition; + SheetAnchor? get maybeMaxPosition; + Size? get maybeContentSize; + Size? get maybeViewportSize; + EdgeInsets? get maybeViewportInsets; /// The [FlutterView.devicePixelRatio] of the view that the sheet @@ -694,16 +699,19 @@ mixin SheetMetrics { /// If the on-screen keyboard is visible, this value is the sum of /// [pixels] and the keyboard's height. Otherwise, it is equal to [pixels]. double get viewPixels => pixels + viewportInsets.bottom; + double? get maybeViewPixels => hasDimensions ? viewPixels : null; /// The minimum visible height of the sheet measured from the bottom /// of the viewport. double get minViewPixels => minPixels + viewportInsets.bottom; + double? get maybeMinViewPixels => hasDimensions ? minViewPixels : null; /// The maximum visible height of the sheet measured from the bottom /// of the viewport. double get maxViewPixels => maxPixels + viewportInsets.bottom; + double? get maybeMaxViewPixels => hasDimensions ? maxViewPixels : null; /// Whether the all metrics are available. diff --git a/lib/src/foundation/sheet_extent_scope.dart b/lib/src/foundation/sheet_position_scope.dart similarity index 81% rename from lib/src/foundation/sheet_extent_scope.dart rename to lib/src/foundation/sheet_position_scope.dart index 5d4f077..281ebed 100644 --- a/lib/src/foundation/sheet_extent_scope.dart +++ b/lib/src/foundation/sheet_position_scope.dart @@ -11,9 +11,9 @@ import 'sheet_position.dart'; @internal @optionalTypeArgs -class SheetExtentScopeKey - extends LabeledGlobalKey { - SheetExtentScopeKey({String? debugLabel}) : super(debugLabel); +class SheetPositionScopeKey + extends LabeledGlobalKey { + SheetPositionScopeKey({String? debugLabel}) : super(debugLabel); final List _onCreatedListeners = []; @@ -50,9 +50,9 @@ class SheetExtentScopeKey /// and exposes it to the descendant widgets. @internal @optionalTypeArgs -abstract class SheetExtentScope extends StatefulWidget { +abstract class SheetPositionScope extends StatefulWidget { /// Creates a widget that hosts a [SheetPosition]. - const SheetExtentScope({ + const SheetPositionScope({ super.key, required this.context, this.controller, @@ -89,20 +89,20 @@ abstract class SheetExtentScope extends StatefulWidget { final Widget child; @override - SheetExtentScopeState createState(); + SheetPositionScopeState createState(); - /// Retrieves a [SheetPosition] from the closest [SheetExtentScope] + /// Retrieves a [SheetPosition] from the closest [SheetPositionScope] /// that encloses the given context, if any. // TODO: Add 'useRoot' option. static E? maybeOf(BuildContext context) { final inherited = context - .dependOnInheritedWidgetOfExactType() + .dependOnInheritedWidgetOfExactType() ?.extent; return inherited is E ? inherited : null; } - /// Retrieves a [SheetPosition] from the closest [SheetExtentScope] + /// Retrieves a [SheetPosition] from the closest [SheetPositionScope] /// that encloses the given context. static E of(BuildContext context) { final extent = maybeOf(context); @@ -110,8 +110,8 @@ abstract class SheetExtentScope extends StatefulWidget { assert(() { if (extent == null) { throw FlutterError( - 'No $SheetExtentScope ancestor for $E could be found starting ' - 'from the context that was passed to $SheetExtentScope.of(). ' + 'No $SheetPositionScope ancestor for $E could be found starting ' + 'from the context that was passed to $SheetPositionScope.of(). ' 'The context used was:\n' '$context', ); @@ -124,14 +124,14 @@ abstract class SheetExtentScope extends StatefulWidget { } @internal -abstract class SheetExtentScopeState extends State { +abstract class SheetPositionScopeState extends State { late E _extent; SheetController? _controller; - SheetExtentScopeKey? get _scopeKey { + SheetPositionScopeKey? get _scopeKey { assert(() { - if (widget.key != null && widget.key is! SheetExtentScopeKey) { + if (widget.key != null && widget.key is! SheetPositionScopeKey) { throw FlutterError( 'The key for a SheetExtentScope<$E> must be a ' 'SheetExtentScopeKey<$E>, but got a ${widget.key.runtimeType}.', @@ -141,7 +141,7 @@ abstract class SheetExtentScopeState key => key, + final SheetPositionScopeKey key => key, _ => null, }; } @@ -224,7 +224,7 @@ abstract class SheetExtentScopeState(); + .dependOnInheritedWidgetOfExactType(); if (!widget.isPrimary || parentScope == null || !parentScope.isPrimary) { @@ -232,7 +232,7 @@ abstract class SheetExtentScopeState + bool updateShouldNotify(InheritedSheetPositionScope oldWidget) => extent != oldWidget.extent || isPrimary != oldWidget.isPrimary; } diff --git a/lib/src/foundation/sheet_viewport.dart b/lib/src/foundation/sheet_viewport.dart index 9f14ac8..984cff5 100644 --- a/lib/src/foundation/sheet_viewport.dart +++ b/lib/src/foundation/sheet_viewport.dart @@ -4,8 +4,8 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; import 'package:meta/meta.dart'; -import 'sheet_extent_scope.dart'; import 'sheet_position.dart'; +import 'sheet_position_scope.dart'; @internal class SheetViewport extends SingleChildRenderObjectWidget { @@ -17,7 +17,7 @@ class SheetViewport extends SingleChildRenderObjectWidget { @override RenderObject createRenderObject(BuildContext context) { return RenderSheetViewport( - SheetExtentScope.of(context), + SheetPositionScope.of(context), MediaQuery.viewInsetsOf(context), ); } @@ -25,7 +25,7 @@ class SheetViewport extends SingleChildRenderObjectWidget { @override void updateRenderObject(BuildContext context, RenderObject renderObject) { (renderObject as RenderSheetViewport) - ..extent = SheetExtentScope.of(context) + ..extent = SheetPositionScope.of(context) ..insets = MediaQuery.viewInsetsOf(context); } } @@ -42,9 +42,11 @@ class RenderSheetViewport extends RenderTransform { // Cache the last measured size because we can't access // 'size' property from outside of the layout phase. Size? _lastMeasuredSize; + Size? get lastMeasuredSize => _lastMeasuredSize; SheetPosition _extent; + // ignore: avoid_setters_without_getters set extent(SheetPosition value) { if (_extent != value) { @@ -55,7 +57,9 @@ class RenderSheetViewport extends RenderTransform { } EdgeInsets _insets; + EdgeInsets get insets => _insets; + set insets(EdgeInsets value) { if (value != _insets) { _insets = value; @@ -184,7 +188,7 @@ class _SheetContentViewportState extends State { state: this, child: _SheetContentLayoutObserver( isEnabled: _isEnabled, - extent: SheetExtentScope.maybeOf(context), + extent: SheetPositionScope.maybeOf(context), child: widget.child, ), ); @@ -244,6 +248,7 @@ class _RenderSheetContentLayoutObserver extends RenderPositionedBox { super(alignment: Alignment.topCenter); SheetPosition? _extent; + // ignore: avoid_setters_without_getters set extent(SheetPosition? value) { if (_extent != value) { @@ -253,6 +258,7 @@ class _RenderSheetContentLayoutObserver extends RenderPositionedBox { } ValueGetter _isEnabled; + // ignore: avoid_setters_without_getters set isEnabled(ValueGetter value) { if (_isEnabled != value) { diff --git a/lib/src/navigation/navigation_route.dart b/lib/src/navigation/navigation_route.dart index 735b91e..7465b91 100644 --- a/lib/src/navigation/navigation_route.dart +++ b/lib/src/navigation/navigation_route.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import '../foundation/sheet_context.dart'; -import '../foundation/sheet_extent_scope.dart'; import '../foundation/sheet_position.dart'; +import '../foundation/sheet_position_scope.dart'; import '../foundation/sheet_viewport.dart'; import 'navigation_sheet.dart'; import 'navigation_sheet_extent.dart'; @@ -13,10 +13,10 @@ abstract class NavigationSheetRoute extends PageRoute { NavigationSheetRoute({super.settings}); - SheetExtentScopeKey get scopeKey => _scopeKey; - late final SheetExtentScopeKey _scopeKey; + SheetPositionScopeKey get scopeKey => _scopeKey; + late final SheetPositionScopeKey _scopeKey; - SheetExtentScopeKey createScopeKey(); + SheetPositionScopeKey createScopeKey(); @override void install() { @@ -40,11 +40,11 @@ abstract class NavigationSheetRoute bool _debugAssertDependencies() { assert( () { - final globalExtent = - SheetExtentScope.maybeOf(navigator!.context); + final globalExtent = SheetPositionScope.maybeOf( + navigator!.context); if (globalExtent == null) { throw FlutterError( - 'A $SheetExtentScope that hosts a $NavigationSheetExtent ' + 'A $SheetPositionScope that hosts a $NavigationSheetExtent ' 'is not found in the given context. This is likely because ' 'this $NavigationSheetRoute is not a route of the navigator ' 'enclosed by a $NavigationSheet.', @@ -125,9 +125,9 @@ abstract class NavigationSheetRoute } } -typedef ExtentScopeBuilder = SheetExtentScope Function( +typedef ExtentScopeBuilder = SheetPositionScope Function( SheetContext context, - SheetExtentScopeKey key, + SheetPositionScopeKey key, Widget child, ); @@ -145,7 +145,7 @@ class NavigationSheetRouteContent extends StatelessWidget { Widget build(BuildContext context) { assert(_debugAssertDependencies(context)); final parentRoute = ModalRoute.of(context)! as NavigationSheetRoute; - final globalExtent = SheetExtentScope.of(context); + final globalExtent = SheetPositionScope.of(context); final routeViewport = NavigationSheetRouteViewport( child: SheetContentViewport(child: child), ); @@ -159,27 +159,27 @@ class NavigationSheetRouteContent extends StatelessWidget { } bool _debugAssertScope( - SheetExtentScope scope, + SheetPositionScope scope, Key expectedKey, Widget expectedChild, ) { assert(() { if (scope.key != expectedKey) { throw FlutterError( - 'The key of the $SheetExtentScope returned by `scopeBuilder` does ' + 'The key of the SheetPositionScope returned by `scopeBuilder` does ' 'not match the key passed to the builder. This is likely a mistake.', ); } if (scope.child != expectedChild) { throw FlutterError( - 'The child of the $SheetExtentScope returned by `scopeBuilder` does ' + 'The child of the SheetPositionScope returned by `scopeBuilder` does ' 'not match the child passed to the builder. ' 'This is likely a mistake.', ); } if (scope.controller != null) { throw FlutterError( - 'The $SheetExtentScope returned by the `scopeBuilder` should not ' + 'The SheetPositionScope returned by the `scopeBuilder` should not ' 'have a controller. Since the controller is managed by the global ' ' scope, this is likely a mistake.', ); @@ -193,13 +193,13 @@ class NavigationSheetRouteContent extends StatelessWidget { assert( () { final globalExtent = - SheetExtentScope.maybeOf(context); + SheetPositionScope.maybeOf(context); if (globalExtent == null) { throw FlutterError( - 'A $SheetExtentScope that hosts a $NavigationSheetExtent ' + 'A SheetPositionScope that hosts a $NavigationSheetExtent ' 'is not found in the given context. This is likely because ' - 'this $NavigationSheetRouteContent is not in the subtree of ' - 'the navigator enclosed by a $NavigationSheet.', + 'this NavigationSheetRouteContent is not in the subtree of ' + 'the navigator enclosed by a NavigationSheet.', ); } @@ -208,8 +208,8 @@ class NavigationSheetRouteContent extends StatelessWidget { return true; } throw FlutterError( - 'The $NavigationSheetRouteContent must be the content of ' - 'a $NavigationSheetRoute, but the result of ModalRoute.of(context) ' + 'The NavigationSheetRouteContent must be the content of ' + 'a NavigationSheetRoute, but the result of ModalRoute.of(context) ' 'is ${parentRoute?.runtimeType}.', ); }(), diff --git a/lib/src/navigation/navigation_routes.dart b/lib/src/navigation/navigation_routes.dart index 7430955..4d131dc 100644 --- a/lib/src/navigation/navigation_routes.dart +++ b/lib/src/navigation/navigation_routes.dart @@ -4,10 +4,10 @@ import 'package:flutter/material.dart'; import '../draggable/draggable_sheet_extent.dart'; import '../draggable/draggable_sheet_extent_scope.dart'; import '../draggable/sheet_draggable.dart'; -import '../foundation/sheet_extent_scope.dart'; import '../foundation/sheet_gesture_tamperer.dart'; import '../foundation/sheet_physics.dart'; import '../foundation/sheet_position.dart'; +import '../foundation/sheet_position_scope.dart'; import '../foundation/sheet_theme.dart'; import '../scrollable/scrollable_sheet.dart'; import '../scrollable/scrollable_sheet_extent.dart'; @@ -129,8 +129,8 @@ class ScrollableNavigationSheetRoute final WidgetBuilder builder; @override - SheetExtentScopeKey createScopeKey() { - return SheetExtentScopeKey( + SheetPositionScopeKey createScopeKey() { + return SheetPositionScopeKey( debugLabel: kDebugMode ? '$debugLabel:${describeIdentity(this)}' : null, ); } @@ -183,8 +183,8 @@ class DraggableNavigationSheetRoute final WidgetBuilder builder; @override - SheetExtentScopeKey createScopeKey() { - return SheetExtentScopeKey( + SheetPositionScopeKey createScopeKey() { + return SheetPositionScopeKey( debugLabel: kDebugMode ? '$debugLabel:${describeIdentity(this)}' : null, ); } @@ -263,8 +263,8 @@ class _PageBasedScrollableNavigationSheetRoute RouteTransitionsBuilder? get transitionsBuilder => page.transitionsBuilder; @override - SheetExtentScopeKey createScopeKey() { - return SheetExtentScopeKey( + SheetPositionScopeKey createScopeKey() { + return SheetPositionScopeKey( debugLabel: kDebugMode ? '$debugLabel:${describeIdentity(this)}' : null, ); } @@ -343,8 +343,8 @@ class _PageBasedDraggableNavigationSheetRoute RouteTransitionsBuilder? get transitionsBuilder => page.transitionsBuilder; @override - SheetExtentScopeKey createScopeKey() { - return SheetExtentScopeKey( + SheetPositionScopeKey createScopeKey() { + return SheetPositionScopeKey( debugLabel: kDebugMode ? '$debugLabel:${describeIdentity(this)}' : null, ); } diff --git a/lib/src/navigation/navigation_sheet.dart b/lib/src/navigation/navigation_sheet.dart index 1c77abb..eeff5cb 100644 --- a/lib/src/navigation/navigation_sheet.dart +++ b/lib/src/navigation/navigation_sheet.dart @@ -3,8 +3,8 @@ import 'package:flutter/material.dart'; import '../foundation/sheet_context.dart'; import '../foundation/sheet_controller.dart'; -import '../foundation/sheet_extent_scope.dart'; import '../foundation/sheet_gesture_tamperer.dart'; +import '../foundation/sheet_position_scope.dart'; import '../foundation/sheet_viewport.dart'; import '../internal/transition_observer.dart'; import 'navigation_sheet_extent.dart'; @@ -36,7 +36,7 @@ class _NavigationSheetState extends State TransitionAwareStateMixin, TickerProviderStateMixin, SheetContextStateMixin { - final _scopeKey = SheetExtentScopeKey( + final _scopeKey = SheetPositionScopeKey( debugLabel: kDebugMode ? 'NavigationSheet' : null, ); diff --git a/lib/src/navigation/navigation_sheet_extent_scope.dart b/lib/src/navigation/navigation_sheet_extent_scope.dart index 65fb87a..39a846a 100644 --- a/lib/src/navigation/navigation_sheet_extent_scope.dart +++ b/lib/src/navigation/navigation_sheet_extent_scope.dart @@ -1,13 +1,13 @@ import 'package:meta/meta.dart'; import '../foundation/sheet_context.dart'; -import '../foundation/sheet_extent_scope.dart'; import '../foundation/sheet_physics.dart'; import '../foundation/sheet_position.dart'; +import '../foundation/sheet_position_scope.dart'; import 'navigation_sheet_extent.dart'; @internal -class NavigationSheetExtentScope extends SheetExtentScope { +class NavigationSheetExtentScope extends SheetPositionScope { const NavigationSheetExtentScope({ super.key, super.controller, @@ -27,12 +27,12 @@ class NavigationSheetExtentScope extends SheetExtentScope { final String? debugLabel; @override - SheetExtentScopeState createState() { + SheetPositionScopeState createState() { return _NavigationSheetExtentScopeState(); } } -class _NavigationSheetExtentScopeState extends SheetExtentScopeState< +class _NavigationSheetExtentScopeState extends SheetPositionScopeState< NavigationSheetExtent, NavigationSheetExtentScope> { @override bool shouldRebuildExtent(NavigationSheetExtent oldExtent) { diff --git a/lib/src/navigation/navigation_sheet_viewport.dart b/lib/src/navigation/navigation_sheet_viewport.dart index 506de81..cf479a2 100644 --- a/lib/src/navigation/navigation_sheet_viewport.dart +++ b/lib/src/navigation/navigation_sheet_viewport.dart @@ -2,8 +2,8 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; import 'package:meta/meta.dart'; -import '../foundation/sheet_extent_scope.dart'; import '../foundation/sheet_position.dart'; +import '../foundation/sheet_position_scope.dart'; import '../foundation/sheet_viewport.dart'; @internal @@ -16,7 +16,7 @@ class NavigationSheetViewport extends SheetViewport { @override RenderObject createRenderObject(BuildContext context) { return _RenderNavigationSheetViewport( - SheetExtentScope.of(context), + SheetPositionScope.of(context), MediaQuery.viewInsetsOf(context), ); } @@ -84,7 +84,7 @@ class NavigationSheetRouteViewport extends SingleChildRenderObjectWidget { RenderObject createRenderObject(BuildContext context) { return _RenderNavigationSheetRouteViewport( globalViewport: NavigationSheetViewport._of(context), - localExtent: SheetExtentScope.of(context), + localExtent: SheetPositionScope.of(context), ); } @@ -92,7 +92,7 @@ class NavigationSheetRouteViewport extends SingleChildRenderObjectWidget { void updateRenderObject(BuildContext context, RenderObject renderObject) { (renderObject as _RenderNavigationSheetRouteViewport) ..globalViewport = NavigationSheetViewport._of(context) - ..localExtent = SheetExtentScope.of(context); + ..localExtent = SheetPositionScope.of(context); } } @@ -106,6 +106,7 @@ class _RenderNavigationSheetRouteViewport extends RenderProxyBox { } _RenderNavigationSheetViewport _globalViewport; + // ignore: avoid_setters_without_getters set globalViewport(_RenderNavigationSheetViewport value) { if (_globalViewport != value) { @@ -115,6 +116,7 @@ class _RenderNavigationSheetRouteViewport extends RenderProxyBox { } SheetPosition _localExtent; + // ignore: avoid_setters_without_getters set localExtent(SheetPosition value) { if (_localExtent != value) { diff --git a/lib/src/scrollable/scrollable_sheet_extent_scope.dart b/lib/src/scrollable/scrollable_sheet_extent_scope.dart index ad2084d..ee1caf8 100644 --- a/lib/src/scrollable/scrollable_sheet_extent_scope.dart +++ b/lib/src/scrollable/scrollable_sheet_extent_scope.dart @@ -1,12 +1,12 @@ import 'package:meta/meta.dart'; import '../foundation/sheet_context.dart'; -import '../foundation/sheet_extent_scope.dart'; import '../foundation/sheet_position.dart'; +import '../foundation/sheet_position_scope.dart'; import 'scrollable_sheet_extent.dart'; @internal -class ScrollableSheetExtentScope extends SheetExtentScope { +class ScrollableSheetExtentScope extends SheetPositionScope { const ScrollableSheetExtentScope({ super.key, super.controller, @@ -28,12 +28,12 @@ class ScrollableSheetExtentScope extends SheetExtentScope { final String? debugLabel; @override - SheetExtentScopeState createState() { + SheetPositionScopeState createState() { return _ScrollableSheetExtentScopeState(); } } -class _ScrollableSheetExtentScopeState extends SheetExtentScopeState< +class _ScrollableSheetExtentScopeState extends SheetPositionScopeState< ScrollableSheetExtent, ScrollableSheetExtentScope> { @override bool shouldRebuildExtent(ScrollableSheetExtent oldExtent) { diff --git a/lib/src/scrollable/sheet_scrollable.dart b/lib/src/scrollable/sheet_scrollable.dart index d823c47..af124f1 100644 --- a/lib/src/scrollable/sheet_scrollable.dart +++ b/lib/src/scrollable/sheet_scrollable.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; -import '../foundation/sheet_extent_scope.dart'; +import '../foundation/sheet_position_scope.dart'; import 'scrollable_sheet_extent.dart'; import 'sheet_content_scroll_position.dart'; @@ -36,7 +36,7 @@ class _SheetScrollableState extends State { @override void didChangeDependencies() { super.didChangeDependencies(); - _extent = SheetExtentScope.maybeOf(context); + _extent = SheetPositionScope.maybeOf(context); } @override diff --git a/test/foundation/sheet_viewport_test.dart b/test/foundation/sheet_viewport_test.dart index 1691acf..c651ec7 100644 --- a/test/foundation/sheet_viewport_test.dart +++ b/test/foundation/sheet_viewport_test.dart @@ -2,15 +2,17 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:smooth_sheets/src/foundation/sheet_activity.dart'; import 'package:smooth_sheets/src/foundation/sheet_context.dart'; -import 'package:smooth_sheets/src/foundation/sheet_extent_scope.dart'; import 'package:smooth_sheets/src/foundation/sheet_physics.dart'; import 'package:smooth_sheets/src/foundation/sheet_position.dart'; +import 'package:smooth_sheets/src/foundation/sheet_position_scope.dart'; import 'package:smooth_sheets/src/foundation/sheet_status.dart'; import 'package:smooth_sheets/src/foundation/sheet_viewport.dart'; class _FakeNotificationContext extends Fake implements BuildContext { @override - void dispatchNotification(Notification notification) {/* no-op */} + void dispatchNotification(Notification notification) { + /* no-op */ + } } class _FakeSheetContext extends Fake implements SheetContext { @@ -79,7 +81,7 @@ class _TestWidget extends StatelessWidget { @override Widget build(BuildContext context) { - final sheet = InheritedSheetExtentScope( + final sheet = InheritedSheetPositionScope( isPrimary: true, extent: extent, child: SheetViewport( diff --git a/test/scrollable/scrollable_sheet_test.dart b/test/scrollable/scrollable_sheet_test.dart index 5e734ac..a6b28ea 100644 --- a/test/scrollable/scrollable_sheet_test.dart +++ b/test/scrollable/scrollable_sheet_test.dart @@ -5,7 +5,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:smooth_sheets/smooth_sheets.dart'; import 'package:smooth_sheets/src/foundation/sheet_activity.dart'; import 'package:smooth_sheets/src/foundation/sheet_controller.dart'; -import 'package:smooth_sheets/src/foundation/sheet_extent_scope.dart'; +import 'package:smooth_sheets/src/foundation/sheet_position_scope.dart'; import 'package:smooth_sheets/src/scrollable/scrollable_sheet_extent.dart'; import 'package:smooth_sheets/src/scrollable/sheet_content_scroll_position.dart'; @@ -350,7 +350,7 @@ void main() { child: Builder( builder: (context) { scrollController = PrimaryScrollController.of(context); - sheetExtent = SheetExtentScope.of(context); + sheetExtent = SheetPositionScope.of(context); return SingleChildScrollView( physics: const BouncingScrollPhysics(), child: Container( From f7968a89d780db47171d76f49010afa8ba136ec5 Mon Sep 17 00:00:00 2001 From: fujidaiti Date: Fri, 27 Sep 2024 21:51:50 +0900 Subject: [PATCH 15/22] Rename navigation_sheet_extent_scope to navigation_sheet_position_scope --- lib/src/navigation/navigation_route.dart | 16 +++++++++------- lib/src/navigation/navigation_sheet.dart | 8 ++++---- .../navigation/navigation_sheet_activity.dart | 8 ++++---- ...ent.dart => navigation_sheet_position.dart} | 4 ++-- ...rt => navigation_sheet_position_scope.dart} | 18 +++++++++--------- 5 files changed, 28 insertions(+), 26 deletions(-) rename lib/src/navigation/{navigation_sheet_extent.dart => navigation_sheet_position.dart} (98%) rename lib/src/navigation/{navigation_sheet_extent_scope.dart => navigation_sheet_position_scope.dart} (69%) diff --git a/lib/src/navigation/navigation_route.dart b/lib/src/navigation/navigation_route.dart index 7465b91..b3aa271 100644 --- a/lib/src/navigation/navigation_route.dart +++ b/lib/src/navigation/navigation_route.dart @@ -5,7 +5,7 @@ import '../foundation/sheet_position.dart'; import '../foundation/sheet_position_scope.dart'; import '../foundation/sheet_viewport.dart'; import 'navigation_sheet.dart'; -import 'navigation_sheet_extent.dart'; +import 'navigation_sheet_position.dart'; import 'navigation_sheet_viewport.dart'; @optionalTypeArgs @@ -40,11 +40,12 @@ abstract class NavigationSheetRoute bool _debugAssertDependencies() { assert( () { - final globalExtent = SheetPositionScope.maybeOf( - navigator!.context); + final globalExtent = + SheetPositionScope.maybeOf( + navigator!.context); if (globalExtent == null) { throw FlutterError( - 'A $SheetPositionScope that hosts a $NavigationSheetExtent ' + 'A $SheetPositionScope that hosts a $NavigationSheetPosition ' 'is not found in the given context. This is likely because ' 'this $NavigationSheetRoute is not a route of the navigator ' 'enclosed by a $NavigationSheet.', @@ -145,7 +146,8 @@ class NavigationSheetRouteContent extends StatelessWidget { Widget build(BuildContext context) { assert(_debugAssertDependencies(context)); final parentRoute = ModalRoute.of(context)! as NavigationSheetRoute; - final globalExtent = SheetPositionScope.of(context); + final globalExtent = + SheetPositionScope.of(context); final routeViewport = NavigationSheetRouteViewport( child: SheetContentViewport(child: child), ); @@ -193,10 +195,10 @@ class NavigationSheetRouteContent extends StatelessWidget { assert( () { final globalExtent = - SheetPositionScope.maybeOf(context); + SheetPositionScope.maybeOf(context); if (globalExtent == null) { throw FlutterError( - 'A SheetPositionScope that hosts a $NavigationSheetExtent ' + 'A SheetPositionScope that hosts a $NavigationSheetPosition ' 'is not found in the given context. This is likely because ' 'this NavigationSheetRouteContent is not in the subtree of ' 'the navigator enclosed by a NavigationSheet.', diff --git a/lib/src/navigation/navigation_sheet.dart b/lib/src/navigation/navigation_sheet.dart index eeff5cb..2aa1b14 100644 --- a/lib/src/navigation/navigation_sheet.dart +++ b/lib/src/navigation/navigation_sheet.dart @@ -7,8 +7,8 @@ import '../foundation/sheet_gesture_tamperer.dart'; import '../foundation/sheet_position_scope.dart'; import '../foundation/sheet_viewport.dart'; import '../internal/transition_observer.dart'; -import 'navigation_sheet_extent.dart'; -import 'navigation_sheet_extent_scope.dart'; +import 'navigation_sheet_position.dart'; +import 'navigation_sheet_position_scope.dart'; import 'navigation_sheet_viewport.dart'; typedef NavigationSheetTransitionObserver = TransitionObserver; @@ -36,7 +36,7 @@ class _NavigationSheetState extends State TransitionAwareStateMixin, TickerProviderStateMixin, SheetContextStateMixin { - final _scopeKey = SheetPositionScopeKey( + final _scopeKey = SheetPositionScopeKey( debugLabel: kDebugMode ? 'NavigationSheet' : null, ); @@ -51,7 +51,7 @@ class _NavigationSheetState extends State final controller = widget.controller ?? SheetControllerScope.maybeOf(context); - return NavigationSheetExtentScope( + return NavigationSheetPositionScope( key: _scopeKey, context: this, controller: controller, diff --git a/lib/src/navigation/navigation_sheet_activity.dart b/lib/src/navigation/navigation_sheet_activity.dart index 694b4b8..3dd45ff 100644 --- a/lib/src/navigation/navigation_sheet_activity.dart +++ b/lib/src/navigation/navigation_sheet_activity.dart @@ -6,11 +6,11 @@ import 'package:meta/meta.dart'; import '../foundation/sheet_activity.dart'; import '../foundation/sheet_status.dart'; import 'navigation_route.dart'; -import 'navigation_sheet_extent.dart'; +import 'navigation_sheet_position.dart'; @internal abstract class NavigationSheetActivity - extends SheetActivity {} + extends SheetActivity {} @internal class TransitionSheetActivity extends NavigationSheetActivity { @@ -34,7 +34,7 @@ class TransitionSheetActivity extends NavigationSheetActivity { bool get shouldIgnorePointer => true; @override - void init(NavigationSheetExtent owner) { + void init(NavigationSheetPosition owner) { super.init(owner); _curvedAnimation = animation.drive( CurveTween(curve: animationCurve), @@ -80,7 +80,7 @@ class ProxySheetActivity extends NavigationSheetActivity { route.scopeKey.maybeCurrentExtent?.status ?? SheetStatus.stable; @override - void init(NavigationSheetExtent owner) { + void init(NavigationSheetPosition owner) { super.init(owner); route.scopeKey.addOnCreatedListener(_onLocalExtentCreated); } diff --git a/lib/src/navigation/navigation_sheet_extent.dart b/lib/src/navigation/navigation_sheet_position.dart similarity index 98% rename from lib/src/navigation/navigation_sheet_extent.dart rename to lib/src/navigation/navigation_sheet_position.dart index b05983f..80ccf6f 100644 --- a/lib/src/navigation/navigation_sheet_extent.dart +++ b/lib/src/navigation/navigation_sheet_position.dart @@ -9,8 +9,8 @@ import 'navigation_route.dart'; import 'navigation_sheet_activity.dart'; @internal -class NavigationSheetExtent extends SheetPosition { - NavigationSheetExtent({ +class NavigationSheetPosition extends SheetPosition { + NavigationSheetPosition({ required super.context, required super.minPosition, required super.maxPosition, diff --git a/lib/src/navigation/navigation_sheet_extent_scope.dart b/lib/src/navigation/navigation_sheet_position_scope.dart similarity index 69% rename from lib/src/navigation/navigation_sheet_extent_scope.dart rename to lib/src/navigation/navigation_sheet_position_scope.dart index 39a846a..cb620b1 100644 --- a/lib/src/navigation/navigation_sheet_extent_scope.dart +++ b/lib/src/navigation/navigation_sheet_position_scope.dart @@ -4,11 +4,11 @@ import '../foundation/sheet_context.dart'; import '../foundation/sheet_physics.dart'; import '../foundation/sheet_position.dart'; import '../foundation/sheet_position_scope.dart'; -import 'navigation_sheet_extent.dart'; +import 'navigation_sheet_position.dart'; @internal -class NavigationSheetExtentScope extends SheetPositionScope { - const NavigationSheetExtentScope({ +class NavigationSheetPositionScope extends SheetPositionScope { + const NavigationSheetPositionScope({ super.key, super.controller, super.gestureTamperer, @@ -28,21 +28,21 @@ class NavigationSheetExtentScope extends SheetPositionScope { @override SheetPositionScopeState createState() { - return _NavigationSheetExtentScopeState(); + return _NavigationSheetPositionScopeState(); } } -class _NavigationSheetExtentScopeState extends SheetPositionScopeState< - NavigationSheetExtent, NavigationSheetExtentScope> { +class _NavigationSheetPositionScopeState extends SheetPositionScopeState< + NavigationSheetPosition, NavigationSheetPositionScope> { @override - bool shouldRebuildExtent(NavigationSheetExtent oldExtent) { + bool shouldRebuildExtent(NavigationSheetPosition oldExtent) { return widget.debugLabel != oldExtent.debugLabel || super.shouldRebuildExtent(oldExtent); } @override - NavigationSheetExtent buildExtent(SheetContext context) { - return NavigationSheetExtent( + NavigationSheetPosition buildExtent(SheetContext context) { + return NavigationSheetPosition( context: context, minPosition: widget.minPosition, maxPosition: widget.maxPosition, From 2c6ee7403924c2dfe80bc579804e0d4b009ab452 Mon Sep 17 00:00:00 2001 From: fujidaiti Date: Fri, 27 Sep 2024 21:57:15 +0900 Subject: [PATCH 16/22] Rename scrollable_sheet_extent to scrollable_sheet_position --- lib/src/navigation/navigation_routes.dart | 2 +- lib/src/scrollable/scrollable_sheet_activity.dart | 3 ++- lib/src/scrollable/scrollable_sheet_extent_scope.dart | 2 +- ...llable_sheet_extent.dart => scrollable_sheet_position.dart} | 0 lib/src/scrollable/sheet_scrollable.dart | 2 +- test/scrollable/scrollable_sheet_test.dart | 2 +- 6 files changed, 6 insertions(+), 5 deletions(-) rename lib/src/scrollable/{scrollable_sheet_extent.dart => scrollable_sheet_position.dart} (100%) diff --git a/lib/src/navigation/navigation_routes.dart b/lib/src/navigation/navigation_routes.dart index 4d131dc..1e15d24 100644 --- a/lib/src/navigation/navigation_routes.dart +++ b/lib/src/navigation/navigation_routes.dart @@ -10,8 +10,8 @@ import '../foundation/sheet_position.dart'; import '../foundation/sheet_position_scope.dart'; import '../foundation/sheet_theme.dart'; import '../scrollable/scrollable_sheet.dart'; -import '../scrollable/scrollable_sheet_extent.dart'; import '../scrollable/scrollable_sheet_extent_scope.dart'; +import '../scrollable/scrollable_sheet_position.dart'; import 'navigation_route.dart'; class _ScrollableNavigationSheetRouteContent extends StatelessWidget { diff --git a/lib/src/scrollable/scrollable_sheet_activity.dart b/lib/src/scrollable/scrollable_sheet_activity.dart index 64b0eb0..51eb791 100644 --- a/lib/src/scrollable/scrollable_sheet_activity.dart +++ b/lib/src/scrollable/scrollable_sheet_activity.dart @@ -10,7 +10,7 @@ import '../foundation/sheet_drag.dart'; import '../foundation/sheet_status.dart'; import '../internal/float_comp.dart'; import 'scrollable_sheet.dart'; -import 'scrollable_sheet_extent.dart'; +import 'scrollable_sheet_position.dart'; import 'sheet_content_scroll_activity.dart'; import 'sheet_content_scroll_position.dart'; @@ -33,6 +33,7 @@ abstract class ScrollableSheetActivity : _scrollPosition = scrollPosition; SheetContentScrollPosition? _scrollPosition; + SheetContentScrollPosition get scrollPosition { assert(debugAssertNotDisposed()); return _scrollPosition!; diff --git a/lib/src/scrollable/scrollable_sheet_extent_scope.dart b/lib/src/scrollable/scrollable_sheet_extent_scope.dart index ee1caf8..9619419 100644 --- a/lib/src/scrollable/scrollable_sheet_extent_scope.dart +++ b/lib/src/scrollable/scrollable_sheet_extent_scope.dart @@ -3,7 +3,7 @@ import 'package:meta/meta.dart'; import '../foundation/sheet_context.dart'; import '../foundation/sheet_position.dart'; import '../foundation/sheet_position_scope.dart'; -import 'scrollable_sheet_extent.dart'; +import 'scrollable_sheet_position.dart'; @internal class ScrollableSheetExtentScope extends SheetPositionScope { diff --git a/lib/src/scrollable/scrollable_sheet_extent.dart b/lib/src/scrollable/scrollable_sheet_position.dart similarity index 100% rename from lib/src/scrollable/scrollable_sheet_extent.dart rename to lib/src/scrollable/scrollable_sheet_position.dart diff --git a/lib/src/scrollable/sheet_scrollable.dart b/lib/src/scrollable/sheet_scrollable.dart index af124f1..39e301d 100644 --- a/lib/src/scrollable/sheet_scrollable.dart +++ b/lib/src/scrollable/sheet_scrollable.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import '../foundation/sheet_position_scope.dart'; -import 'scrollable_sheet_extent.dart'; +import 'scrollable_sheet_position.dart'; import 'sheet_content_scroll_position.dart'; class SheetScrollable extends StatefulWidget { diff --git a/test/scrollable/scrollable_sheet_test.dart b/test/scrollable/scrollable_sheet_test.dart index a6b28ea..b91aa51 100644 --- a/test/scrollable/scrollable_sheet_test.dart +++ b/test/scrollable/scrollable_sheet_test.dart @@ -6,7 +6,7 @@ import 'package:smooth_sheets/smooth_sheets.dart'; import 'package:smooth_sheets/src/foundation/sheet_activity.dart'; import 'package:smooth_sheets/src/foundation/sheet_controller.dart'; import 'package:smooth_sheets/src/foundation/sheet_position_scope.dart'; -import 'package:smooth_sheets/src/scrollable/scrollable_sheet_extent.dart'; +import 'package:smooth_sheets/src/scrollable/scrollable_sheet_position.dart'; import 'package:smooth_sheets/src/scrollable/sheet_content_scroll_position.dart'; import '../src/keyboard_inset_simulation.dart'; From 684f35f29e264f8befd4cbca1daef3311621059a Mon Sep 17 00:00:00 2001 From: fujidaiti Date: Fri, 27 Sep 2024 21:58:43 +0900 Subject: [PATCH 17/22] Rename scrollable_sheet_extent_scope --- lib/src/navigation/navigation_routes.dart | 2 +- lib/src/scrollable/scrollable_sheet.dart | 2 +- ...t_extent_scope.dart => scrollable_sheet_position_scope.dart} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename lib/src/scrollable/{scrollable_sheet_extent_scope.dart => scrollable_sheet_position_scope.dart} (100%) diff --git a/lib/src/navigation/navigation_routes.dart b/lib/src/navigation/navigation_routes.dart index 1e15d24..3a5b080 100644 --- a/lib/src/navigation/navigation_routes.dart +++ b/lib/src/navigation/navigation_routes.dart @@ -10,8 +10,8 @@ import '../foundation/sheet_position.dart'; import '../foundation/sheet_position_scope.dart'; import '../foundation/sheet_theme.dart'; import '../scrollable/scrollable_sheet.dart'; -import '../scrollable/scrollable_sheet_extent_scope.dart'; import '../scrollable/scrollable_sheet_position.dart'; +import '../scrollable/scrollable_sheet_position_scope.dart'; import 'navigation_route.dart'; class _ScrollableNavigationSheetRouteContent extends StatelessWidget { diff --git a/lib/src/scrollable/scrollable_sheet.dart b/lib/src/scrollable/scrollable_sheet.dart index f949611..faf47b5 100644 --- a/lib/src/scrollable/scrollable_sheet.dart +++ b/lib/src/scrollable/scrollable_sheet.dart @@ -10,7 +10,7 @@ import '../foundation/sheet_physics.dart'; import '../foundation/sheet_position.dart'; import '../foundation/sheet_theme.dart'; import '../foundation/sheet_viewport.dart'; -import 'scrollable_sheet_extent_scope.dart'; +import 'scrollable_sheet_position_scope.dart'; import 'sheet_scrollable.dart'; class ScrollableSheet extends StatefulWidget { diff --git a/lib/src/scrollable/scrollable_sheet_extent_scope.dart b/lib/src/scrollable/scrollable_sheet_position_scope.dart similarity index 100% rename from lib/src/scrollable/scrollable_sheet_extent_scope.dart rename to lib/src/scrollable/scrollable_sheet_position_scope.dart From 578bf90bac5e2f01d472d16684e9650d161a151a Mon Sep 17 00:00:00 2001 From: fujidaiti Date: Fri, 27 Sep 2024 21:59:13 +0900 Subject: [PATCH 18/22] Rename draggable_sheet_extent_scope --- lib/src/draggable/draggable_sheet.dart | 2 +- ...et_extent_scope.dart => draggable_sheet_position_scope.dart} | 0 lib/src/navigation/navigation_routes.dart | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename lib/src/draggable/{draggable_sheet_extent_scope.dart => draggable_sheet_position_scope.dart} (100%) diff --git a/lib/src/draggable/draggable_sheet.dart b/lib/src/draggable/draggable_sheet.dart index 37b480b..15de8a0 100644 --- a/lib/src/draggable/draggable_sheet.dart +++ b/lib/src/draggable/draggable_sheet.dart @@ -9,7 +9,7 @@ import '../foundation/sheet_position.dart'; import '../foundation/sheet_theme.dart'; import '../foundation/sheet_viewport.dart'; import '../scrollable/scrollable_sheet.dart'; -import 'draggable_sheet_extent_scope.dart'; +import 'draggable_sheet_position_scope.dart'; import 'sheet_draggable.dart'; /// A sheet that can be dragged. diff --git a/lib/src/draggable/draggable_sheet_extent_scope.dart b/lib/src/draggable/draggable_sheet_position_scope.dart similarity index 100% rename from lib/src/draggable/draggable_sheet_extent_scope.dart rename to lib/src/draggable/draggable_sheet_position_scope.dart diff --git a/lib/src/navigation/navigation_routes.dart b/lib/src/navigation/navigation_routes.dart index 3a5b080..2200c63 100644 --- a/lib/src/navigation/navigation_routes.dart +++ b/lib/src/navigation/navigation_routes.dart @@ -2,7 +2,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import '../draggable/draggable_sheet_extent.dart'; -import '../draggable/draggable_sheet_extent_scope.dart'; +import '../draggable/draggable_sheet_position_scope.dart'; import '../draggable/sheet_draggable.dart'; import '../foundation/sheet_gesture_tamperer.dart'; import '../foundation/sheet_physics.dart'; From 80814daa080f6bcdb629149a586477bdbdc2ed48 Mon Sep 17 00:00:00 2001 From: fujidaiti Date: Fri, 27 Sep 2024 21:59:46 +0900 Subject: [PATCH 19/22] Rename draggable_sheet_extent --- ...raggable_sheet_extent.dart => draggable_sheet_position.dart} | 0 lib/src/draggable/draggable_sheet_position_scope.dart | 2 +- lib/src/navigation/navigation_routes.dart | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename lib/src/draggable/{draggable_sheet_extent.dart => draggable_sheet_position.dart} (100%) diff --git a/lib/src/draggable/draggable_sheet_extent.dart b/lib/src/draggable/draggable_sheet_position.dart similarity index 100% rename from lib/src/draggable/draggable_sheet_extent.dart rename to lib/src/draggable/draggable_sheet_position.dart diff --git a/lib/src/draggable/draggable_sheet_position_scope.dart b/lib/src/draggable/draggable_sheet_position_scope.dart index 02b4363..01a2af6 100644 --- a/lib/src/draggable/draggable_sheet_position_scope.dart +++ b/lib/src/draggable/draggable_sheet_position_scope.dart @@ -3,7 +3,7 @@ import 'package:meta/meta.dart'; import '../foundation/sheet_context.dart'; import '../foundation/sheet_position.dart'; import '../foundation/sheet_position_scope.dart'; -import 'draggable_sheet_extent.dart'; +import 'draggable_sheet_position.dart'; @internal class DraggableSheetExtentScope extends SheetPositionScope { diff --git a/lib/src/navigation/navigation_routes.dart b/lib/src/navigation/navigation_routes.dart index 2200c63..a5932c0 100644 --- a/lib/src/navigation/navigation_routes.dart +++ b/lib/src/navigation/navigation_routes.dart @@ -1,7 +1,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import '../draggable/draggable_sheet_extent.dart'; +import '../draggable/draggable_sheet_position.dart'; import '../draggable/draggable_sheet_position_scope.dart'; import '../draggable/sheet_draggable.dart'; import '../foundation/sheet_gesture_tamperer.dart'; From f59bb0f3b0387385361a62c78483769ec9b7eb60 Mon Sep 17 00:00:00 2001 From: fujidaiti Date: Fri, 27 Sep 2024 22:14:17 +0900 Subject: [PATCH 20/22] Replace all "extent"s with "position"s --- .../lib/showcase/ai_playlist_generator.dart | 2 +- example/lib/showcase/airbnb_mobile_app.dart | 24 ++-- example/lib/showcase/safari/menu.dart | 6 +- .../lib/tutorial/bottom_bar_visibility.dart | 2 +- .../lib/tutorial/cupertino_modal_sheet.dart | 4 +- .../declarative_navigation_sheet.dart | 2 +- .../lib/tutorial/extent_driven_animation.dart | 24 ++-- .../tutorial/imperative_navigation_sheet.dart | 2 +- example/lib/tutorial/sheet_controller.dart | 6 +- example/lib/tutorial/sheet_draggable.dart | 2 +- example/lib/tutorial/sheet_physics.dart | 16 ++- .../textfield_with_multiple_stops.dart | 2 +- lib/src/draggable/draggable_sheet.dart | 14 +- .../draggable/draggable_sheet_position.dart | 14 +- .../draggable_sheet_position_scope.dart | 32 ++--- lib/src/draggable/sheet_draggable.dart | 8 +- lib/src/foundation/sheet_activity.dart | 13 +- .../foundation/sheet_content_scaffold.dart | 59 ++++----- lib/src/foundation/sheet_controller.dart | 14 +- lib/src/foundation/sheet_notification.dart | 12 +- lib/src/foundation/sheet_physics.dart | 87 +++++++------ lib/src/foundation/sheet_position.dart | 8 +- .../sheet_position_driven_animation.dart | 12 +- lib/src/foundation/sheet_position_scope.dart | 99 +++++++------- lib/src/foundation/sheet_viewport.dart | 68 +++++----- lib/src/navigation/navigation.dart | 5 +- lib/src/navigation/navigation_route.dart | 16 +-- lib/src/navigation/navigation_routes.dart | 64 ++++----- lib/src/navigation/navigation_sheet.dart | 2 +- .../navigation/navigation_sheet_activity.dart | 28 ++-- .../navigation/navigation_sheet_position.dart | 18 +-- .../navigation_sheet_position_scope.dart | 10 +- .../navigation/navigation_sheet_viewport.dart | 26 ++-- lib/src/scrollable/scrollable_sheet.dart | 14 +- .../scrollable/scrollable_sheet_activity.dart | 35 ++--- .../scrollable/scrollable_sheet_position.dart | 18 +-- .../scrollable_sheet_position_scope.dart | 32 ++--- lib/src/scrollable/sheet_scrollable.dart | 8 +- test/draggable/draggable_sheet_test.dart | 6 +- test/foundation/physics_test.dart | 122 +++++++++--------- test/foundation/sheet_activity_test.dart | 18 +-- test/foundation/sheet_viewport_test.dart | 18 +-- test/navigation/navigation_sheet_test.dart | 14 +- test/scrollable/scrollable_sheet_test.dart | 18 +-- test/src/stubbing.dart | 47 +++---- test/src/stubbing.mocks.dart | 4 +- 46 files changed, 537 insertions(+), 518 deletions(-) diff --git a/example/lib/showcase/ai_playlist_generator.dart b/example/lib/showcase/ai_playlist_generator.dart index 8f2cb14..b4f3aac 100644 --- a/example/lib/showcase/ai_playlist_generator.dart +++ b/example/lib/showcase/ai_playlist_generator.dart @@ -104,7 +104,7 @@ final _confirmRoute = GoRoute( path: 'confirm', pageBuilder: (context, state) { return const ScrollableNavigationSheetPage( - initialExtent: SheetAnchor.proportional(0.7), + initialPosition: SheetAnchor.proportional(0.7), minPosition: SheetAnchor.proportional(0.7), physics: BouncingSheetPhysics( parent: SnappingSheetPhysics(), diff --git a/example/lib/showcase/airbnb_mobile_app.dart b/example/lib/showcase/airbnb_mobile_app.dart index 1b1a10c..3543204 100644 --- a/example/lib/showcase/airbnb_mobile_app.dart +++ b/example/lib/showcase/airbnb_mobile_app.dart @@ -60,7 +60,7 @@ class _Home extends StatelessWidget { return DefaultTabController( length: _AppBar.tabs.length, // Provides a SheetController to the descendant widgets - // to perform some sheet extent driven animations. + // to perform some sheet position driven animations. // The sheet will look up and use this controller unless // another one is manually specified in the constructor. // The descendant widgets can also get this controller by @@ -97,19 +97,19 @@ class _MapButton extends StatelessWidget { icon: const Icon(Icons.map), ); - // It is easy to create sheet extent driven animations - // by using 'ExtentDrivenAnimation', a special kind of + // It is easy to create sheet position driven animations + // by using 'PositionDrivenAnimation', a special kind of // 'Animation' whose value changes from 0 to 1 as - // the sheet extent changes from 'startExtent' to 'endExtent'. + // the sheet position changes from 'startPosition' to 'endPosition'. final animation = SheetPositionDrivenAnimation( controller: DefaultSheetController.of(context), // The initial value of the animation is required - // since the sheet extent is not available at the first build. + // since the sheet position is not available at the first build. initialValue: 1, - // If null, the minimum extent will be used. (Default) - startExtent: null, - // If null, the maximum extent will be used. (Default) - endExtent: null, + // If null, the minimum position will be used. (Default) + startPosition: null, + // If null, the maximum position will be used. (Default) + endPosition: null, ).drive(CurveTween(curve: Curves.easeInExpo)); // Hide the button when the sheet is dragged down. @@ -155,7 +155,7 @@ class _ContentSheet extends StatelessWidget { final appbarHeight = MediaQuery.of(context).padding.top; final handleHeight = const _ContentSheetHandle().preferredSize.height; final sheetHeight = parentHeight - appbarHeight + handleHeight; - final minSheetExtent = + final minSheetPosition = SheetAnchor.pixels(handleHeight + systemUiInsets.bottom); const sheetShape = RoundedRectangleBorder( @@ -168,7 +168,7 @@ class _ContentSheet extends StatelessWidget { parent: SnappingSheetPhysics( snappingBehavior: SnapToNearest( snapTo: [ - minSheetExtent, + minSheetPosition, const SheetAnchor.proportional(1), ], ), @@ -177,7 +177,7 @@ class _ContentSheet extends StatelessWidget { return ScrollableSheet( physics: sheetPhysics, - minPosition: minSheetExtent, + minPosition: minSheetPosition, child: SizedBox( height: sheetHeight, child: const Card( diff --git a/example/lib/showcase/safari/menu.dart b/example/lib/showcase/safari/menu.dart index 1a81d31..fc6f085 100644 --- a/example/lib/showcase/safari/menu.dart +++ b/example/lib/showcase/safari/menu.dart @@ -22,10 +22,10 @@ class MenuSheet extends StatelessWidget { @override Widget build(BuildContext context) { - const halfWayExtent = SheetAnchor.proportional(0.5); + const halfWayPosition = SheetAnchor.proportional(0.5); return ScrollableSheet( - initialExtent: halfWayExtent, - minPosition: halfWayExtent, + initialPosition: halfWayPosition, + minPosition: halfWayPosition, physics: const BouncingSheetPhysics( parent: SnappingSheetPhysics(), ), diff --git a/example/lib/tutorial/bottom_bar_visibility.dart b/example/lib/tutorial/bottom_bar_visibility.dart index 3b978fa..f4e3bb7 100644 --- a/example/lib/tutorial/bottom_bar_visibility.dart +++ b/example/lib/tutorial/bottom_bar_visibility.dart @@ -149,7 +149,7 @@ class _ExampleSheet extends StatelessWidget { bottom: false, child: DraggableSheet( minPosition: minSize, - initialExtent: halfSize, + initialPosition: halfSize, physics: multiStopPhysics, child: SheetContentScaffold( appBar: AppBar(), diff --git a/example/lib/tutorial/cupertino_modal_sheet.dart b/example/lib/tutorial/cupertino_modal_sheet.dart index 97e6b79..ac6f315 100644 --- a/example/lib/tutorial/cupertino_modal_sheet.dart +++ b/example/lib/tutorial/cupertino_modal_sheet.dart @@ -70,9 +70,9 @@ class _HalfScreenSheet extends StatelessWidget { @override Widget build(BuildContext context) { // `CupertinoStackedTransition` won't start the transition animation until - // the visible height of a modal sheet (the extent) exceeds 50% of the screen height. + // the visible height of a modal sheet (the position) exceeds 50% of the screen height. return const DraggableSheet( - initialExtent: SheetAnchor.proportional(0.5), + initialPosition: SheetAnchor.proportional(0.5), minPosition: SheetAnchor.proportional(0.5), physics: BouncingSheetPhysics( parent: SnappingSheetPhysics(), diff --git a/example/lib/tutorial/declarative_navigation_sheet.dart b/example/lib/tutorial/declarative_navigation_sheet.dart index 08ed157..3b3e002 100644 --- a/example/lib/tutorial/declarative_navigation_sheet.dart +++ b/example/lib/tutorial/declarative_navigation_sheet.dart @@ -13,7 +13,7 @@ void main() { } // NavigationSheet requires a special NavigatorObserver in order to -// smoothly change its extent during a route transition. +// smoothly change its position during a route transition. final transitionObserver = NavigationSheetTransitionObserver(); // To use declarative navigation, we utilize the 'go_router' package. diff --git a/example/lib/tutorial/extent_driven_animation.dart b/example/lib/tutorial/extent_driven_animation.dart index 7519bf4..cac4d35 100644 --- a/example/lib/tutorial/extent_driven_animation.dart +++ b/example/lib/tutorial/extent_driven_animation.dart @@ -2,11 +2,11 @@ import 'package:flutter/material.dart'; import 'package:smooth_sheets/smooth_sheets.dart'; void main() { - runApp(const _ExtentDrivenAnimationExample()); + runApp(const _PositionDrivenAnimationExample()); } -class _ExtentDrivenAnimationExample extends StatelessWidget { - const _ExtentDrivenAnimationExample(); +class _PositionDrivenAnimationExample extends StatelessWidget { + const _PositionDrivenAnimationExample(); @override Widget build(BuildContext context) { @@ -20,7 +20,7 @@ class _ExampleScaffold extends StatelessWidget { @override Widget build(BuildContext context) { // Provides a SheetController to the descendant widgets - // to perform some sheet extent driven animations. + // to perform some sheet position driven animations. // The sheet will look up and use this controller unless // another one is manually specified in the constructor. // The descendant widgets can also get this controller by @@ -84,19 +84,19 @@ class _BottomAppBar extends StatelessWidget { // Lookup the nearest controller. final controller = DefaultSheetController.of(context); - // It is easy to create sheet extent driven animations - // by using 'ExtentDrivenAnimation', a special kind of + // It is easy to create sheet position driven animations + // by using 'PositionDrivenAnimation', a special kind of // 'Animation' whose value changes from 0 to 1 as - // the sheet extent changes from 'startExtent' to 'endExtent'. + // the sheet position changes from 'startPosition' to 'endPosition'. final animation = SheetPositionDrivenAnimation( controller: controller, // The initial value of the animation is required - // since the sheet extent is not available at the first build. + // since the sheet position is not available at the first build. initialValue: 1, - // If null, the minimum extent will be used. (Default) - startExtent: null, - // If null, the maximum extent will be used. (Default) - endExtent: null, + // If null, the minimum position will be used. (Default) + startPosition: null, + // If null, the maximum position will be used. (Default) + endPosition: null, ); final bottomAppBar = BottomAppBar( diff --git a/example/lib/tutorial/imperative_navigation_sheet.dart b/example/lib/tutorial/imperative_navigation_sheet.dart index df9a733..c2cfb5d 100644 --- a/example/lib/tutorial/imperative_navigation_sheet.dart +++ b/example/lib/tutorial/imperative_navigation_sheet.dart @@ -22,7 +22,7 @@ class _ImperativeNavigationSheetExample extends StatelessWidget { } // NavigationSheet requires a special NavigatorObserver in order to -// smoothly change its extent during a route transition. +// smoothly change its position during a route transition. final _transitionObserver = NavigationSheetTransitionObserver(); class _ExampleSheet extends StatelessWidget { diff --git a/example/lib/tutorial/sheet_controller.dart b/example/lib/tutorial/sheet_controller.dart index 0a7d562..3840bec 100644 --- a/example/lib/tutorial/sheet_controller.dart +++ b/example/lib/tutorial/sheet_controller.dart @@ -47,12 +47,12 @@ class _ExampleHomeState extends State<_ExampleHome> { child: Align( alignment: Alignment.topCenter, // Like ScrollController for scrollable widgets, - // SheetController can be used to observe changes in the sheet extent. + // SheetController can be used to observe changes in the sheet position. child: ValueListenableBuilder( valueListenable: controller, builder: (context, pixels, child) { return Text( - 'Extent: ${pixels?.toStringAsFixed(1)}', + 'Position: ${pixels?.toStringAsFixed(1)}', style: Theme.of(context).textTheme.displaySmall, ); }, @@ -69,7 +69,7 @@ class _ExampleHomeState extends State<_ExampleHome> { foregroundColor: Theme.of(context).colorScheme.onPrimary, child: const Icon(Icons.arrow_downward_rounded), onPressed: () { - // SheetController can also be used to animate the sheet extent. + // SheetController can also be used to animate the sheet position. controller.animateTo(const SheetAnchor.proportional(0.5)); }, ), diff --git a/example/lib/tutorial/sheet_draggable.dart b/example/lib/tutorial/sheet_draggable.dart index ab29a4c..d061d96 100644 --- a/example/lib/tutorial/sheet_draggable.dart +++ b/example/lib/tutorial/sheet_draggable.dart @@ -75,7 +75,7 @@ class _ExampleSheet extends StatelessWidget { child: ScrollableSheet( physics: physics, minPosition: minPosition, - initialExtent: minPosition, + initialPosition: minPosition, child: Card( margin: EdgeInsets.zero, color: Theme.of(context).colorScheme.secondaryContainer, diff --git a/example/lib/tutorial/sheet_physics.dart b/example/lib/tutorial/sheet_physics.dart index 4285a7e..f99284b 100644 --- a/example/lib/tutorial/sheet_physics.dart +++ b/example/lib/tutorial/sheet_physics.dart @@ -84,9 +84,9 @@ class _MySheet extends StatelessWidget { SheetPhysics createPhysics(_PhysicsKind kind) { // With this configuration, the sheet will snap to: - // - the extent at which ony (_halfwayFraction * 100)% of the content is visible, or - // - the extent at which the entire content is visible. - // Note that the "extent" is the visible height of the sheet. + // - the position at which ony (_halfwayFraction * 100)% of the content is visible, or + // - the position at which the entire content is visible. + // Note that the "position" is the visible height of the sheet. const snappingPhysics = SnappingSheetPhysics( snappingBehavior: SnapToNearest( snapTo: [ @@ -114,16 +114,18 @@ class _MySheet extends StatelessWidget { Widget build(BuildContext context) { return DraggableSheet( // The 'minPosition' and 'maxPosition' properties determine - // how far the sheet can be dragged. Note that "extent" + // how far the sheet can be dragged. Note that "position" // refers to the visible height of the sheet. For example, // the configuration below ensures that the sheet is fully visible // at first and can then be dragged down to (_halfwayFraction * 100)% // of the sheet height at minimum. minPosition: const SheetAnchor.proportional(_halfwayFraction), - maxPosition: const SheetAnchor.proportional(1), // Default - initialExtent: const SheetAnchor.proportional(1), // Default + maxPosition: const SheetAnchor.proportional(1), + // Default + initialPosition: const SheetAnchor.proportional(1), + // Default // 'physics' determines how the sheet will behave when the user reaches - // the maximum or minimum extent, or when the user stops dragging. + // the maximum or minimum position, or when the user stops dragging. physics: createPhysics(physicsKind), child: buildContent(context), ); diff --git a/example/lib/tutorial/textfield_with_multiple_stops.dart b/example/lib/tutorial/textfield_with_multiple_stops.dart index 243c902..762a1e0 100644 --- a/example/lib/tutorial/textfield_with_multiple_stops.dart +++ b/example/lib/tutorial/textfield_with_multiple_stops.dart @@ -15,7 +15,7 @@ class TextFieldWithMultipleStops extends StatelessWidget { children: [ const Scaffold(), ScrollableSheet( - initialExtent: const SheetAnchor.proportional(0.7), + initialPosition: const SheetAnchor.proportional(0.7), minPosition: const SheetAnchor.proportional(0.4), physics: const BouncingSheetPhysics( parent: SnappingSheetPhysics( diff --git a/lib/src/draggable/draggable_sheet.dart b/lib/src/draggable/draggable_sheet.dart index 15de8a0..f10de15 100644 --- a/lib/src/draggable/draggable_sheet.dart +++ b/lib/src/draggable/draggable_sheet.dart @@ -32,7 +32,7 @@ class DraggableSheet extends StatefulWidget { const DraggableSheet({ super.key, this.hitTestBehavior = HitTestBehavior.translucent, - this.initialExtent = const SheetAnchor.proportional(1), + this.initialPosition = const SheetAnchor.proportional(1), this.minPosition = const SheetAnchor.proportional(1), this.maxPosition = const SheetAnchor.proportional(1), this.physics, @@ -40,15 +40,15 @@ class DraggableSheet extends StatefulWidget { this.controller, }); - final SheetAnchor initialExtent; + final SheetAnchor initialPosition; - /// {@macro SheetExtentConfig.minPosition} + /// {@macro SheetPositionConfig.minPosition} final SheetAnchor minPosition; - /// {@macro SheetExtentConfig.maxPosition} + /// {@macro SheetPositionConfig.maxPosition} final SheetAnchor maxPosition; - /// {@macro SheetExtentConfig.physics} + /// {@macro SheetPositionConfig.physics} final SheetPhysics? physics; /// An object that can be used to control and observe the sheet height. @@ -76,10 +76,10 @@ class _DraggableSheetState extends State final controller = widget.controller ?? SheetControllerScope.maybeOf(context); - return DraggableSheetExtentScope( + return DraggableSheetPositionScope( context: this, controller: controller, - initialExtent: widget.initialExtent, + initialPosition: widget.initialPosition, minPosition: widget.minPosition, maxPosition: widget.maxPosition, physics: physics, diff --git a/lib/src/draggable/draggable_sheet_position.dart b/lib/src/draggable/draggable_sheet_position.dart index 2a232a9..41439db 100644 --- a/lib/src/draggable/draggable_sheet_position.dart +++ b/lib/src/draggable/draggable_sheet_position.dart @@ -5,27 +5,27 @@ import 'package:meta/meta.dart'; import '../foundation/sheet_position.dart'; @internal -class DraggableSheetExtent extends SheetPosition { - DraggableSheetExtent({ +class DraggableSheetPosition extends SheetPosition { + DraggableSheetPosition({ required super.context, required super.minPosition, required super.maxPosition, - required this.initialExtent, + required this.initialPosition, required super.physics, super.gestureTamperer, super.debugLabel, }); - /// {@template DraggableSheetExtent.initialExtent} - /// The initial extent of the sheet. + /// {@template DraggableSheetPosition.initialPosition} + /// The initial position of the sheet. /// {@endtemplate} - final SheetAnchor initialExtent; + final SheetAnchor initialPosition; @override void applyNewContentSize(Size contentSize) { super.applyNewContentSize(contentSize); if (maybePixels == null) { - setPixels(initialExtent.resolve(contentSize)); + setPixels(initialPosition.resolve(contentSize)); } } } diff --git a/lib/src/draggable/draggable_sheet_position_scope.dart b/lib/src/draggable/draggable_sheet_position_scope.dart index 01a2af6..04c2444 100644 --- a/lib/src/draggable/draggable_sheet_position_scope.dart +++ b/lib/src/draggable/draggable_sheet_position_scope.dart @@ -6,13 +6,13 @@ import '../foundation/sheet_position_scope.dart'; import 'draggable_sheet_position.dart'; @internal -class DraggableSheetExtentScope extends SheetPositionScope { - const DraggableSheetExtentScope({ +class DraggableSheetPositionScope extends SheetPositionScope { + const DraggableSheetPositionScope({ super.key, super.controller, super.isPrimary, required super.context, - required this.initialExtent, + required this.initialPosition, required super.minPosition, required super.maxPosition, required super.physics, @@ -21,32 +21,32 @@ class DraggableSheetExtentScope extends SheetPositionScope { required super.child, }); - /// {@macro DraggableSheetExtent.initialExtent} - final SheetAnchor initialExtent; + /// {@macro DraggableSheetPosition.initialPosition} + final SheetAnchor initialPosition; - /// {@macro SheetExtent.debugLabel} + /// {@macro SheetPosition.debugLabel} final String? debugLabel; @override SheetPositionScopeState createState() { - return _DraggableSheetExtentScopeState(); + return _DraggableSheetPositionScopeState(); } } -class _DraggableSheetExtentScopeState extends SheetPositionScopeState< - DraggableSheetExtent, DraggableSheetExtentScope> { +class _DraggableSheetPositionScopeState extends SheetPositionScopeState< + DraggableSheetPosition, DraggableSheetPositionScope> { @override - bool shouldRebuildExtent(DraggableSheetExtent oldExtent) { - return widget.initialExtent != oldExtent.initialExtent || - widget.debugLabel != oldExtent.debugLabel || - super.shouldRebuildExtent(oldExtent); + bool shouldRebuildPosition(DraggableSheetPosition oldPosition) { + return widget.initialPosition != oldPosition.initialPosition || + widget.debugLabel != oldPosition.debugLabel || + super.shouldRebuildPosition(oldPosition); } @override - DraggableSheetExtent buildExtent(SheetContext context) { - return DraggableSheetExtent( + DraggableSheetPosition buildPosition(SheetContext context) { + return DraggableSheetPosition( context: context, - initialExtent: widget.initialExtent, + initialPosition: widget.initialPosition, minPosition: widget.minPosition, maxPosition: widget.maxPosition, physics: widget.physics, diff --git a/lib/src/draggable/sheet_draggable.dart b/lib/src/draggable/sheet_draggable.dart index 9dc1a8e..9d326bc 100644 --- a/lib/src/draggable/sheet_draggable.dart +++ b/lib/src/draggable/sheet_draggable.dart @@ -41,18 +41,18 @@ class SheetDraggable extends StatefulWidget { } class _SheetDraggableState extends State { - SheetPosition? _extent; + SheetPosition? _position; Drag? _currentDrag; @override void didChangeDependencies() { super.didChangeDependencies(); - _extent = SheetPositionScope.maybeOf(context); + _position = SheetPositionScope.maybeOf(context); } @override void dispose() { - _extent = null; + _position = null; _disposeDrag(); super.dispose(); } @@ -63,7 +63,7 @@ class _SheetDraggableState extends State { void _handleDragStart(DragStartDetails details) { assert(_currentDrag == null); - _currentDrag = _extent?.drag(details, _disposeDrag); + _currentDrag = _position?.drag(details, _disposeDrag); } void _handleDragUpdate(DragUpdateDetails details) { diff --git a/lib/src/foundation/sheet_activity.dart b/lib/src/foundation/sheet_activity.dart index e7f8a1c..a3b846a 100644 --- a/lib/src/foundation/sheet_activity.dart +++ b/lib/src/foundation/sheet_activity.dart @@ -15,18 +15,21 @@ import 'sheet_status.dart'; @optionalTypeArgs abstract class SheetActivity { bool _disposed = false; + bool get disposed { assert(!_mounted || !_disposed); return _disposed; } bool _mounted = false; + bool get mounted { assert(!_mounted || !_disposed); return _mounted; } T? _owner; + T get owner { assert(debugAssertMounted()); return _owner!; @@ -257,7 +260,7 @@ class BallisticSheetActivity extends SheetActivity viewportSize: oldViewportSize, viewportInsets: oldViewportInsets, ); - final destination = owner.physics.findSettledExtent(velocity, oldMetrics); + final destination = owner.physics.findSettledPosition(velocity, oldMetrics); if (oldViewportInsets != null) { absorbBottomViewportInset(owner, oldViewportInsets); @@ -421,7 +424,7 @@ class IdleSheetActivity extends SheetActivity { SheetStatus get status => SheetStatus.stable; /// Updates [SheetMetrics.pixels] to maintain the current [SheetAnchor], which - /// is determined by [SheetPhysics.findSettledExtent] using the metrics of + /// is determined by [SheetPhysics.findSettledPosition] using the metrics of /// the previous frame. @override void didFinalizeDimensions( @@ -440,7 +443,7 @@ class IdleSheetActivity extends SheetActivity { viewportSize: oldViewportSize, viewportInsets: oldViewportInsets, ); - final prevDetent = owner.physics.findSettledExtent(0, oldMetrics); + final prevDetent = owner.physics.findSettledPosition(0, oldMetrics); final newPixels = prevDetent.resolve(owner.contentSize); if (newPixels == owner.pixels) { @@ -543,12 +546,16 @@ mixin ControlledSheetActivityMixin late final AnimationController controller; final _completer = Completer(); + Future get done => _completer.future; @factory AnimationController createAnimationController(); + TickerFuture onAnimationStart(); + void onAnimationTick(); + void onAnimationEnd() {} @override diff --git a/lib/src/foundation/sheet_content_scaffold.dart b/lib/src/foundation/sheet_content_scaffold.dart index b48d05d..ce567ea 100644 --- a/lib/src/foundation/sheet_content_scaffold.dart +++ b/lib/src/foundation/sheet_content_scaffold.dart @@ -222,26 +222,26 @@ abstract class BottomBarVisibility implements Widget { abstract class _RenderBottomBarVisibility extends RenderTransform { _RenderBottomBarVisibility({ - required SheetPosition extent, - }) : _extent = extent, + required SheetPosition position, + }) : _position = position, super(transform: Matrix4.zero(), transformHitTests: true) { - _extent.addListener(invalidateVisibility); + _position.addListener(invalidateVisibility); } - SheetPosition _extent; + SheetPosition _position; // ignore: avoid_setters_without_getters - set extent(SheetPosition value) { - if (_extent != value) { - _extent.removeListener(invalidateVisibility); - _extent = value..addListener(invalidateVisibility); + set position(SheetPosition value) { + if (_position != value) { + _position.removeListener(invalidateVisibility); + _position = value..addListener(invalidateVisibility); invalidateVisibility(); } } @override void dispose() { - _extent.removeListener(invalidateVisibility); + _position.removeListener(invalidateVisibility); super.dispose(); } @@ -258,10 +258,10 @@ abstract class _RenderBottomBarVisibility extends RenderTransform { void invalidateVisibility() { final size = _bottomBarSize; - if (size != null && _extent.hasDimensions) { - final baseTransition = (_extent.pixels - _extent.viewportSize.height) - .clamp(size.height - _extent.viewportSize.height, 0.0); - final visibility = computeVisibility(_extent, size); + if (size != null && _position.hasDimensions) { + final baseTransition = (_position.pixels - _position.viewportSize.height) + .clamp(size.height - _position.viewportSize.height, 0.0); + final visibility = computeVisibility(_position, size); assert(0 <= visibility && visibility <= 1); final invisibleHeight = size.height * (1 - visibility); final transition = baseTransition + invisibleHeight; @@ -300,7 +300,7 @@ class FixedBottomBarVisibility extends SingleChildRenderObjectWidget @override RenderObject createRenderObject(BuildContext context) { return _RenderFixedBottomBarVisibility( - extent: SheetPositionScope.of(context), + position: SheetPositionScope.of(context), resizeBehavior: _ResizeScaffoldBehaviorScope.of(context), ); } @@ -309,14 +309,14 @@ class FixedBottomBarVisibility extends SingleChildRenderObjectWidget void updateRenderObject(BuildContext context, RenderObject renderObject) { super.updateRenderObject(context, renderObject); (renderObject as _RenderFixedBottomBarVisibility) - ..extent = SheetPositionScope.of(context) + ..position = SheetPositionScope.of(context) ..resizeBehavior = _ResizeScaffoldBehaviorScope.of(context); } } class _RenderFixedBottomBarVisibility extends _RenderBottomBarVisibility { _RenderFixedBottomBarVisibility({ - required super.extent, + required super.position, required ResizeScaffoldBehavior resizeBehavior, }) : _resizeBehavior = resizeBehavior; @@ -389,7 +389,7 @@ class StickyBottomBarVisibility extends SingleChildRenderObjectWidget @override RenderObject createRenderObject(BuildContext context) { return _RenderStickyBottomBarVisibility( - extent: SheetPositionScope.of(context), + position: SheetPositionScope.of(context), resizeBehavior: _ResizeScaffoldBehaviorScope.of(context), ); } @@ -398,14 +398,14 @@ class StickyBottomBarVisibility extends SingleChildRenderObjectWidget void updateRenderObject(BuildContext context, RenderObject renderObject) { super.updateRenderObject(context, renderObject); (renderObject as _RenderStickyBottomBarVisibility) - ..extent = SheetPositionScope.of(context) + ..position = SheetPositionScope.of(context) ..resizeBehavior = _ResizeScaffoldBehaviorScope.of(context); } } class _RenderStickyBottomBarVisibility extends _RenderBottomBarVisibility { _RenderStickyBottomBarVisibility({ - required super.extent, + required super.position, required ResizeScaffoldBehavior resizeBehavior, }) : _resizeBehavior = resizeBehavior; @@ -453,7 +453,7 @@ class AnimatedBottomBarVisibility extends SingleChildRenderObjectWidget @override RenderObject createRenderObject(BuildContext context) { return _RenderAnimatedBottomBarVisibility( - extent: SheetPositionScope.of(context), + position: SheetPositionScope.of(context), visibility: visibility, ); } @@ -462,14 +462,14 @@ class AnimatedBottomBarVisibility extends SingleChildRenderObjectWidget void updateRenderObject(BuildContext context, RenderObject renderObject) { super.updateRenderObject(context, renderObject); (renderObject as _RenderAnimatedBottomBarVisibility) - ..extent = SheetPositionScope.of(context) + ..position = SheetPositionScope.of(context) ..visibility = visibility; } } class _RenderAnimatedBottomBarVisibility extends _RenderBottomBarVisibility { _RenderAnimatedBottomBarVisibility({ - required super.extent, + required super.position, required Animation visibility, }) : _visibility = visibility { _visibility.addListener(invalidateVisibility); @@ -562,7 +562,7 @@ class _ConditionalStickyBottomBarVisibilityState with SingleTickerProviderStateMixin { late final AnimationController _controller; late Animation _curveAnimation; - SheetPosition? _extent; + SheetPosition? _position; @override void initState() { @@ -578,7 +578,7 @@ class _ConditionalStickyBottomBarVisibilityState @override void dispose() { - _extent!.removeListener(_didSheetMetricsChanged); + _position!.removeListener(_didSheetMetricsChanged); _controller.dispose(); super.dispose(); } @@ -586,10 +586,10 @@ class _ConditionalStickyBottomBarVisibilityState @override void didChangeDependencies() { super.didChangeDependencies(); - final extent = SheetPositionScope.of(context); - if (_extent != extent) { - _extent?.removeListener(_didSheetMetricsChanged); - _extent = extent..addListener(_didSheetMetricsChanged); + final position = SheetPositionScope.of(context); + if (_position != position) { + _position?.removeListener(_didSheetMetricsChanged); + _position = position..addListener(_didSheetMetricsChanged); _didSheetMetricsChanged(); } } @@ -608,7 +608,8 @@ class _ConditionalStickyBottomBarVisibilityState } void _didSheetMetricsChanged() { - final isVisible = _extent!.hasDimensions && widget.getIsVisible(_extent!); + final isVisible = + _position!.hasDimensions && widget.getIsVisible(_position!); if (isVisible) { if (_controller.status != AnimationStatus.forward) { diff --git a/lib/src/foundation/sheet_controller.dart b/lib/src/foundation/sheet_controller.dart index 450364a..994cb80 100644 --- a/lib/src/foundation/sheet_controller.dart +++ b/lib/src/foundation/sheet_controller.dart @@ -50,17 +50,17 @@ class SheetController extends ChangeNotifier super.removeListener(listener); } - void attach(SheetPosition extent) { - if (_client case final oldExtent?) { - detach(oldExtent); + void attach(SheetPosition position) { + if (_client case final oldPosition?) { + detach(oldPosition); } - _client = extent..addListener(notifyListeners); + _client = position..addListener(notifyListeners); } - void detach(SheetPosition? extent) { - if (extent == _client) { - extent?.removeListener(notifyListeners); + void detach(SheetPosition? position) { + if (position == _client) { + position?.removeListener(notifyListeners); _client = null; } } diff --git a/lib/src/foundation/sheet_notification.dart b/lib/src/foundation/sheet_notification.dart index f158b6b..1118eaf 100644 --- a/lib/src/foundation/sheet_notification.dart +++ b/lib/src/foundation/sheet_notification.dart @@ -5,14 +5,14 @@ import 'sheet_physics.dart'; import 'sheet_position.dart'; import 'sheet_status.dart'; -/// A [Notification] that is dispatched when the sheet extent changes. +/// A [Notification] that is dispatched when the sheet position changes. /// -/// Sheet widgets notify their ancestors about changes to their extent. +/// Sheet widgets notify their ancestors about changes to their position. /// There are 6 types of notifications: /// - [SheetOverflowNotification], which is dispatched when the user tries /// to drag the sheet beyond its draggable bounds but the sheet has not -/// changed its extent because its [SheetPhysics] does not allow it to be. -/// - [SheetUpdateNotification], which is dispatched when the sheet extent +/// changed its position because its [SheetPhysics] does not allow it to be. +/// - [SheetUpdateNotification], which is dispatched when the sheet position /// is updated by other than user interaction such as animation. /// - [SheetDragUpdateNotification], which is dispatched when the sheet /// is dragged. @@ -52,7 +52,7 @@ sealed class SheetNotification extends Notification { } } -/// A [SheetNotification] that is dispatched when the sheet extent +/// A [SheetNotification] that is dispatched when the sheet position /// is updated by other than user interaction such as animation. class SheetUpdateNotification extends SheetNotification { const SheetUpdateNotification({ @@ -130,7 +130,7 @@ class SheetDragCancelNotification extends SheetNotification { /// A [SheetNotification] that is dispatched when the user tries /// to drag the sheet beyond its draggable bounds but the sheet has not -/// changed its extent because its [SheetPhysics] does not allow it to be. +/// changed its position because its [SheetPhysics] does not allow it to be. class SheetOverflowNotification extends SheetNotification { const SheetOverflowNotification({ required super.metrics, diff --git a/lib/src/foundation/sheet_physics.dart b/lib/src/foundation/sheet_physics.dart index c1cc74a..415a9e3 100644 --- a/lib/src/foundation/sheet_physics.dart +++ b/lib/src/foundation/sheet_physics.dart @@ -68,11 +68,11 @@ abstract class SheetPhysics { Simulation? createBallisticSimulation(double velocity, SheetMetrics metrics); - /// {@template SheetPhysics.findSettledExtent} - /// Returns an extent to which a sheet should eventually settle + /// {@template SheetPhysics.findSettledPosition} + /// Returns an position to which a sheet should eventually settle /// based on the current [metrics] and the [velocity] of a sheet. /// {@endtemplate} - SheetAnchor findSettledExtent(double velocity, SheetMetrics metrics); + SheetAnchor findSettledPosition(double velocity, SheetMetrics metrics); } /// A mixin that provides default implementations for [SheetPhysics] methods. @@ -118,8 +118,8 @@ mixin SheetPhysicsMixin on SheetPhysics { } // Ensure that this method always uses the default implementation - // of findSettledExtent. - final detent = _findSettledExtentInternal(velocity, metrics) + // of findSettledPosition. + final detent = _findSettledPositionInternal(velocity, metrics) .resolve(metrics.contentSize); if (FloatComp.distance(metrics.devicePixelRatio) .isNotApprox(detent, metrics.pixels)) { @@ -144,11 +144,11 @@ mixin SheetPhysicsMixin on SheetPhysics { /// if it is out of bounds, regardless of the [velocity]. /// Otherwise, it returns the current position. @override - SheetAnchor findSettledExtent(double velocity, SheetMetrics metrics) { - return _findSettledExtentInternal(velocity, metrics); + SheetAnchor findSettledPosition(double velocity, SheetMetrics metrics) { + return _findSettledPositionInternal(velocity, metrics); } - SheetAnchor _findSettledExtentInternal( + SheetAnchor _findSettledPositionInternal( double velocity, SheetMetrics metrics) { final pixels = metrics.pixels; final minPixels = metrics.minPixels; @@ -165,11 +165,11 @@ mixin SheetPhysicsMixin on SheetPhysics { } abstract interface class SnappingSheetBehavior { - /// {@macro SheetPhysics.findSettledExtent} + /// {@macro SheetPhysics.findSettledPosition} /// /// Returning `null` indicates that this behavior has no preference for /// for where the sheet should settle. - SheetAnchor? findSettledExtent(double velocity, SheetMetrics metrics); + SheetAnchor? findSettledPosition(double velocity, SheetMetrics metrics); } /// A [SnappingSheetBehavior] that snaps to either [SheetMetrics.minPixels] @@ -201,7 +201,7 @@ class SnapToNearestEdge implements SnappingSheetBehavior { final double minFlingSpeed; @override - SheetAnchor? findSettledExtent(double velocity, SheetMetrics metrics) { + SheetAnchor? findSettledPosition(double velocity, SheetMetrics metrics) { assert(minFlingSpeed >= 0); final pixels = metrics.pixels; final minPixels = metrics.minPixels; @@ -239,13 +239,13 @@ class SnapToNearest implements SnappingSheetBehavior { final double minFlingSpeed; @override - SheetAnchor? findSettledExtent(double velocity, SheetMetrics metrics) { + SheetAnchor? findSettledPosition(double velocity, SheetMetrics metrics) { if (snapTo.length <= 1) { return snapTo.firstOrNull; } - final (sortedDetents, nearestIndex) = - sortExtentsAndFindNearest(snapTo, metrics.pixels, metrics.contentSize); + final (sortedDetents, nearestIndex) = sortPositionsAndFindNearest( + snapTo, metrics.pixels, metrics.contentSize); final cmp = FloatComp.distance(metrics.devicePixelRatio); final pixels = metrics.pixels; @@ -259,7 +259,7 @@ class SnapToNearest implements SnappingSheetBehavior { final nearest = sortedDetents[nearestIndex]; if (velocity.abs() < minFlingSpeed) { - return cmp.isApprox(pixels, nearest.resolved) ? null : nearest.extent; + return cmp.isApprox(pixels, nearest.resolved) ? null : nearest.position; } final int floorIndex; @@ -278,51 +278,52 @@ class SnapToNearest implements SnappingSheetBehavior { assert(velocity.abs() >= minFlingSpeed); return velocity < 0 - ? sortedDetents[floorIndex].extent - : sortedDetents[ceilIndex].extent; + ? sortedDetents[floorIndex].position + : sortedDetents[ceilIndex].position; } } -typedef _SortedExtentList = List<({SheetAnchor extent, double resolved})>; +typedef _SortedPositionList = List<({SheetAnchor position, double resolved})>; -/// Sorts the [extents] based on their resolved values and finds the nearest -/// extent to the [pixels]. +/// Sorts the [positions] based on their resolved values and finds the nearest +/// position to the [pixels]. /// -/// Returns a sorted copy of the [extents] and the index of the nearest extent. -/// Note that the returned list may have a fixed length for better performance. +/// Returns a sorted copy of the [positions] and the index of the nearest +/// position. Note that the returned list may have a fixed length for better +/// performance. @visibleForTesting -(_SortedExtentList, int) sortExtentsAndFindNearest( - List extents, +(_SortedPositionList, int) sortPositionsAndFindNearest( + List positions, double pixels, Size contentSize, ) { - assert(extents.isNotEmpty); - switch (extents) { + assert(positions.isNotEmpty); + switch (positions) { case [final a, final b]: - return _sortTwoExtentsAndFindNearest(a, b, pixels, contentSize); + return _sortTwoPositionsAndFindNearest(a, b, pixels, contentSize); case [final a, final b, final c]: - return _sortThreeExtentsAndFindNearest(a, b, c, pixels, contentSize); + return _sortThreePositionsAndFindNearest(a, b, c, pixels, contentSize); case _: - final sortedExtents = extents - .map((e) => (extent: e, resolved: e.resolve(contentSize))) + final sortedPositions = positions + .map((e) => (position: e, resolved: e.resolve(contentSize))) .sorted((a, b) => a.resolved.compareTo(b.resolved)); - final nearestIndex = sortedExtents + final nearestIndex = sortedPositions .mapIndexed((i, e) => (index: i, dist: (pixels - e.resolved).abs())) .reduce((a, b) => a.dist < b.dist ? a : b) .index; - return (sortedExtents, nearestIndex); + return (sortedPositions, nearestIndex); } } /// Constant time sorting and nearest neighbor search for two [SheetAnchor]s. -(_SortedExtentList, int) _sortTwoExtentsAndFindNearest( +(_SortedPositionList, int) _sortTwoPositionsAndFindNearest( SheetAnchor a, SheetAnchor b, double pixels, Size contentSize, ) { - var first = (extent: a, resolved: a.resolve(contentSize)); - var second = (extent: b, resolved: b.resolve(contentSize)); + var first = (position: a, resolved: a.resolve(contentSize)); + var second = (position: b, resolved: b.resolve(contentSize)); if (first.resolved > second.resolved) { final temp = first; @@ -342,16 +343,16 @@ typedef _SortedExtentList = List<({SheetAnchor extent, double resolved})>; } /// Constant time sorting and nearest neighbor search for three [SheetAnchor]s. -(_SortedExtentList, int) _sortThreeExtentsAndFindNearest( +(_SortedPositionList, int) _sortThreePositionsAndFindNearest( SheetAnchor a, SheetAnchor b, SheetAnchor c, double pixels, Size contentSize, ) { - var first = (extent: a, resolved: a.resolve(contentSize)); - var second = (extent: b, resolved: b.resolve(contentSize)); - var third = (extent: c, resolved: c.resolve(contentSize)); + var first = (position: a, resolved: a.resolve(contentSize)); + var second = (position: b, resolved: b.resolve(contentSize)); + var third = (position: c, resolved: c.resolve(contentSize)); if (first.resolved > second.resolved) { final temp = first; @@ -419,7 +420,7 @@ class SnappingSheetPhysics extends SheetPhysics with SheetPhysicsMixin { @override Simulation? createBallisticSimulation(double velocity, SheetMetrics metrics) { final detent = snappingBehavior - .findSettledExtent(velocity, metrics) + .findSettledPosition(velocity, metrics) ?.resolve(metrics.contentSize); if (detent != null && FloatComp.distance(metrics.devicePixelRatio) @@ -436,9 +437,9 @@ class SnappingSheetPhysics extends SheetPhysics with SheetPhysicsMixin { } @override - SheetAnchor findSettledExtent(double velocity, SheetMetrics metrics) { - return snappingBehavior.findSettledExtent(velocity, metrics) ?? - super.findSettledExtent(velocity, metrics); + SheetAnchor findSettledPosition(double velocity, SheetMetrics metrics) { + return snappingBehavior.findSettledPosition(velocity, metrics) ?? + super.findSettledPosition(velocity, metrics); } } diff --git a/lib/src/foundation/sheet_position.dart b/lib/src/foundation/sheet_position.dart index 011736a..49fc643 100644 --- a/lib/src/foundation/sheet_position.dart +++ b/lib/src/foundation/sheet_position.dart @@ -192,7 +192,7 @@ abstract class SheetPosition extends ChangeNotifier SheetPhysics get physics => _physics; SheetPhysics _physics; - /// {@template SheetExtent.gestureTamperer} + /// {@template SheetPosition.gestureTamperer} /// An object that can modify the gesture details of the sheet. /// {@endtemplate} SheetGestureProxyMixin? get gestureTamperer => _gestureTamperer; @@ -498,16 +498,16 @@ abstract class SheetPosition extends ChangeNotifier /// whether it completed successfully or whether it was /// interrupted prematurely. Future animateTo( - SheetAnchor newExtent, { + SheetAnchor newPosition, { Curve curve = Curves.easeInOut, Duration duration = const Duration(milliseconds: 300), }) { assert(hasDimensions); - if (pixels == newExtent.resolve(contentSize)) { + if (pixels == newPosition.resolve(contentSize)) { return Future.value(); } else { final activity = AnimatedSheetActivity( - destination: newExtent, + destination: newPosition, duration: duration, curve: curve, ); diff --git a/lib/src/foundation/sheet_position_driven_animation.dart b/lib/src/foundation/sheet_position_driven_animation.dart index c5c63c4..07126fe 100644 --- a/lib/src/foundation/sheet_position_driven_animation.dart +++ b/lib/src/foundation/sheet_position_driven_animation.dart @@ -7,15 +7,15 @@ class SheetPositionDrivenAnimation extends Animation { SheetPositionDrivenAnimation({ required SheetController controller, required this.initialValue, - this.startExtent, - this.endExtent, + this.startPosition, + this.endPosition, }) : _controller = controller, assert(initialValue >= 0.0 && initialValue <= 1.0); final SheetController _controller; final double initialValue; - final SheetAnchor? startExtent; - final SheetAnchor? endExtent; + final SheetAnchor? startPosition; + final SheetAnchor? endPosition; @override void addListener(VoidCallback listener) { @@ -48,9 +48,9 @@ class SheetPositionDrivenAnimation extends Animation { } final startPixels = - startExtent?.resolve(metrics.contentSize) ?? metrics.minPixels; + startPosition?.resolve(metrics.contentSize) ?? metrics.minPixels; final endPixels = - endExtent?.resolve(metrics.contentSize) ?? metrics.maxPixels; + endPosition?.resolve(metrics.contentSize) ?? metrics.maxPixels; final distance = endPixels - startPixels; if (distance.isFinite && distance > 0) { diff --git a/lib/src/foundation/sheet_position_scope.dart b/lib/src/foundation/sheet_position_scope.dart index 281ebed..44eed56 100644 --- a/lib/src/foundation/sheet_position_scope.dart +++ b/lib/src/foundation/sheet_position_scope.dart @@ -17,15 +17,17 @@ class SheetPositionScopeKey final List _onCreatedListeners = []; - T? get maybeCurrentExtent => - switch (currentState?._extent) { final T extent => extent, _ => null }; + T? get maybeCurrentPosition => switch (currentState?._position) { + final T position => position, + _ => null + }; - T get currentExtent => maybeCurrentExtent!; + T get currentPosition => maybeCurrentPosition!; void addOnCreatedListener(VoidCallback listener) { _onCreatedListeners.add(listener); - // Immediately notify the listener if the extent is already created. - if (maybeCurrentExtent != null) { + // Immediately notify the listener if the position is already created. + if (maybeCurrentPosition != null) { listener(); } } @@ -34,7 +36,7 @@ class SheetPositionScopeKey _onCreatedListeners.remove(listener); } - void _notifySheetExtentCreation() { + void _notifySheetPositionCreation() { for (final listener in _onCreatedListeners) { listener(); } @@ -64,22 +66,22 @@ abstract class SheetPositionScope extends StatefulWidget { required this.child, }); - /// The context the extent object belongs to. + /// The context the position object belongs to. final SheetContext context; /// The [SheetController] attached to the [SheetPosition]. final SheetController? controller; - /// {@macro SheetExtent.minPosition} + /// {@macro SheetPosition.minPosition} final SheetAnchor minPosition; - /// {@macro SheetExtent.maxPosition} + /// {@macro SheetPosition.maxPosition} final SheetAnchor maxPosition; /// {@macro SheetPosition.physics} final SheetPhysics physics; - /// {@macro SheetExtent.gestureTamperer} + /// {@macro SheetPosition.gestureTamperer} final SheetGestureProxyMixin? gestureTamperer; // TODO: Remove this. Specifying null to `controller` is sufficient. @@ -97,7 +99,7 @@ abstract class SheetPositionScope extends StatefulWidget { static E? maybeOf(BuildContext context) { final inherited = context .dependOnInheritedWidgetOfExactType() - ?.extent; + ?.position; return inherited is E ? inherited : null; } @@ -105,10 +107,10 @@ abstract class SheetPositionScope extends StatefulWidget { /// Retrieves a [SheetPosition] from the closest [SheetPositionScope] /// that encloses the given context. static E of(BuildContext context) { - final extent = maybeOf(context); + final position = maybeOf(context); assert(() { - if (extent == null) { + if (position == null) { throw FlutterError( 'No $SheetPositionScope ancestor for $E could be found starting ' 'from the context that was passed to $SheetPositionScope.of(). ' @@ -119,22 +121,22 @@ abstract class SheetPositionScope extends StatefulWidget { return true; }()); - return extent!; + return position!; } } @internal abstract class SheetPositionScopeState extends State { - late E _extent; + late E _position; SheetController? _controller; SheetPositionScopeKey? get _scopeKey { assert(() { if (widget.key != null && widget.key is! SheetPositionScopeKey) { throw FlutterError( - 'The key for a SheetExtentScope<$E> must be a ' - 'SheetExtentScopeKey<$E>, but got a ${widget.key.runtimeType}.', + 'The key for a SheetPositionScope<$E> must be a ' + 'SheetPositionScopeKey<$E>, but got a ${widget.key.runtimeType}.', ); } return true; @@ -149,13 +151,13 @@ abstract class SheetPositionScopeState widget.context != oldExtent.context; + bool shouldRebuildPosition(E oldPosition) => + widget.context != oldPosition.context; - void _disposeExtent(E extent) { - _controller?.detach(extent); - extent.dispose(); + void _disposePosition(E position) { + _controller?.detach(position); + position.dispose(); } void _rewireControllerAndScope() { if (_controller != widget.controller) { - _controller?.detach(_extent); - _controller = widget.controller?..attach(_extent); + _controller?.detach(_position); + _controller = widget.controller?..attach(_position); } } - void _rewireControllerAndExtent() { + void _rewireControllerAndPosition() { assert(_debugAssertPrimaryScopeNotNested()); if (widget.isPrimary) { - _controller?.attach(_extent); + _controller?.attach(_position); } else { - _controller?.detach(_extent); + _controller?.detach(_position); } } @@ -245,7 +248,7 @@ abstract class SheetPositionScopeState - extent != oldWidget.extent || isPrimary != oldWidget.isPrimary; + position != oldWidget.position || isPrimary != oldWidget.isPrimary; } diff --git a/lib/src/foundation/sheet_viewport.dart b/lib/src/foundation/sheet_viewport.dart index 984cff5..d0e5945 100644 --- a/lib/src/foundation/sheet_viewport.dart +++ b/lib/src/foundation/sheet_viewport.dart @@ -25,18 +25,18 @@ class SheetViewport extends SingleChildRenderObjectWidget { @override void updateRenderObject(BuildContext context, RenderObject renderObject) { (renderObject as RenderSheetViewport) - ..extent = SheetPositionScope.of(context) + ..position = SheetPositionScope.of(context) ..insets = MediaQuery.viewInsetsOf(context); } } @internal class RenderSheetViewport extends RenderTransform { - RenderSheetViewport(SheetPosition extent, EdgeInsets insets) - : _extent = extent, + RenderSheetViewport(SheetPosition position, EdgeInsets insets) + : _position = position, _insets = insets, super(transform: Matrix4.zero(), transformHitTests: true) { - _extent.addListener(_invalidateTranslationValue); + _position.addListener(_invalidateTranslationValue); } // Cache the last measured size because we can't access @@ -45,13 +45,13 @@ class RenderSheetViewport extends RenderTransform { Size? get lastMeasuredSize => _lastMeasuredSize; - SheetPosition _extent; + SheetPosition _position; // ignore: avoid_setters_without_getters - set extent(SheetPosition value) { - if (_extent != value) { - _extent.removeListener(_invalidateTranslationValue); - _extent = value..addListener(_invalidateTranslationValue); + set position(SheetPosition value) { + if (_position != value) { + _position.removeListener(_invalidateTranslationValue); + _position = value..addListener(_invalidateTranslationValue); markNeedsLayout(); } } @@ -71,11 +71,11 @@ class RenderSheetViewport extends RenderTransform { void performLayout() { // We can assume that the viewport will always be as big as possible. _lastMeasuredSize = constraints.biggest; - _extent.markAsDimensionsWillChange(); - // Notify the SheetExtent about the viewport size changes + _position.markAsDimensionsWillChange(); + // Notify the SheetPosition about the viewport size changes // before performing the layout so that the descendant widgets // can use the viewport size during the layout phase. - _extent.applyNewViewportDimensions( + _position.applyNewViewportDimensions( Size(_lastMeasuredSize!.width, _lastMeasuredSize!.height), _insets, ); @@ -89,12 +89,12 @@ class RenderSheetViewport extends RenderTransform { ); assert( - _extent.hasDimensions, - 'The sheet extent and the dimensions values ' + _position.hasDimensions, + 'The sheet position and the dimensions values ' 'must be finalized during the layout phase.', ); - _extent.markAsDimensionsChanged(); + _position.markAsDimensionsChanged(); _invalidateTranslationValue(); } @@ -105,10 +105,10 @@ class RenderSheetViewport extends RenderTransform { } void _invalidateTranslationValue() { - final currentExtent = _extent.maybePixels; + final currentPosition = _position.maybePixels; final viewportSize = _lastMeasuredSize; - if (currentExtent != null && viewportSize != null) { - final dy = viewportSize.height - _insets.bottom - currentExtent; + if (currentPosition != null && viewportSize != null) { + final dy = viewportSize.height - _insets.bottom - currentPosition; // Update the translation value and mark this render object // as needing to be repainted. transform = Matrix4.translationValues(0, dy, 0); @@ -127,7 +127,7 @@ class RenderSheetViewport extends RenderTransform { @override bool hitTest(BoxHitTestResult result, {required Offset position}) { - if (_extent.activity.shouldIgnorePointer) { + if (_position.activity.shouldIgnorePointer) { final invTransform = Matrix4.tryInvert( PointerEvent.removePerspectiveTransform(_transform), ); @@ -140,7 +140,7 @@ class RenderSheetViewport extends RenderTransform { @override void dispose() { - _extent.removeListener(_invalidateTranslationValue); + _position.removeListener(_invalidateTranslationValue); super.dispose(); } } @@ -188,7 +188,7 @@ class _SheetContentViewportState extends State { state: this, child: _SheetContentLayoutObserver( isEnabled: _isEnabled, - extent: SheetPositionScope.maybeOf(context), + position: SheetPositionScope.maybeOf(context), child: widget.child, ), ); @@ -216,17 +216,17 @@ class _SheetContentViewportScope extends InheritedWidget { class _SheetContentLayoutObserver extends SingleChildRenderObjectWidget { const _SheetContentLayoutObserver({ required this.isEnabled, - required this.extent, + required this.position, required super.child, }); final ValueGetter isEnabled; - final SheetPosition? extent; + final SheetPosition? position; @override RenderObject createRenderObject(BuildContext context) { return _RenderSheetContentLayoutObserver( - extent: extent, + position: position, isEnabled: isEnabled, ); } @@ -234,7 +234,7 @@ class _SheetContentLayoutObserver extends SingleChildRenderObjectWidget { @override void updateRenderObject(BuildContext context, RenderObject renderObject) { (renderObject as _RenderSheetContentLayoutObserver) - ..extent = extent + ..position = position ..isEnabled = isEnabled; } } @@ -242,17 +242,17 @@ class _SheetContentLayoutObserver extends SingleChildRenderObjectWidget { class _RenderSheetContentLayoutObserver extends RenderPositionedBox { _RenderSheetContentLayoutObserver({ required ValueGetter isEnabled, - required SheetPosition? extent, + required SheetPosition? position, }) : _isEnabled = isEnabled, - _extent = extent, + _position = position, super(alignment: Alignment.topCenter); - SheetPosition? _extent; + SheetPosition? _position; // ignore: avoid_setters_without_getters - set extent(SheetPosition? value) { - if (_extent != value) { - _extent = value; + set position(SheetPosition? value) { + if (_position != value) { + _position = value; markNeedsLayout(); } } @@ -269,7 +269,7 @@ class _RenderSheetContentLayoutObserver extends RenderPositionedBox { @override void performLayout() { - _extent?.markAsDimensionsWillChange(); + _position?.markAsDimensionsWillChange(); super.performLayout(); final childSize = child?.size; // The evaluation of _isEnabled() is intentionally delayed @@ -278,8 +278,8 @@ class _RenderSheetContentLayoutObserver extends RenderPositionedBox { // and if another SheetContentViewport exists in the subtree, // it will change the result of _isEnabled(). if (_isEnabled() && childSize != null) { - _extent?.applyNewContentSize(childSize); + _position?.applyNewContentSize(childSize); } - _extent?.markAsDimensionsChanged(); + _position?.markAsDimensionsChanged(); } } diff --git a/lib/src/navigation/navigation.dart b/lib/src/navigation/navigation.dart index e1521d3..e13f8a6 100644 --- a/lib/src/navigation/navigation.dart +++ b/lib/src/navigation/navigation.dart @@ -1,5 +1,8 @@ export 'navigation_route.dart' - show ExtentScopeBuilder, NavigationSheetRoute, NavigationSheetRouteContent; + show + NavigationSheetRoute, + NavigationSheetRouteContent, + PositionScopeBuilder; export 'navigation_routes.dart' show DraggableNavigationSheetPage, diff --git a/lib/src/navigation/navigation_route.dart b/lib/src/navigation/navigation_route.dart index b3aa271..d1dca35 100644 --- a/lib/src/navigation/navigation_route.dart +++ b/lib/src/navigation/navigation_route.dart @@ -40,10 +40,10 @@ abstract class NavigationSheetRoute bool _debugAssertDependencies() { assert( () { - final globalExtent = + final globalPosition = SheetPositionScope.maybeOf( navigator!.context); - if (globalExtent == null) { + if (globalPosition == null) { throw FlutterError( 'A $SheetPositionScope that hosts a $NavigationSheetPosition ' 'is not found in the given context. This is likely because ' @@ -126,7 +126,7 @@ abstract class NavigationSheetRoute } } -typedef ExtentScopeBuilder = SheetPositionScope Function( +typedef PositionScopeBuilder = SheetPositionScope Function( SheetContext context, SheetPositionScopeKey key, Widget child, @@ -139,20 +139,20 @@ class NavigationSheetRouteContent extends StatelessWidget { required this.child, }); - final ExtentScopeBuilder scopeBuilder; + final PositionScopeBuilder scopeBuilder; final Widget child; @override Widget build(BuildContext context) { assert(_debugAssertDependencies(context)); final parentRoute = ModalRoute.of(context)! as NavigationSheetRoute; - final globalExtent = + final globalPosition = SheetPositionScope.of(context); final routeViewport = NavigationSheetRouteViewport( child: SheetContentViewport(child: child), ); final localScope = scopeBuilder( - globalExtent.context, + globalPosition.context, parentRoute.scopeKey, routeViewport, ); @@ -194,9 +194,9 @@ class NavigationSheetRouteContent extends StatelessWidget { bool _debugAssertDependencies(BuildContext context) { assert( () { - final globalExtent = + final globalPosition = SheetPositionScope.maybeOf(context); - if (globalExtent == null) { + if (globalPosition == null) { throw FlutterError( 'A SheetPositionScope that hosts a $NavigationSheetPosition ' 'is not found in the given context. This is likely because ' diff --git a/lib/src/navigation/navigation_routes.dart b/lib/src/navigation/navigation_routes.dart index a5932c0..b6a8653 100644 --- a/lib/src/navigation/navigation_routes.dart +++ b/lib/src/navigation/navigation_routes.dart @@ -17,7 +17,7 @@ import 'navigation_route.dart'; class _ScrollableNavigationSheetRouteContent extends StatelessWidget { const _ScrollableNavigationSheetRouteContent({ this.debugLabel, - required this.initialExtent, + required this.initialPosition, required this.minPosition, required this.maxPosition, required this.physics, @@ -25,7 +25,7 @@ class _ScrollableNavigationSheetRouteContent extends StatelessWidget { }); final String? debugLabel; - final SheetAnchor initialExtent; + final SheetAnchor initialPosition; final SheetAnchor minPosition; final SheetAnchor maxPosition; final SheetPhysics? physics; @@ -38,11 +38,11 @@ class _ScrollableNavigationSheetRouteContent extends StatelessWidget { return NavigationSheetRouteContent( scopeBuilder: (context, key, child) { - return ScrollableSheetExtentScope( + return ScrollableSheetPositionScope( key: key, context: context, isPrimary: false, - initialExtent: initialExtent, + initialPosition: initialPosition, minPosition: minPosition, maxPosition: maxPosition, physics: physics ?? theme?.physics ?? kDefaultSheetPhysics, @@ -58,7 +58,7 @@ class _ScrollableNavigationSheetRouteContent extends StatelessWidget { class _DraggableNavigationSheetRouteContent extends StatelessWidget { const _DraggableNavigationSheetRouteContent({ this.debugLabel, - required this.initialExtent, + required this.initialPosition, required this.minPosition, required this.maxPosition, required this.physics, @@ -66,7 +66,7 @@ class _DraggableNavigationSheetRouteContent extends StatelessWidget { }); final String? debugLabel; - final SheetAnchor initialExtent; + final SheetAnchor initialPosition; final SheetAnchor minPosition; final SheetAnchor maxPosition; final SheetPhysics? physics; @@ -80,11 +80,11 @@ class _DraggableNavigationSheetRouteContent extends StatelessWidget { return NavigationSheetRouteContent( scopeBuilder: (context, key, child) { - return DraggableSheetExtentScope( + return DraggableSheetPositionScope( key: key, context: context, isPrimary: false, - initialExtent: initialExtent, + initialPosition: initialPosition, minPosition: minPosition, maxPosition: maxPosition, physics: physics, @@ -99,12 +99,12 @@ class _DraggableNavigationSheetRouteContent extends StatelessWidget { } class ScrollableNavigationSheetRoute - extends NavigationSheetRoute { + extends NavigationSheetRoute { ScrollableNavigationSheetRoute({ super.settings, this.maintainState = true, this.transitionDuration = const Duration(milliseconds: 300), - this.initialExtent = const SheetAnchor.proportional(1), + this.initialPosition = const SheetAnchor.proportional(1), this.minPosition = const SheetAnchor.proportional(1), this.maxPosition = const SheetAnchor.proportional(1), this.physics, @@ -112,7 +112,7 @@ class ScrollableNavigationSheetRoute required this.builder, }); - final SheetAnchor initialExtent; + final SheetAnchor initialPosition; final SheetAnchor minPosition; final SheetAnchor maxPosition; final SheetPhysics? physics; @@ -129,8 +129,8 @@ class ScrollableNavigationSheetRoute final WidgetBuilder builder; @override - SheetPositionScopeKey createScopeKey() { - return SheetPositionScopeKey( + SheetPositionScopeKey createScopeKey() { + return SheetPositionScopeKey( debugLabel: kDebugMode ? '$debugLabel:${describeIdentity(this)}' : null, ); } @@ -143,7 +143,7 @@ class ScrollableNavigationSheetRoute ) { return _ScrollableNavigationSheetRouteContent( debugLabel: '$ScrollableNavigationSheetRoute(${settings.name})', - initialExtent: initialExtent, + initialPosition: initialPosition, minPosition: minPosition, maxPosition: maxPosition, physics: physics, @@ -153,12 +153,12 @@ class ScrollableNavigationSheetRoute } class DraggableNavigationSheetRoute - extends NavigationSheetRoute { + extends NavigationSheetRoute { DraggableNavigationSheetRoute({ super.settings, this.maintainState = true, this.transitionDuration = const Duration(milliseconds: 300), - this.initialExtent = const SheetAnchor.proportional(1), + this.initialPosition = const SheetAnchor.proportional(1), this.minPosition = const SheetAnchor.proportional(1), this.maxPosition = const SheetAnchor.proportional(1), this.physics, @@ -166,7 +166,7 @@ class DraggableNavigationSheetRoute required this.builder, }); - final SheetAnchor initialExtent; + final SheetAnchor initialPosition; final SheetAnchor minPosition; final SheetAnchor maxPosition; final SheetPhysics? physics; @@ -183,8 +183,8 @@ class DraggableNavigationSheetRoute final WidgetBuilder builder; @override - SheetPositionScopeKey createScopeKey() { - return SheetPositionScopeKey( + SheetPositionScopeKey createScopeKey() { + return SheetPositionScopeKey( debugLabel: kDebugMode ? '$debugLabel:${describeIdentity(this)}' : null, ); } @@ -197,7 +197,7 @@ class DraggableNavigationSheetRoute ) { return _DraggableNavigationSheetRouteContent( debugLabel: '$DraggableNavigationSheetRoute(${settings.name})', - initialExtent: initialExtent, + initialPosition: initialPosition, minPosition: minPosition, maxPosition: maxPosition, physics: physics, @@ -214,7 +214,7 @@ class ScrollableNavigationSheetPage extends Page { super.restorationId, this.maintainState = true, this.transitionDuration = const Duration(milliseconds: 300), - this.initialExtent = const SheetAnchor.proportional(1), + this.initialPosition = const SheetAnchor.proportional(1), this.minPosition = const SheetAnchor.proportional(1), this.maxPosition = const SheetAnchor.proportional(1), this.physics, @@ -227,7 +227,7 @@ class ScrollableNavigationSheetPage extends Page { final Duration transitionDuration; - final SheetAnchor initialExtent; + final SheetAnchor initialPosition; final SheetAnchor minPosition; final SheetAnchor maxPosition; @@ -245,7 +245,7 @@ class ScrollableNavigationSheetPage extends Page { } class _PageBasedScrollableNavigationSheetRoute - extends NavigationSheetRoute { + extends NavigationSheetRoute { _PageBasedScrollableNavigationSheetRoute({ required ScrollableNavigationSheetPage page, }) : super(settings: page); @@ -263,8 +263,8 @@ class _PageBasedScrollableNavigationSheetRoute RouteTransitionsBuilder? get transitionsBuilder => page.transitionsBuilder; @override - SheetPositionScopeKey createScopeKey() { - return SheetPositionScopeKey( + SheetPositionScopeKey createScopeKey() { + return SheetPositionScopeKey( debugLabel: kDebugMode ? '$debugLabel:${describeIdentity(this)}' : null, ); } @@ -277,7 +277,7 @@ class _PageBasedScrollableNavigationSheetRoute ) { return _ScrollableNavigationSheetRouteContent( debugLabel: '$ScrollableNavigationSheetPage(${page.name})', - initialExtent: page.initialExtent, + initialPosition: page.initialPosition, minPosition: page.minPosition, maxPosition: page.maxPosition, physics: page.physics, @@ -294,7 +294,7 @@ class DraggableNavigationSheetPage extends Page { super.restorationId, this.maintainState = true, this.transitionDuration = const Duration(milliseconds: 300), - this.initialExtent = const SheetAnchor.proportional(1), + this.initialPosition = const SheetAnchor.proportional(1), this.minPosition = const SheetAnchor.proportional(1), this.maxPosition = const SheetAnchor.proportional(1), this.physics, @@ -307,7 +307,7 @@ class DraggableNavigationSheetPage extends Page { final Duration transitionDuration; - final SheetAnchor initialExtent; + final SheetAnchor initialPosition; final SheetAnchor minPosition; final SheetAnchor maxPosition; @@ -325,7 +325,7 @@ class DraggableNavigationSheetPage extends Page { } class _PageBasedDraggableNavigationSheetRoute - extends NavigationSheetRoute { + extends NavigationSheetRoute { _PageBasedDraggableNavigationSheetRoute({ required DraggableNavigationSheetPage page, }) : super(settings: page); @@ -343,8 +343,8 @@ class _PageBasedDraggableNavigationSheetRoute RouteTransitionsBuilder? get transitionsBuilder => page.transitionsBuilder; @override - SheetPositionScopeKey createScopeKey() { - return SheetPositionScopeKey( + SheetPositionScopeKey createScopeKey() { + return SheetPositionScopeKey( debugLabel: kDebugMode ? '$debugLabel:${describeIdentity(this)}' : null, ); } @@ -357,7 +357,7 @@ class _PageBasedDraggableNavigationSheetRoute ) { return _DraggableNavigationSheetRouteContent( debugLabel: '$DraggableNavigationSheetPage(${page.name})', - initialExtent: page.initialExtent, + initialPosition: page.initialPosition, minPosition: page.minPosition, maxPosition: page.maxPosition, physics: page.physics, diff --git a/lib/src/navigation/navigation_sheet.dart b/lib/src/navigation/navigation_sheet.dart index 2aa1b14..a32b6d0 100644 --- a/lib/src/navigation/navigation_sheet.dart +++ b/lib/src/navigation/navigation_sheet.dart @@ -42,7 +42,7 @@ class _NavigationSheetState extends State @override void didChangeTransitionState(Transition? transition) { - _scopeKey.maybeCurrentExtent?.handleRouteTransition(transition); + _scopeKey.maybeCurrentPosition?.handleRouteTransition(transition); } @override diff --git a/lib/src/navigation/navigation_sheet_activity.dart b/lib/src/navigation/navigation_sheet_activity.dart index 3dd45ff..b893079 100644 --- a/lib/src/navigation/navigation_sheet_activity.dart +++ b/lib/src/navigation/navigation_sheet_activity.dart @@ -49,8 +49,8 @@ class TransitionSheetActivity extends NavigationSheetActivity { void _onAnimationTick() { final fraction = _curvedAnimation.value; - final startPixels = currentRoute.scopeKey.maybeCurrentExtent?.maybePixels; - final endPixels = nextRoute.scopeKey.maybeCurrentExtent?.maybePixels; + final startPixels = currentRoute.scopeKey.maybeCurrentPosition?.maybePixels; + final endPixels = nextRoute.scopeKey.maybeCurrentPosition?.maybePixels; if (startPixels != null && endPixels != null) { owner.setPixels(lerpDouble(startPixels, endPixels, fraction)!); @@ -77,17 +77,17 @@ class ProxySheetActivity extends NavigationSheetActivity { @override SheetStatus get status => - route.scopeKey.maybeCurrentExtent?.status ?? SheetStatus.stable; + route.scopeKey.maybeCurrentPosition?.status ?? SheetStatus.stable; @override void init(NavigationSheetPosition owner) { super.init(owner); - route.scopeKey.addOnCreatedListener(_onLocalExtentCreated); + route.scopeKey.addOnCreatedListener(_onLocalPositionCreated); } - void _onLocalExtentCreated() { + void _onLocalPositionCreated() { if (mounted) { - route.scopeKey.currentExtent.addListener(_syncMetrics); + route.scopeKey.currentPosition.addListener(_syncMetrics); _syncMetrics(notify: false); } } @@ -95,18 +95,18 @@ class ProxySheetActivity extends NavigationSheetActivity { @override void dispose() { route.scopeKey - ..maybeCurrentExtent?.removeListener(_syncMetrics) - ..removeOnCreatedListener(_onLocalExtentCreated); + ..maybeCurrentPosition?.removeListener(_syncMetrics) + ..removeOnCreatedListener(_onLocalPositionCreated); super.dispose(); } void _syncMetrics({bool notify = true}) { - assert(route.scopeKey.maybeCurrentExtent != null); - final localExtent = route.scopeKey.currentExtent; - final localMetrics = localExtent.snapshot; + assert(route.scopeKey.maybeCurrentPosition != null); + final localPosition = route.scopeKey.currentPosition; + final localMetrics = localPosition.snapshot; owner.applyNewBoundaryConstraints( - localExtent.minPosition, - localExtent.maxPosition, + localPosition.minPosition, + localPosition.maxPosition, ); if (localMetrics.maybeContentSize case final contentSize?) { owner.applyNewContentSize(contentSize); @@ -122,7 +122,7 @@ class ProxySheetActivity extends NavigationSheetActivity { Size? oldViewportSize, EdgeInsets? oldViewportInsets, ) { - // The proxied extent will handle the dimension changes, + // The proxied position will handle the dimension changes, // so we do nothing here to avoid data races. } } diff --git a/lib/src/navigation/navigation_sheet_position.dart b/lib/src/navigation/navigation_sheet_position.dart index 80ccf6f..3d4cd28 100644 --- a/lib/src/navigation/navigation_sheet_position.dart +++ b/lib/src/navigation/navigation_sheet_position.dart @@ -90,21 +90,21 @@ class NavigationSheetPosition extends SheetPosition { @override Future animateTo( - SheetAnchor newExtent, { + SheetAnchor newPosition, { Curve curve = Curves.easeInOut, Duration duration = const Duration(milliseconds: 300), }) { if (activity case ProxySheetActivity(:final route)) { - return route.scopeKey.currentExtent - .animateTo(newExtent, curve: curve, duration: duration); + return route.scopeKey.currentPosition + .animateTo(newPosition, curve: curve, duration: duration); } else { - return super.animateTo(newExtent, curve: curve, duration: duration); + return super.animateTo(newPosition, curve: curve, duration: duration); } } @override void didUpdateMetrics() { - // Do not dispatch a notifications if a local extent is active. + // Do not dispatch a notifications if a local position is active. if (activity is! NavigationSheetActivity) { super.didUpdateMetrics(); } @@ -112,7 +112,7 @@ class NavigationSheetPosition extends SheetPosition { @override void didDragStart(SheetDragStartDetails details) { - // Do not dispatch a notifications if a local extent is active. + // Do not dispatch a notifications if a local position is active. if (activity is! NavigationSheetActivity) { super.didDragStart(details); } @@ -120,7 +120,7 @@ class NavigationSheetPosition extends SheetPosition { @override void didDragEnd(SheetDragEndDetails details) { - // Do not dispatch a notifications if a local extent is active. + // Do not dispatch a notifications if a local position is active. if (activity is! NavigationSheetActivity) { super.didDragEnd(details); } @@ -128,7 +128,7 @@ class NavigationSheetPosition extends SheetPosition { @override void didDragUpdateMetrics(SheetDragUpdateDetails details) { - // Do not dispatch a notifications if a local extent is active. + // Do not dispatch a notifications if a local position is active. if (activity is! NavigationSheetActivity) { super.didDragUpdateMetrics(details); } @@ -136,7 +136,7 @@ class NavigationSheetPosition extends SheetPosition { @override void didOverflowBy(double overflow) { - // Do not dispatch a notifications if a local extent is active. + // Do not dispatch a notifications if a local position is active. if (activity is! NavigationSheetActivity) { super.didOverflowBy(overflow); } diff --git a/lib/src/navigation/navigation_sheet_position_scope.dart b/lib/src/navigation/navigation_sheet_position_scope.dart index cb620b1..42d4701 100644 --- a/lib/src/navigation/navigation_sheet_position_scope.dart +++ b/lib/src/navigation/navigation_sheet_position_scope.dart @@ -23,7 +23,7 @@ class NavigationSheetPositionScope extends SheetPositionScope { isPrimary: true, ); - /// {@macro SheetExtent.debugLabel} + /// {@macro SheetPosition.debugLabel} final String? debugLabel; @override @@ -35,13 +35,13 @@ class NavigationSheetPositionScope extends SheetPositionScope { class _NavigationSheetPositionScopeState extends SheetPositionScopeState< NavigationSheetPosition, NavigationSheetPositionScope> { @override - bool shouldRebuildExtent(NavigationSheetPosition oldExtent) { - return widget.debugLabel != oldExtent.debugLabel || - super.shouldRebuildExtent(oldExtent); + bool shouldRebuildPosition(NavigationSheetPosition oldPosition) { + return widget.debugLabel != oldPosition.debugLabel || + super.shouldRebuildPosition(oldPosition); } @override - NavigationSheetPosition buildExtent(SheetContext context) { + NavigationSheetPosition buildPosition(SheetContext context) { return NavigationSheetPosition( context: context, minPosition: widget.minPosition, diff --git a/lib/src/navigation/navigation_sheet_viewport.dart b/lib/src/navigation/navigation_sheet_viewport.dart index cf479a2..f44ba9a 100644 --- a/lib/src/navigation/navigation_sheet_viewport.dart +++ b/lib/src/navigation/navigation_sheet_viewport.dart @@ -42,7 +42,7 @@ class NavigationSheetViewport extends SheetViewport { } class _RenderNavigationSheetViewport extends RenderSheetViewport { - _RenderNavigationSheetViewport(super.extent, super.insets); + _RenderNavigationSheetViewport(super.position, super.insets); final _children = <_RenderNavigationSheetRouteViewport>[]; @@ -84,7 +84,7 @@ class NavigationSheetRouteViewport extends SingleChildRenderObjectWidget { RenderObject createRenderObject(BuildContext context) { return _RenderNavigationSheetRouteViewport( globalViewport: NavigationSheetViewport._of(context), - localExtent: SheetPositionScope.of(context), + localPosition: SheetPositionScope.of(context), ); } @@ -92,16 +92,16 @@ class NavigationSheetRouteViewport extends SingleChildRenderObjectWidget { void updateRenderObject(BuildContext context, RenderObject renderObject) { (renderObject as _RenderNavigationSheetRouteViewport) ..globalViewport = NavigationSheetViewport._of(context) - ..localExtent = SheetPositionScope.of(context); + ..localPosition = SheetPositionScope.of(context); } } class _RenderNavigationSheetRouteViewport extends RenderProxyBox { _RenderNavigationSheetRouteViewport({ required _RenderNavigationSheetViewport globalViewport, - required SheetPosition localExtent, + required SheetPosition localPosition, }) : _globalViewport = globalViewport, - _localExtent = localExtent { + _localPosition = localPosition { _globalViewport.addChild(this); } @@ -115,12 +115,12 @@ class _RenderNavigationSheetRouteViewport extends RenderProxyBox { } } - SheetPosition _localExtent; + SheetPosition _localPosition; // ignore: avoid_setters_without_getters - set localExtent(SheetPosition value) { - if (_localExtent != value) { - _localExtent = value; + set localPosition(SheetPosition value) { + if (_localPosition != value) { + _localPosition = value; markNeedsLayout(); } } @@ -133,15 +133,15 @@ class _RenderNavigationSheetRouteViewport extends RenderProxyBox { @override void performLayout() { - _localExtent.markAsDimensionsWillChange(); - // Notify the SheetExtent about the viewport size changes + _localPosition.markAsDimensionsWillChange(); + // Notify the SheetPosition about the viewport size changes // before performing the layout so that the descendant widgets // can use the viewport size during the layout phase. - _localExtent.applyNewViewportDimensions( + _localPosition.applyNewViewportDimensions( Size.copy(_globalViewport.lastMeasuredSize!), _globalViewport.insets, ); super.performLayout(); - _localExtent.markAsDimensionsChanged(); + _localPosition.markAsDimensionsChanged(); } } diff --git a/lib/src/scrollable/scrollable_sheet.dart b/lib/src/scrollable/scrollable_sheet.dart index faf47b5..503d6e9 100644 --- a/lib/src/scrollable/scrollable_sheet.dart +++ b/lib/src/scrollable/scrollable_sheet.dart @@ -16,7 +16,7 @@ import 'sheet_scrollable.dart'; class ScrollableSheet extends StatefulWidget { const ScrollableSheet({ super.key, - this.initialExtent = const SheetAnchor.proportional(1), + this.initialPosition = const SheetAnchor.proportional(1), this.minPosition = const SheetAnchor.proportional(1), this.maxPosition = const SheetAnchor.proportional(1), this.physics, @@ -24,13 +24,13 @@ class ScrollableSheet extends StatefulWidget { required this.child, }); - /// {@macro ScrollableSheetExtent.initialExtent} - final SheetAnchor initialExtent; + /// {@macro ScrollableSheetPosition.initialPosition} + final SheetAnchor initialPosition; - /// {@macro SheetExtent.minPosition} + /// {@macro SheetPosition.minPosition} final SheetAnchor minPosition; - /// {@macro SheetExtent.maxPosition} + /// {@macro SheetPosition.maxPosition} final SheetAnchor maxPosition; /// {@macro SheetPosition.physics} @@ -56,10 +56,10 @@ class _ScrollableSheetState extends State final controller = widget.controller ?? SheetControllerScope.maybeOf(context); - return ScrollableSheetExtentScope( + return ScrollableSheetPositionScope( context: this, controller: controller, - initialExtent: widget.initialExtent, + initialPosition: widget.initialPosition, minPosition: widget.minPosition, maxPosition: widget.maxPosition, physics: physics, diff --git a/lib/src/scrollable/scrollable_sheet_activity.dart b/lib/src/scrollable/scrollable_sheet_activity.dart index 51eb791..1bc15f9 100644 --- a/lib/src/scrollable/scrollable_sheet_activity.dart +++ b/lib/src/scrollable/scrollable_sheet_activity.dart @@ -28,7 +28,7 @@ import 'sheet_content_scroll_position.dart'; /// items in the scroll view. @internal abstract class ScrollableSheetActivity - extends SheetActivity { + extends SheetActivity { ScrollableSheetActivity(SheetContentScrollPosition scrollPosition) : _scrollPosition = scrollPosition; @@ -58,12 +58,11 @@ abstract class ScrollableSheetActivity final cmp = FloatComp.distance(owner.context.devicePixelRatio); if (cmp.isApprox(offset, 0)) return 0; - final position = scrollPosition; final maxPixels = owner.maxPixels; final oldPixels = owner.pixels; - final oldScrollPixels = position.pixels; - final minScrollPixels = position.minScrollExtent; - final maxScrollPixels = position.maxScrollExtent; + final oldScrollPixels = scrollPosition.pixels; + final minScrollPixels = scrollPosition.minScrollExtent; + final maxScrollPixels = scrollPosition.maxScrollExtent; var newPixels = oldPixels; var delta = offset; @@ -78,13 +77,14 @@ abstract class ScrollableSheetActivity } // If the sheet is at the top, scroll the content up as much as possible. if (cmp.isGreaterThanOrApprox(newPixels, maxPixels) && - position.extentAfter > 0) { - position.correctPixels(min(position.pixels + delta, maxScrollPixels)); - delta -= position.pixels - oldScrollPixels; + scrollPosition.extentAfter > 0) { + scrollPosition + .correctPixels(min(scrollPosition.pixels + delta, maxScrollPixels)); + delta -= scrollPosition.pixels - oldScrollPixels; } // If the content cannot be scrolled up anymore, drag the sheet up // to make a bouncing effect (if needed). - if (cmp.isApprox(position.pixels, maxScrollPixels)) { + if (cmp.isApprox(scrollPosition.pixels, maxScrollPixels)) { final physicsAppliedDelta = _applyPhysicsToOffset(delta); assert(cmp.isLessThanOrApprox(physicsAppliedDelta, delta)); newPixels += physicsAppliedDelta; @@ -102,13 +102,14 @@ abstract class ScrollableSheetActivity // If the sheet is not beyond 'maxPixels', scroll the content down // as much as possible. if (cmp.isLessThanOrApprox(newPixels, maxPixels) && - position.extentBefore > 0) { - position.correctPixels(max(position.pixels + delta, minScrollPixels)); - delta -= position.pixels - oldScrollPixels; + scrollPosition.extentBefore > 0) { + scrollPosition + .correctPixels(max(scrollPosition.pixels + delta, minScrollPixels)); + delta -= scrollPosition.pixels - oldScrollPixels; } // If the content cannot be scrolled down anymore, drag the sheet down // to make a shrinking effect (if needed). - if (cmp.isApprox(position.pixels, minScrollPixels)) { + if (cmp.isApprox(scrollPosition.pixels, minScrollPixels)) { final physicsAppliedDelta = _applyPhysicsToOffset(delta); assert(cmp.isLessThanOrApprox(physicsAppliedDelta.abs(), delta.abs())); newPixels += physicsAppliedDelta; @@ -116,17 +117,17 @@ abstract class ScrollableSheetActivity } } - if (position.pixels != oldScrollPixels) { - position + if (scrollPosition.pixels != oldScrollPixels) { + scrollPosition ..notifyListeners() - ..didUpdateScrollPositionBy(position.pixels - oldScrollPixels); + ..didUpdateScrollPositionBy(scrollPosition.pixels - oldScrollPixels); } owner.setPixels(newPixels); final overflow = owner.physics.computeOverflow(delta, owner.snapshot); if (overflow.abs() > 0) { - position.didOverscrollBy(overflow); + scrollPosition.didOverscrollBy(overflow); return overflow; } diff --git a/lib/src/scrollable/scrollable_sheet_position.dart b/lib/src/scrollable/scrollable_sheet_position.dart index 121cd6a..71cb6ee 100644 --- a/lib/src/scrollable/scrollable_sheet_position.dart +++ b/lib/src/scrollable/scrollable_sheet_position.dart @@ -14,11 +14,11 @@ import 'sheet_content_scroll_activity.dart'; import 'sheet_content_scroll_position.dart'; @internal -class ScrollableSheetExtent extends SheetPosition +class ScrollableSheetPosition extends SheetPosition implements SheetContentScrollPositionOwner { - ScrollableSheetExtent({ + ScrollableSheetPosition({ required super.context, - required this.initialExtent, + required this.initialPosition, required super.minPosition, required super.maxPosition, required SheetPhysics physics, @@ -26,17 +26,17 @@ class ScrollableSheetExtent extends SheetPosition super.debugLabel, }) : super(physics: ScrollableSheetPhysics.wrap(physics)); - /// {@template ScrollableSheetExtent.initialExtent} - /// The initial extent of the sheet. + /// {@template ScrollableSheetPosition.initialPosition} + /// The initial position of the sheet. /// {@endtemplate} - final SheetAnchor initialExtent; + final SheetAnchor initialPosition; @override ScrollableSheetPhysics get physics => super.physics as ScrollableSheetPhysics; final _scrollPositions = HashSet(); - /// A [ScrollPosition] that is currently driving the sheet extent. + /// A [ScrollPosition] that is currently driving the sheet position. SheetContentScrollPosition? get _primaryScrollPosition => switch (activity) { final ScrollableSheetActivity activity => activity.scrollPosition, _ => null, @@ -85,14 +85,14 @@ class ScrollableSheetExtent extends SheetPosition void applyNewContentSize(Size contentSize) { super.applyNewContentSize(contentSize); if (maybePixels == null) { - setPixels(initialExtent.resolve(contentSize)); + setPixels(initialPosition.resolve(contentSize)); } } @override void takeOver(SheetPosition other) { super.takeOver(other); - if (other is ScrollableSheetExtent) { + if (other is ScrollableSheetPosition) { assert(_scrollPositions.isEmpty); _scrollPositions.addAll(other._scrollPositions); other._scrollPositions.clear(); diff --git a/lib/src/scrollable/scrollable_sheet_position_scope.dart b/lib/src/scrollable/scrollable_sheet_position_scope.dart index 9619419..195a13f 100644 --- a/lib/src/scrollable/scrollable_sheet_position_scope.dart +++ b/lib/src/scrollable/scrollable_sheet_position_scope.dart @@ -6,13 +6,13 @@ import '../foundation/sheet_position_scope.dart'; import 'scrollable_sheet_position.dart'; @internal -class ScrollableSheetExtentScope extends SheetPositionScope { - const ScrollableSheetExtentScope({ +class ScrollableSheetPositionScope extends SheetPositionScope { + const ScrollableSheetPositionScope({ super.key, super.controller, super.isPrimary, required super.context, - required this.initialExtent, + required this.initialPosition, required super.minPosition, required super.maxPosition, required super.physics, @@ -21,32 +21,32 @@ class ScrollableSheetExtentScope extends SheetPositionScope { required super.child, }); - /// {@macro ScrollableSheetExtent.initialExtent} - final SheetAnchor initialExtent; + /// {@macro ScrollableSheetPosition.initialPosition} + final SheetAnchor initialPosition; - /// {@macro SheetExtent.debugLabel} + /// {@macro SheetPosition.debugLabel} final String? debugLabel; @override SheetPositionScopeState createState() { - return _ScrollableSheetExtentScopeState(); + return _ScrollableSheetPositionScopeState(); } } -class _ScrollableSheetExtentScopeState extends SheetPositionScopeState< - ScrollableSheetExtent, ScrollableSheetExtentScope> { +class _ScrollableSheetPositionScopeState extends SheetPositionScopeState< + ScrollableSheetPosition, ScrollableSheetPositionScope> { @override - bool shouldRebuildExtent(ScrollableSheetExtent oldExtent) { - return widget.initialExtent != oldExtent.initialExtent || - widget.debugLabel != oldExtent.debugLabel || - super.shouldRebuildExtent(oldExtent); + bool shouldRebuildPosition(ScrollableSheetPosition oldPosition) { + return widget.initialPosition != oldPosition.initialPosition || + widget.debugLabel != oldPosition.debugLabel || + super.shouldRebuildPosition(oldPosition); } @override - ScrollableSheetExtent buildExtent(SheetContext context) { - return ScrollableSheetExtent( + ScrollableSheetPosition buildPosition(SheetContext context) { + return ScrollableSheetPosition( context: context, - initialExtent: widget.initialExtent, + initialPosition: widget.initialPosition, minPosition: widget.minPosition, maxPosition: widget.maxPosition, physics: widget.physics, diff --git a/lib/src/scrollable/sheet_scrollable.dart b/lib/src/scrollable/sheet_scrollable.dart index 39e301d..98e4612 100644 --- a/lib/src/scrollable/sheet_scrollable.dart +++ b/lib/src/scrollable/sheet_scrollable.dart @@ -25,7 +25,7 @@ class SheetScrollable extends StatefulWidget { class _SheetScrollableState extends State { late ScrollController _scrollController; - ScrollableSheetExtent? _extent; + ScrollableSheetPosition? _position; @override void initState() { @@ -36,7 +36,7 @@ class _SheetScrollableState extends State { @override void didChangeDependencies() { super.didChangeDependencies(); - _extent = SheetPositionScope.maybeOf(context); + _position = SheetPositionScope.maybeOf(context); } @override @@ -53,7 +53,7 @@ class _SheetScrollableState extends State { @factory SheetContentScrollController createController() { return SheetContentScrollController( - getOwner: () => _extent, + getOwner: () => _position, debugLabel: widget.debugLabel, initialScrollOffset: widget.initialScrollOffset, keepScrollOffset: widget.keepScrollOffset, @@ -62,7 +62,7 @@ class _SheetScrollableState extends State { @override void dispose() { - _extent = null; + _position = null; _scrollController.dispose(); super.dispose(); } diff --git a/test/draggable/draggable_sheet_test.dart b/test/draggable/draggable_sheet_test.dart index 65fcda2..c7bf83a 100644 --- a/test/draggable/draggable_sheet_test.dart +++ b/test/draggable/draggable_sheet_test.dart @@ -86,7 +86,7 @@ void main() { key: sheetKey, controller: controller, minPosition: const SheetAnchor.pixels(200), - initialExtent: const SheetAnchor.pixels(200), + initialPosition: const SheetAnchor.pixels(200), child: const Material( child: _TestSheetContent( height: 500, @@ -98,11 +98,11 @@ void main() { ); expect(controller.metrics.pixels, 200, - reason: 'The sheet should be at the initial extent.'); + reason: 'The sheet should be at the initial position.'); expect(controller.metrics.minPixels < controller.metrics.maxPixels, isTrue, reason: 'The sheet should be draggable.'); - // Start animating the sheet to the max extent. + // Start animating the sheet to the max position. unawaited( controller.animateTo( const SheetAnchor.proportional(1), diff --git a/test/foundation/physics_test.dart b/test/foundation/physics_test.dart index a03c6a6..9939e7e 100644 --- a/test/foundation/physics_test.dart +++ b/test/foundation/physics_test.dart @@ -161,14 +161,14 @@ void main() { ); }); - test('findSettledExtent', () { + test('findSettledPosition', () { expect( - physicsUnderTest.findSettledExtent(0, _positionAtMiddle), + physicsUnderTest.findSettledPosition(0, _positionAtMiddle), SheetAnchor.pixels(_positionAtMiddle.pixels), reason: 'Should return the current position if it is in bounds', ); expect( - physicsUnderTest.findSettledExtent(1000, _positionAtMiddle), + physicsUnderTest.findSettledPosition(1000, _positionAtMiddle), SheetAnchor.pixels(_positionAtMiddle.pixels), reason: 'The velocity should not affect the result', ); @@ -177,13 +177,13 @@ void main() { pixels: _positionAtTopEdge.maxPixels + 10, ); expect( - physicsUnderTest.findSettledExtent(0, overDraggedPosition), + physicsUnderTest.findSettledPosition(0, overDraggedPosition), _referenceSheetMetrics.maxPosition, - reason: 'Should return the max extent if the position ' + reason: 'Should return the max position if the position ' 'is out of the upper bound', ); expect( - physicsUnderTest.findSettledExtent(1000, overDraggedPosition), + physicsUnderTest.findSettledPosition(1000, overDraggedPosition), _referenceSheetMetrics.maxPosition, reason: 'The velocity should not affect the result', ); @@ -192,29 +192,29 @@ void main() { pixels: _positionAtBottomEdge.minPixels - 10, ); expect( - physicsUnderTest.findSettledExtent(0, underDraggedPosition), + physicsUnderTest.findSettledPosition(0, underDraggedPosition), _referenceSheetMetrics.minPosition, - reason: 'Should return the min extent if the position ' + reason: 'Should return the min position if the position ' 'is out of the lower bound', ); expect( - physicsUnderTest.findSettledExtent(1000, underDraggedPosition), + physicsUnderTest.findSettledPosition(1000, underDraggedPosition), _referenceSheetMetrics.minPosition, reason: 'The velocity should not affect the result', ); // Boundary conditions expect( - physicsUnderTest.findSettledExtent(1000, _positionAtTopEdge), + physicsUnderTest.findSettledPosition(1000, _positionAtTopEdge), _referenceSheetMetrics.maxPosition, reason: - 'Should return the max extent if the position is at the upper bound', + 'Should return the max position if the position is at the upper bound', ); expect( - physicsUnderTest.findSettledExtent(1000, _positionAtBottomEdge), + physicsUnderTest.findSettledPosition(1000, _positionAtBottomEdge), _referenceSheetMetrics.minPosition, reason: - 'Should return the min extent if the position is at the lower bound', + 'Should return the min position if the position is at the lower bound', ); }); }); @@ -235,22 +235,22 @@ void main() { ); expect( - behaviorUnderTest.findSettledExtent(0, positionAtNearTopEdge), + behaviorUnderTest.findSettledPosition(0, positionAtNearTopEdge), _referenceSheetMetrics.maxPosition, ); expect( - behaviorUnderTest.findSettledExtent(0, positionAtNearBottomEdge), + behaviorUnderTest.findSettledPosition(0, positionAtNearBottomEdge), _referenceSheetMetrics.minPosition, ); }); test('is aware of fling gesture direction', () { expect( - behaviorUnderTest.findSettledExtent(50, _positionAtBottomEdge), + behaviorUnderTest.findSettledPosition(50, _positionAtBottomEdge), _referenceSheetMetrics.maxPosition, ); expect( - behaviorUnderTest.findSettledExtent(-50, _positionAtTopEdge), + behaviorUnderTest.findSettledPosition(-50, _positionAtTopEdge), _referenceSheetMetrics.minPosition, ); }); @@ -264,26 +264,26 @@ void main() { ); expect( - behaviorUnderTest.findSettledExtent(0, overDraggedPosition), + behaviorUnderTest.findSettledPosition(0, overDraggedPosition), isNull, ); expect( - behaviorUnderTest.findSettledExtent(0, underDraggedPosition), + behaviorUnderTest.findSettledPosition(0, underDraggedPosition), isNull, ); }); test('Boundary conditions', () { expect( - behaviorUnderTest.findSettledExtent(0, _positionAtTopEdge), isNull); - expect(behaviorUnderTest.findSettledExtent(0, _positionAtBottomEdge), + behaviorUnderTest.findSettledPosition(0, _positionAtTopEdge), isNull); + expect(behaviorUnderTest.findSettledPosition(0, _positionAtBottomEdge), isNull); expect( - behaviorUnderTest.findSettledExtent(-50, _positionAtTopEdge), + behaviorUnderTest.findSettledPosition(-50, _positionAtTopEdge), _referenceSheetMetrics.minPosition, ); expect( - behaviorUnderTest.findSettledExtent(50, _positionAtBottomEdge), + behaviorUnderTest.findSettledPosition(50, _positionAtBottomEdge), _referenceSheetMetrics.maxPosition, ); }); @@ -314,15 +314,15 @@ void main() { ); expect( - behaviorUnderTest.findSettledExtent(0, positionAtNearTopEdge), + behaviorUnderTest.findSettledPosition(0, positionAtNearTopEdge), SheetAnchor.pixels(_referenceSheetMetrics.maxPixels), ); expect( - behaviorUnderTest.findSettledExtent(0, positionAtNearMiddle), + behaviorUnderTest.findSettledPosition(0, positionAtNearMiddle), SheetAnchor.pixels(_positionAtMiddle.pixels), ); expect( - behaviorUnderTest.findSettledExtent(0, positionAtNearBottomEdge), + behaviorUnderTest.findSettledPosition(0, positionAtNearBottomEdge), SheetAnchor.pixels(_referenceSheetMetrics.minPixels), ); }); @@ -336,22 +336,22 @@ void main() { ); // Flings up at the bottom edge expect( - behaviorUnderTest.findSettledExtent(50, _positionAtBottomEdge), + behaviorUnderTest.findSettledPosition(50, _positionAtBottomEdge), SheetAnchor.pixels(_positionAtMiddle.pixels), ); // Flings up at the slightly above the middle position expect( - behaviorUnderTest.findSettledExtent(50, positionAtAboveMiddle), + behaviorUnderTest.findSettledPosition(50, positionAtAboveMiddle), SheetAnchor.pixels(_positionAtTopEdge.pixels), ); // Flings down at the top edge expect( - behaviorUnderTest.findSettledExtent(-50, _positionAtTopEdge), + behaviorUnderTest.findSettledPosition(-50, _positionAtTopEdge), SheetAnchor.pixels(_positionAtMiddle.pixels), ); // Flings down at the slightly below the middle position expect( - behaviorUnderTest.findSettledExtent(-50, positionAtBelowMiddle), + behaviorUnderTest.findSettledPosition(-50, positionAtBelowMiddle), SheetAnchor.pixels(_positionAtBottomEdge.pixels), ); }); @@ -365,74 +365,74 @@ void main() { ); expect( - behaviorUnderTest.findSettledExtent(0, overDraggedPosition), + behaviorUnderTest.findSettledPosition(0, overDraggedPosition), isNull, ); expect( - behaviorUnderTest.findSettledExtent(0, underDraggedPosition), + behaviorUnderTest.findSettledPosition(0, underDraggedPosition), isNull, ); }); test('Boundary condition: a drag ends exactly at the top detent', () { expect( - behaviorUnderTest.findSettledExtent(0, _positionAtTopEdge), + behaviorUnderTest.findSettledPosition(0, _positionAtTopEdge), isNull, ); }); test('Boundary condition: flings up exactly at the top detent', () { expect( - behaviorUnderTest.findSettledExtent(50, _positionAtTopEdge), + behaviorUnderTest.findSettledPosition(50, _positionAtTopEdge), SheetAnchor.pixels(_positionAtTopEdge.pixels), ); }); test('Boundary condition: flings down exactly at the top detent', () { expect( - behaviorUnderTest.findSettledExtent(-50, _positionAtTopEdge), + behaviorUnderTest.findSettledPosition(-50, _positionAtTopEdge), SheetAnchor.pixels(_positionAtMiddle.pixels), ); }); test('Boundary condition: a drag ends exactly at the middle detent', () { expect( - behaviorUnderTest.findSettledExtent(0, _positionAtMiddle), + behaviorUnderTest.findSettledPosition(0, _positionAtMiddle), isNull, ); }); test('Boundary condition: flings up exactly at the middle detent', () { expect( - behaviorUnderTest.findSettledExtent(50, _positionAtMiddle), + behaviorUnderTest.findSettledPosition(50, _positionAtMiddle), SheetAnchor.pixels(_positionAtTopEdge.pixels), ); }); test('Boundary condition: flings down exactly at the middle detent', () { expect( - behaviorUnderTest.findSettledExtent(-50, _positionAtMiddle), + behaviorUnderTest.findSettledPosition(-50, _positionAtMiddle), SheetAnchor.pixels(_positionAtBottomEdge.pixels), ); }); test('Boundary condition: a drag ends exactly at the bottom detent', () { expect( - behaviorUnderTest.findSettledExtent(0, _positionAtBottomEdge), + behaviorUnderTest.findSettledPosition(0, _positionAtBottomEdge), isNull, ); }); test('Boundary condition: flings up exactly at the bottom detent', () { expect( - behaviorUnderTest.findSettledExtent(50, _positionAtBottomEdge), + behaviorUnderTest.findSettledPosition(50, _positionAtBottomEdge), SheetAnchor.pixels(_positionAtMiddle.pixels), ); }); test('Boundary condition: flings down exactly at the bottom detent', () { expect( - behaviorUnderTest.findSettledExtent(-50, _positionAtBottomEdge), + behaviorUnderTest.findSettledPosition(-50, _positionAtBottomEdge), SheetAnchor.pixels(_positionAtBottomEdge.pixels), ); }); @@ -528,22 +528,22 @@ void main() { }); }); - group('sortExtentsAndFindNearest', () { - test('with two extents', () { - final (sortedExtents, nearestIndex) = sortExtentsAndFindNearest( + group('sortPositionsAndFindNearest', () { + test('with two positions', () { + final (sortedPositions, nearestIndex) = sortPositionsAndFindNearest( const [SheetAnchor.proportional(1), SheetAnchor.pixels(0)], 250, const Size(400, 600), ); - expect(sortedExtents, const [ - (extent: SheetAnchor.pixels(0), resolved: 0), - (extent: SheetAnchor.proportional(1), resolved: 600), + expect(sortedPositions, const [ + (position: SheetAnchor.pixels(0), resolved: 0), + (position: SheetAnchor.proportional(1), resolved: 600), ]); expect(nearestIndex, 0); }); - test('with three extents', () { - final (sortedExtents, nearestIndex) = sortExtentsAndFindNearest( + test('with three positions', () { + final (sortedPositions, nearestIndex) = sortPositionsAndFindNearest( const [ SheetAnchor.proportional(1), SheetAnchor.proportional(0.5), @@ -552,16 +552,16 @@ void main() { 250, const Size(400, 600), ); - expect(sortedExtents, const [ - (extent: SheetAnchor.pixels(0), resolved: 0), - (extent: SheetAnchor.proportional(0.5), resolved: 300), - (extent: SheetAnchor.proportional(1), resolved: 600), + expect(sortedPositions, const [ + (position: SheetAnchor.pixels(0), resolved: 0), + (position: SheetAnchor.proportional(0.5), resolved: 300), + (position: SheetAnchor.proportional(1), resolved: 600), ]); expect(nearestIndex, 1); }); - test('with more than three extents', () { - final (sortedExtents, nearestIndex) = sortExtentsAndFindNearest( + test('with more than three positions', () { + final (sortedPositions, nearestIndex) = sortPositionsAndFindNearest( const [ SheetAnchor.proportional(0.25), SheetAnchor.proportional(0.5), @@ -572,12 +572,12 @@ void main() { 500, const Size(400, 600), ); - expect(sortedExtents, const [ - (extent: SheetAnchor.pixels(0), resolved: 0), - (extent: SheetAnchor.proportional(0.25), resolved: 150), - (extent: SheetAnchor.proportional(0.5), resolved: 300), - (extent: SheetAnchor.proportional(0.75), resolved: 450), - (extent: SheetAnchor.proportional(1), resolved: 600), + expect(sortedPositions, const [ + (position: SheetAnchor.pixels(0), resolved: 0), + (position: SheetAnchor.proportional(0.25), resolved: 150), + (position: SheetAnchor.proportional(0.5), resolved: 300), + (position: SheetAnchor.proportional(0.75), resolved: 450), + (position: SheetAnchor.proportional(1), resolved: 600), ]); expect(nearestIndex, 3); }); diff --git a/test/foundation/sheet_activity_test.dart b/test/foundation/sheet_activity_test.dart index 0a3c0c4..021c77d 100644 --- a/test/foundation/sheet_activity_test.dart +++ b/test/foundation/sheet_activity_test.dart @@ -41,7 +41,7 @@ void main() { }); test('should animate to the destination', () { - final (ownerMetrics, owner) = createMockSheetExtent( + final (ownerMetrics, owner) = createMockSheetPosition( pixels: 300, minPosition: const SheetAnchor.pixels(300), maxPosition: const SheetAnchor.pixels(700), @@ -80,7 +80,7 @@ void main() { }); test('should absorb viewport changes', () { - final (ownerMetrics, owner) = createMockSheetExtent( + final (ownerMetrics, owner) = createMockSheetPosition( pixels: 300, minPosition: const SheetAnchor.pixels(300), maxPosition: const SheetAnchor.proportional(1), @@ -140,7 +140,7 @@ void main() { late TickerCallback? internalOnTickCallback; setUp(() { - (ownerMetrics, owner) = createMockSheetExtent( + (ownerMetrics, owner) = createMockSheetPosition( pixels: 300, minPosition: const SheetAnchor.proportional(0.5), maxPosition: const SheetAnchor.proportional(1), @@ -271,8 +271,8 @@ void main() { }); group('IdleSheetActivity', () { - test('should maintain previous extent when keyboard appears', () { - final (ownerMetrics, owner) = createMockSheetExtent( + test('should maintain previous position when keyboard appears', () { + final (ownerMetrics, owner) = createMockSheetPosition( pixels: 450, minPosition: const SheetAnchor.proportional(0.5), maxPosition: const SheetAnchor.proportional(1), @@ -294,10 +294,10 @@ void main() { }); test( - 'should maintain previous extent when content size changes, ' + 'should maintain previous position when content size changes, ' 'without animation if gap is small', () { - final (ownerMetrics, owner) = createMockSheetExtent( + final (ownerMetrics, owner) = createMockSheetPosition( pixels: 300, minPosition: const SheetAnchor.proportional(0.5), maxPosition: const SheetAnchor.proportional(1), @@ -320,10 +320,10 @@ void main() { ); test( - 'should maintain previous extent when content size changes, ' + 'should maintain previous position when content size changes, ' 'with animation if gap is large', () { - final (ownerMetrics, owner) = createMockSheetExtent( + final (ownerMetrics, owner) = createMockSheetPosition( pixels: 300, minPosition: const SheetAnchor.proportional(0.5), maxPosition: const SheetAnchor.proportional(1), diff --git a/test/foundation/sheet_viewport_test.dart b/test/foundation/sheet_viewport_test.dart index c651ec7..635d977 100644 --- a/test/foundation/sheet_viewport_test.dart +++ b/test/foundation/sheet_viewport_test.dart @@ -38,8 +38,8 @@ class _FakeSheetActivity extends SheetActivity { SheetStatus get status => SheetStatus.stable; } -class _FakeSheetExtent extends SheetPosition { - _FakeSheetExtent({ +class _FakeSheetPosition extends SheetPosition { + _FakeSheetPosition({ this.createIdleActivity, }) : super( context: _FakeSheetContext(), @@ -70,12 +70,12 @@ class _FakeSheetExtent extends SheetPosition { class _TestWidget extends StatelessWidget { const _TestWidget({ - required this.extent, + required this.position, this.background, this.sheetContent, }); - final SheetPosition extent; + final SheetPosition position; final Widget? sheetContent; final Widget? background; @@ -83,7 +83,7 @@ class _TestWidget extends StatelessWidget { Widget build(BuildContext context) { final sheet = InheritedSheetPositionScope( isPrimary: true, - extent: extent, + position: position, child: SheetViewport( child: SheetContentViewport( child: sheetContent ?? @@ -114,7 +114,7 @@ class _TestWidget extends StatelessWidget { void main() { group('Ignore pointer test:', () { ({ - SheetPosition extent, + SheetPosition position, Widget testWidget, ValueGetter didTapForeground, ValueGetter didTapBackgroundTop, @@ -126,14 +126,14 @@ void main() { var didTapBackgroundTop = false; var didTapBackgroundBottom = false; - final extent = _FakeSheetExtent( + final position = _FakeSheetPosition( createIdleActivity: () => _FakeSheetActivity( shouldIgnorePointer: shouldIgnorePointer, ), ); final testWidget = _TestWidget( - extent: extent, + position: position, background: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -160,7 +160,7 @@ void main() { ); return ( - extent: extent, + position: position, testWidget: testWidget, didTapForeground: () => didTapForeground, didTapBackgroundTop: () => didTapBackgroundTop, diff --git a/test/navigation/navigation_sheet_test.dart b/test/navigation/navigation_sheet_test.dart index 3555a78..4fa7895 100644 --- a/test/navigation/navigation_sheet_test.dart +++ b/test/navigation/navigation_sheet_test.dart @@ -123,14 +123,14 @@ class _TestDraggablePageWidget extends StatelessWidget { required String label, required double height, String? nextRoute, - SheetAnchor initialExtent = const SheetAnchor.proportional(1), + SheetAnchor initialPosition = const SheetAnchor.proportional(1), SheetAnchor minPosition = const SheetAnchor.proportional(1), Duration transitionDuration = const Duration(milliseconds: 300), SheetPhysics? physics, }) { return DraggableNavigationSheetRoute( physics: physics, - initialExtent: initialExtent, + initialPosition: initialPosition, minPosition: minPosition, transitionDuration: transitionDuration, builder: (context) => _TestDraggablePageWidget( @@ -202,7 +202,7 @@ class _TestScrollablePageWidget extends StatelessWidget { double? height, int itemCount = 30, String? nextRoute, - SheetAnchor initialExtent = const SheetAnchor.proportional(1), + SheetAnchor initialPosition = const SheetAnchor.proportional(1), SheetAnchor minPosition = const SheetAnchor.proportional(1), Duration transitionDuration = const Duration(milliseconds: 300), SheetPhysics? physics, @@ -210,7 +210,7 @@ class _TestScrollablePageWidget extends StatelessWidget { }) { return ScrollableNavigationSheetRoute( physics: physics, - initialExtent: initialExtent, + initialPosition: initialPosition, minPosition: minPosition, transitionDuration: transitionDuration, builder: (context) => _TestScrollablePageWidget( @@ -459,7 +459,7 @@ void main() { label: 'First', height: 500, minPosition: const SheetAnchor.pixels(200), - initialExtent: const SheetAnchor.pixels(200), + initialPosition: const SheetAnchor.pixels(200), ), }, contentBuilder: (context, child) { @@ -473,14 +473,14 @@ void main() { ); expect(controller.metrics.pixels, 200, - reason: 'The sheet should be at the initial extent.'); + reason: 'The sheet should be at the initial position.'); expect( controller.metrics.minPixels < controller.metrics.maxPixels, isTrue, reason: 'The sheet should be draggable.', ); - // Start animating the sheet to the max extent. + // Start animating the sheet to the max position. unawaited( controller.animateTo( const SheetAnchor.proportional(1), diff --git a/test/scrollable/scrollable_sheet_test.dart b/test/scrollable/scrollable_sheet_test.dart index b91aa51..e471502 100644 --- a/test/scrollable/scrollable_sheet_test.dart +++ b/test/scrollable/scrollable_sheet_test.dart @@ -107,7 +107,7 @@ void main() { key: sheetKey, controller: controller, minPosition: const SheetAnchor.pixels(200), - initialExtent: const SheetAnchor.pixels(200), + initialPosition: const SheetAnchor.pixels(200), child: const _TestSheetContent(height: 500), ), ), @@ -115,11 +115,11 @@ void main() { ); expect(controller.metrics.pixels, 200, - reason: 'The sheet should be at the initial extent.'); + reason: 'The sheet should be at the initial position.'); expect(controller.metrics.minPixels < controller.metrics.maxPixels, isTrue, reason: 'The sheet should be draggable.'); - // Start animating the sheet to the max extent. + // Start animating the sheet to the max position. unawaited( controller.animateTo( const SheetAnchor.proportional(1), @@ -342,7 +342,7 @@ void main() { // - https://github.com/fujidaiti/smooth_sheets/issues/212 group('Infinite ballistic scroll activity test', () { late ScrollController scrollController; - late ScrollableSheetExtent sheetExtent; + late ScrollableSheetPosition sheetPosition; late Widget testWidget; setUp(() { @@ -350,7 +350,7 @@ void main() { child: Builder( builder: (context) { scrollController = PrimaryScrollController.of(context); - sheetExtent = SheetPositionScope.of(context); + sheetPosition = SheetPositionScope.of(context); return SingleChildScrollView( physics: const BouncingScrollPhysics(), child: Container( @@ -372,13 +372,13 @@ void main() { // Start a ballistic animation from a position extremely close to, // but not equal, to the initial position. scrollController.position.correctPixels(-0.000000001); - sheetExtent.goBallisticWithScrollPosition( + sheetPosition.goBallisticWithScrollPosition( velocity: 0, scrollPosition: scrollController.position as SheetContentScrollPosition, ); await tester.pumpAndSettle(); expect(scrollController.position.pixels, 0); - expect(sheetExtent.activity, isA(), + expect(sheetPosition.activity, isA(), reason: 'Should not enter an infinite recursion ' 'of BallisticScrollDrivenSheetActivity'); }); @@ -393,13 +393,13 @@ void main() { // Start a ballistic animation from a position extremely close to, // but not equal, to the current position. scrollController.position.correctPixels(600.000000001); - sheetExtent.goBallisticWithScrollPosition( + sheetPosition.goBallisticWithScrollPosition( velocity: 0, scrollPosition: scrollController.position as SheetContentScrollPosition, ); await tester.pumpAndSettle(); expect(scrollController.position.pixels, 600.0); - expect(sheetExtent.activity, isA(), + expect(sheetPosition.activity, isA(), reason: 'Should not enter an infinite recursion ' 'of BallisticScrollDrivenSheetActivity'); }); diff --git a/test/src/stubbing.dart b/test/src/stubbing.dart index ed9daed..f3f66da 100644 --- a/test/src/stubbing.dart +++ b/test/src/stubbing.dart @@ -72,7 +72,7 @@ class MutableSheetMetrics with SheetMetrics { } } -(MutableSheetMetrics, MockSheetPosition) createMockSheetExtent({ +(MutableSheetMetrics, MockSheetPosition) createMockSheetPosition({ required double pixels, required SheetAnchor minPosition, required SheetAnchor maxPosition, @@ -92,47 +92,48 @@ class MutableSheetMetrics with SheetMetrics { devicePixelRatio: devicePixelRatio, ); - final extent = MockSheetPosition(); - when(extent.pixels).thenAnswer((_) => metricsRegistry.pixels); - when(extent.maybePixels).thenAnswer((_) => metricsRegistry.maybePixels); - when(extent.minPosition).thenAnswer((_) => metricsRegistry.minPosition); - when(extent.maybeMinPosition) + final position = MockSheetPosition(); + when(position.pixels).thenAnswer((_) => metricsRegistry.pixels); + when(position.maybePixels).thenAnswer((_) => metricsRegistry.maybePixels); + when(position.minPosition).thenAnswer((_) => metricsRegistry.minPosition); + when(position.maybeMinPosition) .thenAnswer((_) => metricsRegistry.maybeMinPosition); - when(extent.maxPosition).thenAnswer((_) => metricsRegistry.maxPosition); - when(extent.maybeMaxPosition) + when(position.maxPosition).thenAnswer((_) => metricsRegistry.maxPosition); + when(position.maybeMaxPosition) .thenAnswer((_) => metricsRegistry.maybeMaxPosition); - when(extent.contentSize).thenAnswer((_) => metricsRegistry.contentSize); - when(extent.maybeContentSize) + when(position.contentSize).thenAnswer((_) => metricsRegistry.contentSize); + when(position.maybeContentSize) .thenAnswer((_) => metricsRegistry.maybeContentSize); - when(extent.viewportSize).thenAnswer((_) => metricsRegistry.viewportSize); - when(extent.maybeViewportSize) + when(position.viewportSize).thenAnswer((_) => metricsRegistry.viewportSize); + when(position.maybeViewportSize) .thenAnswer((_) => metricsRegistry.maybeViewportSize); - when(extent.viewportInsets).thenAnswer((_) => metricsRegistry.viewportInsets); - when(extent.maybeViewportInsets) + when(position.viewportInsets) + .thenAnswer((_) => metricsRegistry.viewportInsets); + when(position.maybeViewportInsets) .thenAnswer((_) => metricsRegistry.maybeViewportInsets); - when(extent.devicePixelRatio) + when(position.devicePixelRatio) .thenAnswer((_) => metricsRegistry.devicePixelRatio); - when(extent.snapshot).thenAnswer((_) => metricsRegistry); + when(position.snapshot).thenAnswer((_) => metricsRegistry); - when(extent.setPixels(any)).thenAnswer((invocation) { + when(position.setPixels(any)).thenAnswer((invocation) { metricsRegistry.maybePixels = invocation.positionalArguments.first as double; }); - when(extent.applyNewContentSize(any)).thenAnswer((invocation) { + when(position.applyNewContentSize(any)).thenAnswer((invocation) { metricsRegistry.maybeContentSize = invocation.positionalArguments.first as Size; }); - when(extent.applyNewViewportDimensions(any, any)).thenAnswer((invocation) { + when(position.applyNewViewportDimensions(any, any)).thenAnswer((invocation) { metricsRegistry ..maybeViewportSize = invocation.positionalArguments.first as Size ..maybeViewportInsets = invocation.positionalArguments.last as EdgeInsets; }); - when(extent.applyNewBoundaryConstraints(any, any)).thenAnswer((invocation) { + when(position.applyNewBoundaryConstraints(any, any)).thenAnswer((invocation) { metricsRegistry ..maybeMinPosition = invocation.positionalArguments.first as SheetAnchor ..maybeMaxPosition = invocation.positionalArguments.last as SheetAnchor; }); - when(extent.copyWith( + when(position.copyWith( pixels: anyNamed('pixels'), minPosition: anyNamed('minPosition'), maxPosition: anyNamed('maxPosition'), @@ -153,8 +154,8 @@ class MutableSheetMetrics with SheetMetrics { }); if (physics != null) { - when(extent.physics).thenReturn(physics); + when(position.physics).thenReturn(physics); } - return (metricsRegistry, extent); + return (metricsRegistry, position); } diff --git a/test/src/stubbing.mocks.dart b/test/src/stubbing.mocks.dart index 30cba95..39b473d 100644 --- a/test/src/stubbing.mocks.dart +++ b/test/src/stubbing.mocks.dart @@ -615,14 +615,14 @@ class MockSheetPosition extends _i1.Mock implements _i4.SheetPosition { @override _i9.Future animateTo( - _i4.SheetAnchor? newExtent, { + _i4.SheetAnchor? newPosition, { _i7.Curve? curve = _i7.Curves.easeInOut, Duration? duration = const Duration(milliseconds: 300), }) => (super.noSuchMethod( Invocation.method( #animateTo, - [newExtent], + [newPosition], { #curve: curve, #duration: duration, From 190bd3f39fb0c403d0b838c48e594eef93644e29 Mon Sep 17 00:00:00 2001 From: fujidaiti Date: Fri, 27 Sep 2024 22:35:24 +0900 Subject: [PATCH 21/22] Rename PositionScopeBuilder --- lib/src/navigation/navigation.dart | 2 +- lib/src/navigation/navigation_route.dart | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/navigation/navigation.dart b/lib/src/navigation/navigation.dart index e13f8a6..f3b4c34 100644 --- a/lib/src/navigation/navigation.dart +++ b/lib/src/navigation/navigation.dart @@ -2,7 +2,7 @@ export 'navigation_route.dart' show NavigationSheetRoute, NavigationSheetRouteContent, - PositionScopeBuilder; + SheetPositionScopeBuilder; export 'navigation_routes.dart' show DraggableNavigationSheetPage, diff --git a/lib/src/navigation/navigation_route.dart b/lib/src/navigation/navigation_route.dart index d1dca35..bab565e 100644 --- a/lib/src/navigation/navigation_route.dart +++ b/lib/src/navigation/navigation_route.dart @@ -126,7 +126,7 @@ abstract class NavigationSheetRoute } } -typedef PositionScopeBuilder = SheetPositionScope Function( +typedef SheetPositionScopeBuilder = SheetPositionScope Function( SheetContext context, SheetPositionScopeKey key, Widget child, @@ -139,7 +139,7 @@ class NavigationSheetRouteContent extends StatelessWidget { required this.child, }); - final PositionScopeBuilder scopeBuilder; + final SheetPositionScopeBuilder scopeBuilder; final Widget child; @override From 006a58373a642057e4151ceccffdebf2978e6abd Mon Sep 17 00:00:00 2001 From: fujidaiti Date: Fri, 27 Sep 2024 22:43:33 +0900 Subject: [PATCH 22/22] Update documentation --- README.md | 279 +++++++++++++++++---------- migrations/migration-guide-0.10.x.md | 22 ++- 2 files changed, 196 insertions(+), 105 deletions(-) diff --git a/README.md b/README.md index f335f1d..2176703 100644 --- a/README.md +++ b/README.md @@ -2,20 +2,27 @@ [![GitHub Repo stars](https://img.shields.io/github/stars/fujidaiti/smooth_sheets)](https://github.com/fujidaiti/smooth_sheets) [![GitHub last commit (branch)](https://img.shields.io/github/last-commit/fujidaiti/smooth_sheets/main?logo=git)](https://github.com/fujidaiti/smooth_sheets/commits/main/) [![Pub Version](https://img.shields.io/pub/v/smooth_sheets)](https://pub.dev/packages/smooth_sheets) ![Pub Likes](https://img.shields.io/pub/likes/smooth_sheets) ![Pub Points](https://img.shields.io/pub/points/smooth_sheets) ![Pub Popularity](https://img.shields.io/pub/popularity/smooth_sheets) - **smooth_sheets** offers modal and persistent sheet widgets for Flutter apps. The key features are: - **Smooth motion**: The sheets respond to user interaction with smooth, graceful motion. -- **Highly flexible**: Not restricted to a specific design. Both modal and persistent styles are supp/orted, as well as scrollable and non-scrollable widgets. -- **Supports nested navigation**: A sheet is able to have multiple pages and to navigate between the pages with motion animation for transitions. -- **Works with imperative & declarative Navigator API**: No special navigation mechanism is required. The traditional ways such as `Navigator.push` is supported and it works with Navigator 2.0 packages like go_route as well. +- **Highly flexible**: Not restricted to a specific design. Both modal and persistent styles are + supp/orted, as well as scrollable and non-scrollable widgets. +- **Supports nested navigation**: A sheet is able to have multiple pages and to navigate between the + pages with motion animation for transitions. +- **Works with imperative & declarative Navigator API**: No special navigation mechanism is + required. The traditional ways such as `Navigator.push` is supported and it works with Navigator + 2.0 packages like go_route as well. - **iOS flavor**: The modal sheets in the style of iOS 15 are supported.
## For developers using Flutter 3.24+ -If your project uses Flutter 3.24.0 or later, we recommend using the pre-release versions named `1.0.0-f324.x.x.x`. While you can still use the non-pre-release versions (e.g., `0.9.4`) with Flutter 3.24+, you may encounter issues related to the `PopScope` widget due to a breaking change in Flutter 3.24. There are no functional or API differences between the pre-release and non-pre-release versions, except that the pre-release versions require Flutter 3.24.0 or later. +If your project uses Flutter 3.24.0 or later, we recommend using the pre-release versions +named `1.0.0-f324.x.x.x`. While you can still use the non-pre-release versions (e.g., `0.9.4`) with +Flutter 3.24+, you may encounter issues related to the `PopScope` widget due to a breaking change in +Flutter 3.24. There are no functional or API differences between the pre-release and non-pre-release +versions, except that the pre-release versions require Flutter 3.24.0 or later. ```yaml dependencies: @@ -28,16 +35,28 @@ dependencies:
Background -This package previously used the `Route.onPopInvoked` method to invoke `PopScope.onPopInvoked` callbacks when users performed a swipe-to-dismiss gesture. However, these methods were deprecated in Flutter 3.24.0 as part of a [breaking change](https://docs.flutter.dev/release/breaking-changes/popscope-with-result) related to the `PopScope` widget. The problem is that `ModalRoute.onPopInvoked`, which was an override of `Route.onPopInvoked` and where `PopScope.onPopInvoked` callbacks were actually invoked, was removed. As a result, the `PopScope.onPopInvoked` callback is no longer invoked in Flutter 3.24+. These changes led to issues such as [#233](https://github.com/fujidaiti/smooth_sheets/issues/233). - -The only possible solution was to replace `Route.onPopInvoked` with `Route.onPopInvokedWithResult`, which was introduced in Flutter 3.24.0. However, migrating to the new API would require increasing the lower bound of the SDK constraint to 3.24.0. For those using an SDK version lower than 3.24, this change would be a significant breaking change. Ultimately, we decided to publish different versions for different SDK constraints to maintain backward compatibility. +This package previously used the `Route.onPopInvoked` method to invoke `PopScope.onPopInvoked` +callbacks when users performed a swipe-to-dismiss gesture. However, these methods were deprecated in +Flutter 3.24.0 as part of +a [breaking change](https://docs.flutter.dev/release/breaking-changes/popscope-with-result) related +to the `PopScope` widget. The problem is that `ModalRoute.onPopInvoked`, which was an override +of `Route.onPopInvoked` and where `PopScope.onPopInvoked` callbacks were actually invoked, was +removed. As a result, the `PopScope.onPopInvoked` callback is no longer invoked in Flutter 3.24+. +These changes led to issues such as [#233](https://github.com/fujidaiti/smooth_sheets/issues/233). + +The only possible solution was to replace `Route.onPopInvoked` with `Route.onPopInvokedWithResult`, +which was introduced in Flutter 3.24.0. However, migrating to the new API would require increasing +the lower bound of the SDK constraint to 3.24.0. For those using an SDK version lower than 3.24, +this change would be a significant breaking change. Ultimately, we decided to publish different +versions for different SDK constraints to maintain backward compatibility.

## Migration guide -- [0.8.x to 0.9.x](https://github.com/fujidaiti/smooth_sheets/blob/main/docs/migration-guide-0.9.x.md) 🆕 +- [0.8.x to 0.9.x](https://github.com/fujidaiti/smooth_sheets/blob/main/docs/migration-guide-0.9.x.md) + 🆕 - [0.7.x to 0.8.x](https://github.com/fujidaiti/smooth_sheets/blob/main/docs/migration-guide-0.8.x.md) See [here](https://github.com/fujidaiti/smooth_sheets/blob/main/docs/) for older versions. @@ -112,15 +131,19 @@ See [here](https://github.com/fujidaiti/smooth_sheets/blob/main/docs/) for older ## Why use this? -There are few packages on pub.dev that supports nested navigation with motion animation for page transitions. One of the great choices for this usecase is [wolt_modal_sheet](https://github.com/woltapp/wolt_modal_sheet), which this package is inspired by. Although smooth_sheet has similar features with wolt_modal_sheet, it does not intended to be a replacement of that package. Here is some differences between those 2 packages: +There are few packages on pub.dev that supports nested navigation with motion animation for page +transitions. One of the great choices for this usecase +is [wolt_modal_sheet](https://github.com/woltapp/wolt_modal_sheet), which this package is inspired +by. Although smooth_sheet has similar features with wolt_modal_sheet, it does not intended to be a +replacement of that package. Here is some differences between those 2 packages: -| | wolt_modal_sheet | smooth_sheets | -| :--------------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | -| Design | Based on Wolt's [design guideline](https://careers.wolt.com/en/blog/tech/an-overview-of-the-multi-page-scrollable-bottom-sheet-ui-design) | Not restricted to a specific design, fully customizable | -| Navigation mechanism | [Manage the page index in ValueNotifier](https://github.com/woltapp/wolt_modal_sheet#usage) | Works with built-in Navigator API (both of imperative and declarative) | -| Scrollable content | [Supported](https://github.com/woltapp/wolt_modal_sheet#scrollable-content) | Supported | -| Persistent sheets | Not supported | Supported | -| Screen size adaptation | [The sheet appears as a dialog on large screens](https://github.com/woltapp/wolt_modal_sheet#responsive-design) | Not supported | +| | wolt_modal_sheet | smooth_sheets | +|:----------------------:|:-----------------------------------------------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------:| +| Design | Based on Wolt's [design guideline](https://careers.wolt.com/en/blog/tech/an-overview-of-the-multi-page-scrollable-bottom-sheet-ui-design) | Not restricted to a specific design, fully customizable | +| Navigation mechanism | [Manage the page index in ValueNotifier](https://github.com/woltapp/wolt_modal_sheet#usage) | Works with built-in Navigator API (both of imperative and declarative) | +| Scrollable content | [Supported](https://github.com/woltapp/wolt_modal_sheet#scrollable-content) | Supported | +| Persistent sheets | Not supported | Supported | +| Screen size adaptation | [The sheet appears as a dialog on large screens](https://github.com/woltapp/wolt_modal_sheet#responsive-design) | Not supported |
@@ -128,21 +151,27 @@ There are few packages on pub.dev that supports nested navigation with motion an Several resources are available for learning the functionalities of this package. -- Tutorials: See [example/lib/tutorial/](https://github.com/fujidaiti/smooth_sheets/tree/main/example/lib/tutorial) to learn the basic usage of the core components. -- Showcases: More practical examples are available in [example/lib/showcase/](https://github.com/fujidaiti/smooth_sheets/tree/main/example/lib/showcase). +- Tutorials: + See [example/lib/tutorial/](https://github.com/fujidaiti/smooth_sheets/tree/main/example/lib/tutorial) + to learn the basic usage of the core components. +- Showcases: More practical examples are available + in [example/lib/showcase/](https://github.com/fujidaiti/smooth_sheets/tree/main/example/lib/showcase). - Documentation: WORK IN PROGRESS! Please see the source code for a while.
## Ingredients -This section provides descriptions for each core component and links to related resources for further learning. +This section provides descriptions for each core component and links to related resources for +further learning.
-### Extent +### SheetAnchor -Extent represents the visible height of the sheet. It is used in a variety of situations, for example, to specify how much area of a sheet is initially visible at first build, or to limit the range of sheet dragging. +SheetAnchor represents the visible height of the sheet. It is used in a variety of situations, for +example, to specify how much area of a sheet is initially visible at first build, or to limit the +range of sheet dragging.
@@ -153,13 +182,15 @@ Extent represents the visible height of the sheet. It is used in a variety of si -A sheet that can be dragged. The height will be equal to the content. The behavior of the sheet when over-dragged or under-dragged is determined by [SheetPhysics](#sheetphysics). Note that this widget does not work with scrollable widgets. Instead, use [ScrollableSheet](#scrollablesheet) for this usecase. - - +A sheet that can be dragged. The height will be equal to the content. The behavior of the sheet when +over-dragged or under-dragged is determined by [SheetPhysics](#sheetphysics). Note that this widget +does not work with scrollable widgets. Instead, use [ScrollableSheet](#scrollablesheet) for this +usecase. See also: -- [draggable_sheet.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/draggable_sheet.dart) for basic usage. +- [draggable_sheet.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/draggable_sheet.dart) + for basic usage.
@@ -170,13 +201,14 @@ See also: -A sheet that is similar to [DraggableSheet](#draggablesheet), but specifically designed to be integrated with scrollable widgets. It will begin to be dragged when the content is over-scrolled or under-scrolled. - - +A sheet that is similar to [DraggableSheet](#draggablesheet), but specifically designed to be +integrated with scrollable widgets. It will begin to be dragged when the content is over-scrolled or +under-scrolled. See also: -- [scrollable_sheet.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/scrollable_sheet.dart) for basic usage. +- [scrollable_sheet.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/scrollable_sheet.dart) + for basic usage.
@@ -187,14 +219,17 @@ See also: -A sheet that is able to have multiple pages and performs graceful motion animation when page transitions. It supports both of imperative Navigator API such as `Navigator.push`, and declarative API (Navigator 2.0). - - +A sheet that is able to have multiple pages and performs graceful motion animation when page +transitions. It supports both of imperative Navigator API such as `Navigator.push`, and declarative +API (Navigator 2.0). See also: -- [declarative_navigation_sheet.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/declarative_navigation_sheet.dart), tutorial of integration with Navigator 2.0 using [go_router](https://pub.dev/packages/go_router) package. -- [imperative_navigation_sheet.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/imperative_navigation_sheet.dart), a tutorial of integration with imperative Navigator API. +- [declarative_navigation_sheet.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/declarative_navigation_sheet.dart), + tutorial of integration with Navigator 2.0 using [go_router](https://pub.dev/packages/go_router) + package. +- [imperative_navigation_sheet.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/imperative_navigation_sheet.dart), + a tutorial of integration with imperative Navigator API.
@@ -207,25 +242,34 @@ See also: -A sheet can be displayed as a modal sheet using ModalSheetRoute for imperative navigation, or ModalSheetPage for declarative navigation. To enable the *swipe-to-dismiss* action, which allows the user to dismiss the sheet by a swiping-down gesture, set `swipeDismissible` to true. +A sheet can be displayed as a modal sheet using ModalSheetRoute for imperative navigation, or +ModalSheetPage for declarative navigation. To enable the *swipe-to-dismiss* action, which allows the +user to dismiss the sheet by a swiping-down gesture, set `swipeDismissible` to true.
-Furthermore, [the modal sheets in the style of iOS 15](https://medium.com/surf-dev/bottomsheet-in-ios-15-uisheetpresentationcontroller-and-its-capabilities-5e913661c9f) are also supported. For imperative navigation, use CupertinoModalSheetRoute, and for declarative navigation, use CupertinoModalSheetPage, respectively. - - - +Furthermore, [the modal sheets in the style of iOS 15](https://medium.com/surf-dev/bottomsheet-in-ios-15-uisheetpresentationcontroller-and-its-capabilities-5e913661c9f) +are also supported. For imperative navigation, use CupertinoModalSheetRoute, and for declarative +navigation, use CupertinoModalSheetPage, respectively. See also: -- [SwipeDismissSensitivity](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/SwipeDismissSensitivity-class.html), which can be used to tweak the sensitivity of the swipe-to-dismiss action. -- [declarative_modal_sheet.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/declarative_modal_sheet.dart), a tutorial of integration with declarative navigation using [go_router](https://pub.dev/packages/go_router) package. -- [imperative_modal_sheet.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/imperative_modal_sheet.dart), a tutorial of integration with imperative Navigator API. -- [cupertino_modal_sheet.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/cupertino_modal_sheet.dart), a tutorial of iOS style modal sheets. -- [ios_style_declarative_modal_navigation_sheet.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/ios_style_declarative_modal_navigation_sheet.dart), an example of iOS-style modal NavigationSheet with go_router. -- [showcase/todo_list](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/showcase/todo_list), which uses SheetDismissible to show a confirmation dialog when the user tries to discard the todo editing sheet without saving the content. +- [SwipeDismissSensitivity](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/SwipeDismissSensitivity-class.html), + which can be used to tweak the sensitivity of the swipe-to-dismiss action. +- [declarative_modal_sheet.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/declarative_modal_sheet.dart), + a tutorial of integration with declarative navigation + using [go_router](https://pub.dev/packages/go_router) package. +- [imperative_modal_sheet.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/imperative_modal_sheet.dart), + a tutorial of integration with imperative Navigator API. +- [cupertino_modal_sheet.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/cupertino_modal_sheet.dart), + a tutorial of iOS style modal sheets. +- [ios_style_declarative_modal_navigation_sheet.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/ios_style_declarative_modal_navigation_sheet.dart), + an example of iOS-style modal NavigationSheet with go_router. +- [showcase/todo_list](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/showcase/todo_list), + which uses SheetDismissible to show a confirmation dialog when the user tries to discard the todo + editing sheet without saving the content.
@@ -236,20 +280,26 @@ See also: -A physics determines how the sheet will behave when over-dragged or under-dragged, or when the user stops dragging. There are 3 predefined physics: +A physics determines how the sheet will behave when over-dragged or under-dragged, or when the user +stops dragging. There are 3 predefined physics: - ClampingSheetPhysics: Prevents the sheet from reaching beyond the content bounds. -- BouncingSheetPhysics: Allows the sheet to go beyond the content bounds, but then bounce the sheet back to the edge of those bounds. Use [BouncingBehavior](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/BouncingBehavior-class.html) and its subclasses to tweak the bouncing behavior. -- SnappingSheetPhysics: Automatically snaps the sheet to a certain extent when the user stops dragging. - -These physics can be combined to create more complex behavior (e.g. bouncing behavior + snapping behavior). - +- BouncingSheetPhysics: Allows the sheet to go beyond the content bounds, but then bounce the sheet + back to the edge of those bounds. + Use [BouncingBehavior](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/BouncingBehavior-class.html) + and its subclasses to tweak the bouncing behavior. +- SnappingSheetPhysics: Automatically snaps the sheet to a certain extent when the user stops + dragging. +These physics can be combined to create more complex behavior (e.g. bouncing behavior + snapping +behavior). See also: -- [sheet_physics.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/sheet_physics.dart) for basic usage. -- [bouncing_behaviors.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/bouncing_behaviors.dart), which shows how to tweak the bouncing behavior of BouncingSheetPhysics. +- [sheet_physics.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/sheet_physics.dart) + for basic usage. +- [bouncing_behaviors.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/bouncing_behaviors.dart), + which shows how to tweak the bouncing behavior of BouncingSheetPhysics.
@@ -260,13 +310,13 @@ See also: -Like [ScrollController](https://api.flutter.dev/flutter/widgets/ScrollController-class.html) for scrollable widget, the SheetController can be used to animate or observe the extent of a sheet. - - +Like [ScrollController](https://api.flutter.dev/flutter/widgets/ScrollController-class.html) for +scrollable widget, the SheetController can be used to animate or observe the extent of a sheet. See also: -- [sheet_controller.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/sheet_controller.dart) for basic usage. +- [sheet_controller.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/sheet_controller.dart) + for basic usage.
@@ -277,16 +327,20 @@ See also: -A special kind of [Scaffold](https://api.flutter.dev/flutter/material/Scaffold-class.html) designed for use in a sheet. It has slots for an app bar and a bottom bar, similar to Scaffold. However, it differs in that its height reduces to fit the content widget. - - +A special kind of [Scaffold](https://api.flutter.dev/flutter/material/Scaffold-class.html) designed +for use in a sheet. It has slots for an app bar and a bottom bar, similar to Scaffold. However, it +differs in that its height reduces to fit the content widget. See also: -- [SheetContentScaffold](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/SheetContentScaffold-class.html), the API documentation. -- [BottomBarVisibility](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/BottomBarVisibility-class.html), which can be used to control the visibility of the bottom bar based on the sheet position. -- [tutorial/sheet_content_scaffold.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/sheet_content_scaffold.dart), which shows the basic usage of SheetContentScaffold. -- [tutorial/bottom_bar_visibility.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/bottom_bar_visibility.dart), which shows the basic usage of BottomBarVisibility widgets. +- [SheetContentScaffold](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/SheetContentScaffold-class.html), + the API documentation. +- [BottomBarVisibility](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/BottomBarVisibility-class.html), + which can be used to control the visibility of the bottom bar based on the sheet position. +- [tutorial/sheet_content_scaffold.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/sheet_content_scaffold.dart), + which shows the basic usage of SheetContentScaffold. +- [tutorial/bottom_bar_visibility.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/bottom_bar_visibility.dart), + which shows the basic usage of BottomBarVisibility widgets.
@@ -296,56 +350,72 @@ See also: -SheetDraggable enables its child widget to act as a drag handle for the sheet. Typically, you will want to use this widget when placing non-scrollable widget(s) in a [ScrollableSheet](#scrollablesheet), since it only works with scrollable widgets, so you can't drag the sheet by touching a non-scrollable area. Try removing SheetDraggable and you will see that the drag handle doesn't work as it should. -Note that SheetDraggable is not needed when using DraggableSheet since it implicitly wraps the child widget with SheetDraggable. - - +SheetDraggable enables its child widget to act as a drag handle for the sheet. Typically, you will +want to use this widget when placing non-scrollable widget(s) in +a [ScrollableSheet](#scrollablesheet), since it only works with scrollable widgets, so you can't +drag the sheet by touching a non-scrollable area. Try removing SheetDraggable and you will see that +the drag handle doesn't work as it should. +Note that SheetDraggable is not needed when using DraggableSheet since it implicitly wraps the child +widget with SheetDraggable. See also: -- [sheet_draggable.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/sheet_draggable.dart) for basic usage. +- [sheet_draggable.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/sheet_draggable.dart) + for basic usage.
-### ExtentDrivenAnimation +### SheetPositionDrivenAnimation
-It is easy to create sheet extent driven animations by using ExtentDrivenAnimation, a special kind of [Animation](https://api.flutter.dev/flutter/animation/Animation-class.html) whose value changes from 0 to 1 as the sheet extent changes from 'startExtent' to 'endExtent'. - - +It is easy to create sheet extent driven animations by using SheetPositionDrivenAnimation, a special +kind of [Animation](https://api.flutter.dev/flutter/animation/Animation-class.html) whose value +changes from 0 to 1 as the sheet extent changes from 'startExtent' to 'endExtent'. See also: -- [extent_driven_animation](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/extent_driven_animation.dart) for basic usage. -- [airbnb_mobile_app.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/showcase/airbnb_mobile_app.dart), which show how ExtentDrivenAnimation can be used to hide the bottom navigation bar and a FAB when the sheet is dragged down, and to show them when the sheet is dragged up again. +- [sheet_position_driven_animation](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/sheet_position_driven_animation.dart) + for basic usage. +- [airbnb_mobile_app.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/showcase/airbnb_mobile_app.dart), + which show how SheetPositionDrivenAnimation can be used to hide the bottom navigation bar and a + FAB when the sheet is dragged down, and to show them when the sheet is dragged up again.
### SheetNotification -A sheet dispatches a [SheetNotification](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/SheetNotification-class.html) when its extent changes. This can be used to observe the extent of a descendant sheet from an ancestor widget. +A sheet dispatches +a [SheetNotification](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/SheetNotification-class.html) +when its extent changes. This can be used to observe the extent of a descendant sheet from an +ancestor widget. ```dart -NotificationListener( - onNotification: (notification) { - debugPrint('${notification.metrics}'); - return false; - }, - child: DraggableSheet(...), +NotificationListener +( +onNotification: (notification) { +debugPrint('${notification.metrics}'); +return false; +}, +child: DraggableSheet(...), ), ``` - - See also: -- [SheetDragUpdateNotification](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/SheetDragUpdateNotification-class.html), which is dispatched when the sheet is dragged by the user. -- [SheetUpdateNotification](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/SheetUpdateNotification-class.html), which is dispatched when the sheet extent is updated by other than user interaction such as animation. -- [SheetOverflowNotification](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/SheetOverflowNotification-class.html), which is dispatched when the user tries to drag the sheet beyond its draggable bounds but the sheet has not changed its extent because its [SheetPhysics](#sheetphysics) does not allow it to be. -- [NotificationListener](https://api.flutter.dev/flutter/widgets/NotificationListener-class.html), which can be used to listen for the notifications in a subtree. +- [SheetDragUpdateNotification](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/SheetDragUpdateNotification-class.html), + which is dispatched when the sheet is dragged by the user. +- [SheetUpdateNotification](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/SheetUpdateNotification-class.html), + which is dispatched when the sheet extent is updated by other than user interaction such as + animation. +- [SheetOverflowNotification](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/SheetOverflowNotification-class.html), + which is dispatched when the user tries to drag the sheet beyond its draggable bounds but the + sheet has not changed its extent because its [SheetPhysics](#sheetphysics) does not allow it to + be. +- [NotificationListener](https://api.flutter.dev/flutter/widgets/NotificationListener-class.html), + which can be used to listen for the notifications in a subtree.
@@ -356,33 +426,42 @@ See also:
-[SheetKeyboardDismissBehavior](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/SheetKeyboardDismissBehavior-class.html) determines when the sheet should dismiss the on-screen keyboard. This feature is similar to [ScrollViewKeyboardDismissBehavior](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/ScrollViewKeyboardDismissBehavior.html) for scrollable widgets. - -Although it is easy to create custom behaviors by implementing SheetKeyboardDismissBehavior interface, there are 3 types of predefined behaviors for convenience. - -- [DragSheetKeyboardDismissBehavior](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/DragSheetKeyboardDismissBehavior-class.html), which always dismisses the on-screen keyboard when the sheet is dragged. -- [DragDownSheetKeyboardDismissBehavior](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/DragDownSheetKeyboardDismissBehavior-class.html), which always dismisses the on-screen keyboard only when the sheet is dragged down. -- [DragUpSheetKeyboardDismissBehavior](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/DragUpSheetKeyboardDismissBehavior-class.html), which always dismisses the on-screen keyboard only when the sheet is dragged up. +[SheetKeyboardDismissBehavior](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/SheetKeyboardDismissBehavior-class.html) +determines when the sheet should dismiss the on-screen keyboard. This feature is similar +to [ScrollViewKeyboardDismissBehavior](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/ScrollViewKeyboardDismissBehavior.html) +for scrollable widgets. +Although it is easy to create custom behaviors by implementing SheetKeyboardDismissBehavior +interface, there are 3 types of predefined behaviors for convenience. +- [DragSheetKeyboardDismissBehavior](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/DragSheetKeyboardDismissBehavior-class.html), + which always dismisses the on-screen keyboard when the sheet is dragged. +- [DragDownSheetKeyboardDismissBehavior](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/DragDownSheetKeyboardDismissBehavior-class.html), + which always dismisses the on-screen keyboard only when the sheet is dragged down. +- [DragUpSheetKeyboardDismissBehavior](https://pub.dev/documentation/smooth_sheets/latest/smooth_sheets/DragUpSheetKeyboardDismissBehavior-class.html), + which always dismisses the on-screen keyboard only when the sheet is dragged up. See also: -- [tutorial/keyboard_dismiss_behavior.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/keyboard_dismiss_behavior.dart) for basic usage. +- [tutorial/keyboard_dismiss_behavior.dart](https://github.com/fujidaiti/smooth_sheets/blob/main/example/lib/tutorial/keyboard_dismiss_behavior.dart) + for basic usage.
## Questions -If you have any questions, feel free to ask them on [the discussions page](https://github.com/fujidaiti/smooth_sheets/discussions). +If you have any questions, feel free to ask them +on [the discussions page](https://github.com/fujidaiti/smooth_sheets/discussions).
## Contributing -Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**. +Contributions are what make the open source community such an amazing place to learn, inspire, and +create. Any contributions you make are **greatly appreciated**. -If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". +If you have a suggestion that would make this better, please fork the repo and create a pull +request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again! 1. Fork the Project diff --git a/migrations/migration-guide-0.10.x.md b/migrations/migration-guide-0.10.x.md index 76efa52..71364fb 100644 --- a/migrations/migration-guide-0.10.x.md +++ b/migrations/migration-guide-0.10.x.md @@ -4,18 +4,30 @@ The changes in v0.10.0 are summarized as follows. Breaking changes are marked wi ## Changes in `SheetMetrics` :boom: -- The `double? minPixels` and `double? maxPixels` parameters in the `copyWith` method have been replaced with `Extent? minExtent` and `Extent? maxExtent`, respectively. The `minPixels` and `maxPixels` getters are still available in this version. +- The `double? minPixels` and `double? maxPixels` parameters in the `copyWith` method have been + replaced with `Extent? minPosition` and `Extent? maxPosition`, respectively. The `minPixels` + and `maxPixels` getters are still available in this version. -- `SheetMetrics` is now a mixin and can no longer be instantiated directly. Use the `SheetMetricsSnapshot` class for this purpose. +- `SheetMetrics` is now a mixin and can no longer be instantiated directly. Use + the `SheetMetricsSnapshot` class for this purpose. ## Change in `SnappingSheetBehavior` :boom: -The `findSnapPixels` method has been removed. Use `findSnapExtent` instead. +The `findSnapPixels` method has been removed. Use `findSettledPosition` instead. ## Changes in `SheetPhysics` :boom: -The `createSettlingSimulation` method has been removed in favor of the `findSettledExtent` method. As a result, `InterpolationSimulation` has also been removed since it is no longer used internally and is not a core feature of the package. +The `createSettlingSimulation` method has been removed in favor of the `findSettledPosition` method. +As a result, `InterpolationSimulation` has also been removed since it is no longer used internally +and is not a core feature of the package. ## Changes in `SheetController` :boom: -`SheetController` is no longer a notifier of `SheetMetrics`, and is now a notifier of the sheet position (`double?`) instead. It is still possible to access the `SheetMetrics` object through the `SheetController.metrics` getter. +`SheetController` is no longer a notifier of `SheetMetrics`, and is now a notifier of the sheet +position (`double?`) instead. It is still possible to access the `SheetMetrics` object through +the `SheetController.metrics` getter. + +## Changes in `Extent` :boom: + +`Extent`, `FixedExtent`, and `ProportionalExtent` have been renamed +to `SheetAnchor`, `FixedSheetAnchor`, and `ProportionalSheetAnchor`, respectively.