Skip to content

Commit

Permalink
Fix: Unable to build version 0.6.0 for Flutter versions < 3.22.0 (#146)
Browse files Browse the repository at this point in the history
Fixes #144.

- `SheetDragDetails` subclasses no longer implement `Drag*Details`
- Bumped to 0.7.0
- Added a migration guide
  • Loading branch information
fujidaiti authored May 30, 2024
1 parent d600a6c commit d044cd7
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 78 deletions.
7 changes: 7 additions & 0 deletions docs/migration-guide-0.7.x.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Migration guide to 0.7.x from 0.6.x

Here is the summary of the breaking changes included in version 0.7.0.

- `SheetDragStartDetails` no longer implements `DragStartDetails`
- `SheetDragUpdateDetails` no longer implements `DragUpdateDetails`
- `SheetDragEndDetails` no longer implements `DragEndDetails`
6 changes: 6 additions & 0 deletions package/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.7.0 May 30, 2024

This version contains some breaking changes. See the [migration guide](https://github.com/fujidaiti/smooth_sheets/blob/main/docs/migration-guide-0.7.x.md) for more details.

- Fix: Unable to build with Flutter versions `< 3.22.0` (#141)

## 0.6.0 May 26, 2024

This version contains some breaking changes. See the [migration guide](https://github.com/fujidaiti/smooth_sheets/blob/main/docs/migration-guide-0.6.x.md) for more details.
Expand Down
4 changes: 2 additions & 2 deletions package/lib/src/foundation/keyboard_dismissible.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class SheetKeyboardDismissible extends StatelessWidget {
Widget result = NotificationListener<SheetDragUpdateNotification>(
onNotification: (notification) {
final delta = switch (notification.dragDetails.axisDirection) {
VerticalDirection.up => notification.dragDetails.primaryDelta,
VerticalDirection.down => -1 * notification.dragDetails.primaryDelta,
VerticalDirection.up => notification.dragDetails.deltaY,
VerticalDirection.down => -1 * notification.dragDetails.deltaY,
};

if (primaryFocus?.hasFocus == true &&
Expand Down
136 changes: 72 additions & 64 deletions package/lib/src/foundation/sheet_drag.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,33 @@ sealed class SheetDragDetails {
/// Const constructor to allow subclasses to be const.
SheetDragDetails({
required this.axisDirection,
});

/// The direction in which the drag is occurring.
final VerticalDirection axisDirection;
}

/// Details for the start of a sheet drag.
///
/// Contains information about the starting position and velocity of the drag.
class SheetDragStartDetails extends SheetDragDetails {
/// Creates details for the start of a sheet drag.
SheetDragStartDetails({
required super.axisDirection,
required this.localPositionX,
required this.localPositionY,
required this.globalPositionX,
required this.globalPositionY,
this.sourceTimeStamp,
this.kind,
});

/// The direction in which the drag is occurring.
final VerticalDirection axisDirection;
/// Recorded timestamp of the source pointer event that
/// triggered the drag events.
final Duration? sourceTimeStamp;

/// The kind of the device that initiated the event.
final PointerDeviceKind? kind;

/// The local x position in the coordinate system of the event receiver
/// at which the pointer contacted the screen.
Expand All @@ -46,29 +65,6 @@ sealed class SheetDragDetails {
Offset get globalPosition => _globalPosition;
// Lazily initialized to avoid unnecessary object creation.
late final _globalPosition = Offset(globalPositionX, globalPositionY);
}

/// Details for the start of a sheet drag.
///
/// Contains information about the starting position and velocity of the drag.
class SheetDragStartDetails extends SheetDragDetails
implements DragStartDetails {
/// Creates details for the start of a sheet drag.
SheetDragStartDetails({
required super.axisDirection,
required super.localPositionX,
required super.localPositionY,
required super.globalPositionX,
required super.globalPositionY,
this.sourceTimeStamp,
this.kind,
});

@override
final Duration? sourceTimeStamp;

@override
final PointerDeviceKind? kind;

/// Creates a copy of this object but with the given fields
/// replaced with the new values.
Expand Down Expand Up @@ -97,37 +93,60 @@ class SheetDragStartDetails extends SheetDragDetails
///
/// This class contains information about the current state of
/// a sheet drag gesture, such as the position and velocity of the drag.
class SheetDragUpdateDetails extends SheetDragDetails
implements DragUpdateDetails {
class SheetDragUpdateDetails extends SheetDragDetails {
/// Creates details for the update of a sheet drag.
SheetDragUpdateDetails({
required super.axisDirection,
required super.localPositionX,
required super.localPositionY,
required super.globalPositionX,
required super.globalPositionY,
required this.localPositionX,
required this.localPositionY,
required this.globalPositionX,
required this.globalPositionY,
required this.deltaX,
required this.deltaY,
this.sourceTimeStamp,
});

@override
/// Recorded timestamp of the source pointer event that
/// triggered the drag events.
final Duration? sourceTimeStamp;

/// The local x position in the coordinate system of the event receiver
/// at which the pointer contacted the screen.
final double localPositionX;

/// The local y position in the coordinate system of the event receiver
/// at which the pointer contacted the screen.
final double localPositionY;

/// The global x position at which the pointer contacted the screen.
final double globalPositionX;

/// The global y position at which the pointer contacted the screen.
final double globalPositionY;

/// The local position in the coordinate system of the event receiver
/// at which the pointer contacted the screen.
Offset get localPosition => _localPosition;
// Lazily initialized to avoid unnecessary object creation.
late final _localPosition = Offset(localPositionX, localPositionY);

/// The global position at which the pointer contacted the screen.
Offset get globalPosition => _globalPosition;
// Lazily initialized to avoid unnecessary object creation.
late final _globalPosition = Offset(globalPositionX, globalPositionY);

/// The horizontal distance the pointer has moved since the last update.
final double deltaX;

/// The vertical distance the pointer has moved since the last update.
final double deltaY;

@override
/// The amount the pointer has moved in the coordinate space
/// of the event receiver since the previous update.
Offset get delta => _delta;
// Lazily initialized to avoid unnecessary object creation.
late final _delta = Offset(deltaX, deltaY);

@override
double get primaryDelta => deltaY;

/// Creates a copy of this object but with the given fields
/// replaced with the new values.
SheetDragUpdateDetails copyWith({
Expand Down Expand Up @@ -157,14 +176,10 @@ class SheetDragUpdateDetails extends SheetDragDetails
///
/// Contains information about the drag end, such as
/// the velocity at which the drag ended.
class SheetDragEndDetails extends SheetDragDetails implements DragEndDetails {
class SheetDragEndDetails extends SheetDragDetails {
/// Creates details for the end of a sheet drag.
SheetDragEndDetails({
required super.axisDirection,
required super.localPositionX,
required super.localPositionY,
required super.globalPositionX,
required super.globalPositionY,
required this.velocityX,
required this.velocityY,
});
Expand All @@ -177,33 +192,22 @@ class SheetDragEndDetails extends SheetDragDetails implements DragEndDetails {
/// when the drag ended in logical pixels per second.
final double velocityY;

@override
/// The velocity the pointer was moving when it stopped contacting the screen.
Velocity get velocity => _velocity;
// Lazily initialized to avoid unnecessary object creation.
late final _velocity = Velocity(
pixelsPerSecond: Offset(velocityX, velocityY),
);

@override
double get primaryVelocity => velocityY;

/// Creates a copy of this object but with the given fields
/// replaced with the new values.
SheetDragEndDetails copyWith({
VerticalDirection? axisDirection,
double? localPositionX,
double? localPositionY,
double? globalPositionX,
double? globalPositionY,
double? velocityX,
double? velocityY,
}) {
return SheetDragEndDetails(
axisDirection: axisDirection ?? this.axisDirection,
localPositionX: localPositionX ?? this.localPositionX,
localPositionY: localPositionY ?? this.localPositionY,
globalPositionX: globalPositionX ?? this.globalPositionX,
globalPositionY: globalPositionY ?? this.globalPositionY,
velocityX: velocityX ?? this.velocityX,
velocityY: velocityY ?? this.velocityY,
);
Expand Down Expand Up @@ -267,6 +271,8 @@ class SheetDragController implements Drag, ScrollActivityDelegate {
SheetDragDetails _lastDetails;
SheetDragDetails get lastDetails => _lastDetails;

dynamic get lastRawDetails => _impl.lastDetails;

void updateTarget(SheetDragControllerTarget delegate) {
_target = delegate;
}
Expand All @@ -293,17 +299,19 @@ class SheetDragController implements Drag, ScrollActivityDelegate {
/// Called by the [ScrollDragController] in [Drag.end] and [Drag.cancel].
@override
void goBallistic(double velocity) {
assert(_impl.lastDetails is DragEndDetails);
final rawDetails = _impl.lastDetails as DragEndDetails;
var details = SheetDragEndDetails(
axisDirection: _target!.dragAxisDirection,
localPositionX: rawDetails.localPosition.dx,
localPositionY: rawDetails.localPosition.dy,
globalPositionX: rawDetails.globalPosition.dx,
globalPositionY: rawDetails.globalPosition.dy,
velocityX: rawDetails.velocity.pixelsPerSecond.dx,
velocityY: -1 * velocity,
);
var details = switch (_impl.lastDetails) {
final DragEndDetails details => SheetDragEndDetails(
axisDirection: _target!.dragAxisDirection,
velocityX: details.velocity.pixelsPerSecond.dx,
velocityY: -1 * velocity,
),
// Drag was canceled.
_ => SheetDragEndDetails(
axisDirection: _target!.dragAxisDirection,
velocityX: 0,
velocityY: 0,
),
};

if (_gestureTamperer case final tamper?) {
details = tamper.tamperWithDragEnd(details);
Expand Down
2 changes: 1 addition & 1 deletion package/lib/src/scrollable/scrollable_sheet_extent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class ScrollableSheetExtent extends SheetExtent<ScrollableSheetExtentConfig>
scrollPosition.beginActivity(
SheetContentDragScrollActivity(
delegate: scrollPosition,
getLastDragDetails: () => currentDrag?.lastDetails,
getLastDragDetails: () => currentDrag?.lastRawDetails,
getPointerDeviceKind: () => currentDrag?.pointerDeviceKind,
),
);
Expand Down
19 changes: 9 additions & 10 deletions package/lib/src/scrollable/sheet_content_scroll_activity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:meta/meta.dart';

import '../foundation/sheet_drag.dart';
import 'scrollable_sheet_activity.dart';
import 'sheet_content_scroll_position.dart';

Expand All @@ -22,7 +21,7 @@ class SheetContentDragScrollActivity extends ScrollActivity {
required this.getPointerDeviceKind,
}) : super(delegate);

final ValueGetter<SheetDragDetails?> getLastDragDetails;
final ValueGetter<dynamic> getLastDragDetails;
final ValueGetter<PointerDeviceKind?> getPointerDeviceKind;

@override
Expand All @@ -31,7 +30,7 @@ class SheetContentDragScrollActivity extends ScrollActivity {
BuildContext? context,
) {
final lastDetails = getLastDragDetails();
if (lastDetails is SheetDragStartDetails) {
if (lastDetails is DragStartDetails) {
ScrollStartNotification(
metrics: metrics,
context: context,
Expand All @@ -40,7 +39,7 @@ class SheetContentDragScrollActivity extends ScrollActivity {
} else {
assert(() {
throw FlutterError(
'Expected to have a $SheetDragStartDetails, but got $lastDetails.',
'Expected to have a $DragStartDetails, but got $lastDetails.',
);
}());
}
Expand All @@ -53,7 +52,7 @@ class SheetContentDragScrollActivity extends ScrollActivity {
double scrollDelta,
) {
final lastDetails = getLastDragDetails();
if (lastDetails is SheetDragUpdateDetails) {
if (lastDetails is DragUpdateDetails) {
ScrollUpdateNotification(
metrics: metrics,
context: context,
Expand All @@ -63,7 +62,7 @@ class SheetContentDragScrollActivity extends ScrollActivity {
} else {
assert(() {
throw FlutterError(
'Expected to have a $SheetDragUpdateDetails, but got $lastDetails.',
'Expected to have a $DragUpdateDetails, but got $lastDetails.',
);
}());
}
Expand All @@ -76,7 +75,7 @@ class SheetContentDragScrollActivity extends ScrollActivity {
double overscroll,
) {
final lastDetails = getLastDragDetails();
if (lastDetails is SheetDragUpdateDetails) {
if (lastDetails is DragUpdateDetails) {
OverscrollNotification(
metrics: metrics,
context: context,
Expand All @@ -86,7 +85,7 @@ class SheetContentDragScrollActivity extends ScrollActivity {
} else {
assert(() {
throw FlutterError(
'Expected to have a $SheetDragUpdateDetails, but got $lastDetails.',
'Expected to have a $DragUpdateDetails, but got $lastDetails.',
);
}());
}
Expand All @@ -98,7 +97,7 @@ class SheetContentDragScrollActivity extends ScrollActivity {
BuildContext context,
) {
final lastDetails = getLastDragDetails();
if (lastDetails is SheetDragEndDetails) {
if (lastDetails is DragEndDetails?) {
ScrollEndNotification(
metrics: metrics,
context: context,
Expand All @@ -107,7 +106,7 @@ class SheetContentDragScrollActivity extends ScrollActivity {
} else {
assert(() {
throw FlutterError(
'Expected to have a $SheetDragEndDetails, but got $lastDetails.',
'Expected to have a $DragEndDetails?, but got $lastDetails.',
);
}());
}
Expand Down
2 changes: 1 addition & 1 deletion package/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: smooth_sheets
description: Sheet widgets with smooth motion and great flexibility. Also supports nested navigation in both imperative and declarative ways.
version: 0.6.0
version: 0.7.0
repository: https://github.com/fujidaiti/smooth_sheets
screenshots:
- description: Practical examples of smooth_sheets.
Expand Down

0 comments on commit d044cd7

Please sign in to comment.