Skip to content

Commit

Permalink
Fix: SheetController attached to NavigationSheet always emits minPixe…
Browse files Browse the repository at this point in the history
…ls = 0.0 (#164)

Fixes #163.

**New APIs**
- `ExtentScopeBuilder`

**Internal changes**
- Removed `SheetExtentConfig`, `SheetExtentFactory`, and their
subclasses.
- Accordingly, `SheetExtentScope` widgets now also take responsibility
for creating the `SheetExtent`s they host.
- Moved the responsibility for managing the scope keys of the local
`SheetExtentScope`s from `NavigationSheetExtent` to each
`NavigationSheetRoute`.

**Misc**
- Added a regression test for #163.
- Bumped the version to 0.7.2.
  • Loading branch information
fujidaiti authored Jun 9, 2024
1 parent 6b3b455 commit 0cae9c1
Show file tree
Hide file tree
Showing 26 changed files with 884 additions and 667 deletions.
5 changes: 5 additions & 0 deletions package/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.7.2 Jun 9, 2024

- Fix: Attaching SheetController to NavigationSheet causes "Null check operator used on a null value" (#151)
- Fix: SheetController attached to NavigationSheet always emits minPixels = 0.0 (#163)

## 0.7.1 Jun 1, 2024

- Fix: Unwanted bouncing effect when opening keyboard on NavigationSheet (#153)
Expand Down
20 changes: 9 additions & 11 deletions package/lib/src/draggable/draggable_sheet.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';

import '../foundation/keyboard_dismissible.dart';
Expand All @@ -8,7 +9,7 @@ import '../foundation/sheet_physics.dart';
import '../foundation/sheet_theme.dart';
import '../foundation/sheet_viewport.dart';
import '../scrollable/scrollable_sheet.dart';
import 'draggable_sheet_extent.dart';
import 'draggable_sheet_extent_scope.dart';
import 'sheet_draggable.dart';

/// A sheet that can be dragged.
Expand Down Expand Up @@ -73,17 +74,14 @@ class DraggableSheet extends StatelessWidget {
this.keyboardDismissBehavior ?? theme?.keyboardDismissBehavior;
final gestureTamper = TamperSheetGesture.maybeOf(context);

Widget result = SheetExtentScope(
Widget result = DraggableSheetExtentScope(
controller: controller,
factory: const DraggableSheetExtentFactory(),
config: DraggableSheetExtentConfig(
initialExtent: initialExtent,
minExtent: minExtent,
maxExtent: maxExtent,
physics: physics,
gestureTamperer: gestureTamper,
debugLabel: 'DraggableSheet',
),
initialExtent: initialExtent,
minExtent: minExtent,
maxExtent: maxExtent,
physics: physics,
gestureTamperer: gestureTamper,
debugLabel: kDebugMode ? 'DraggableSheet' : null,
child: SheetViewport(
child: SheetContentViewport(
child: SheetDraggable(
Expand Down
47 changes: 9 additions & 38 deletions package/lib/src/draggable/draggable_sheet_extent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,27 @@ import 'package:meta/meta.dart';
import '../foundation/sheet_extent.dart';

@internal
class DraggableSheetExtentFactory extends SheetExtentFactory<
DraggableSheetExtentConfig, DraggableSheetExtent> {
const DraggableSheetExtentFactory();

@override
DraggableSheetExtent createSheetExtent({
required SheetContext context,
required DraggableSheetExtentConfig config,
}) {
return DraggableSheetExtent(context: context, config: config);
}
}

@internal
class DraggableSheetExtentConfig extends SheetExtentConfig {
const DraggableSheetExtentConfig({
required this.initialExtent,
class DraggableSheetExtent extends SheetExtent {
DraggableSheetExtent({
required super.context,
required super.minExtent,
required super.maxExtent,
required this.initialExtent,
required super.physics,
required super.gestureTamperer,
super.gestureTamperer,
super.debugLabel,
});

/// {@template DraggableSheetExtent.initialExtent}
/// The initial extent of the sheet.
/// {@endtemplate}
final Extent initialExtent;

@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is DraggableSheetExtentConfig &&
other.initialExtent == initialExtent &&
super == other;
}

@override
int get hashCode => Object.hash(initialExtent, super.hashCode);
}

@internal
class DraggableSheetExtent extends SheetExtent<DraggableSheetExtentConfig> {
DraggableSheetExtent({
required super.context,
required super.config,
});

@override
void applyNewContentSize(Size contentSize) {
super.applyNewContentSize(contentSize);
if (metrics.maybePixels == null) {
setPixels(config.initialExtent.resolve(metrics.contentSize));
setPixels(initialExtent.resolve(metrics.contentSize));
}
}
}
55 changes: 55 additions & 0 deletions package/lib/src/draggable/draggable_sheet_extent_scope.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import 'package:meta/meta.dart';

import '../foundation/sheet_extent.dart';
import '../foundation/sheet_extent_scope.dart';
import 'draggable_sheet_extent.dart';

@internal
class DraggableSheetExtentScope extends SheetExtentScope {
const DraggableSheetExtentScope({
super.key,
super.controller,
super.isPrimary,
required this.initialExtent,
required super.minExtent,
required super.maxExtent,
required super.physics,
super.gestureTamperer,
this.debugLabel,
required super.child,
});

/// {@macro DraggableSheetExtent.initialExtent}
final Extent initialExtent;

/// {@macro SheetExtent.debugLabel}
final String? debugLabel;

@override
SheetExtentScopeState createState() {
return _DraggableSheetExtentScopeState();
}
}

class _DraggableSheetExtentScopeState extends SheetExtentScopeState<
DraggableSheetExtent, DraggableSheetExtentScope> {
@override
bool shouldRebuildExtent(DraggableSheetExtent oldExtent) {
return widget.initialExtent != oldExtent.initialExtent ||
widget.debugLabel != oldExtent.debugLabel ||
super.shouldRebuildExtent(oldExtent);
}

@override
DraggableSheetExtent buildExtent(SheetContext context) {
return DraggableSheetExtent(
context: context,
initialExtent: widget.initialExtent,
minExtent: widget.minExtent,
maxExtent: widget.maxExtent,
physics: widget.physics,
gestureTamperer: widget.gestureTamperer,
debugLabel: widget.debugLabel,
);
}
}
1 change: 1 addition & 0 deletions package/lib/src/draggable/sheet_draggable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/widgets.dart';

import '../foundation/sheet_extent.dart';
import '../foundation/sheet_extent_scope.dart';
import '../scrollable/scrollable_sheet.dart';
import 'draggable_sheet.dart';

Expand Down
2 changes: 1 addition & 1 deletion package/lib/src/foundation/sheet_activity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class DragSheetActivity extends SheetActivity
@override
void applyUserDragUpdate(Offset offset) {
final physicsAppliedDelta =
owner.config.physics.applyPhysicsToOffset(offset.dy, owner.metrics);
owner.physics.applyPhysicsToOffset(offset.dy, owner.metrics);
if (physicsAppliedDelta != 0) {
owner.setPixels(owner.metrics.pixels + physicsAppliedDelta);
}
Expand Down
1 change: 1 addition & 0 deletions package/lib/src/foundation/sheet_content_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/rendering.dart';

import '../draggable/sheet_draggable.dart';
import 'sheet_extent.dart';
import 'sheet_extent_scope.dart';
import 'sheet_viewport.dart';

class SheetContentScaffold extends StatelessWidget {
Expand Down
Loading

0 comments on commit 0cae9c1

Please sign in to comment.