Unverified Commit c815aaed authored by Mahesh Jamdade's avatar Mahesh Jamdade Committed by GitHub

adds `isAttached` getter to DraggableScrollableController (#100269)

parent 33d14352
...@@ -71,6 +71,14 @@ class DraggableScrollableController extends ChangeNotifier { ...@@ -71,6 +71,14 @@ class DraggableScrollableController extends ChangeNotifier {
return _attachedController!.extent.sizeToPixels(size); return _attachedController!.extent.sizeToPixels(size);
} }
/// Returns Whether any [DraggableScrollableController] objects have attached themselves to the
/// [DraggableScrollableSheet].
///
/// If this is false, then members that interact with the [ScrollPosition],
/// such as [sizeToPixels], [size], [animateTo], and [jumpTo], must not be
/// called.
bool get isAttached => _attachedController != null && _attachedController!.hasClients;
/// Convert a sheet's pixel height to size (fractional value of parent container height). /// Convert a sheet's pixel height to size (fractional value of parent container height).
double pixelsToSize(double pixels) { double pixelsToSize(double pixels) {
_assertAttached(); _assertAttached();
...@@ -157,7 +165,7 @@ class DraggableScrollableController extends ChangeNotifier { ...@@ -157,7 +165,7 @@ class DraggableScrollableController extends ChangeNotifier {
void _assertAttached() { void _assertAttached() {
assert( assert(
_attachedController != null, isAttached,
'DraggableScrollableController is not attached to a sheet. A DraggableScrollableController ' 'DraggableScrollableController is not attached to a sheet. A DraggableScrollableController '
'must be used in a DraggableScrollableSheet before any of its methods are called.', 'must be used in a DraggableScrollableSheet before any of its methods are called.',
); );
......
...@@ -1195,4 +1195,18 @@ void main() { ...@@ -1195,4 +1195,18 @@ void main() {
// Can't use animateTo with a zero duration. // Can't use animateTo with a zero duration.
expect(() => controller.animateTo(.5, duration: Duration.zero, curve: Curves.linear), throwsAssertionError); expect(() => controller.animateTo(.5, duration: Duration.zero, curve: Curves.linear), throwsAssertionError);
}); });
testWidgets('DraggableScrollableController must be attached before using any of its paramters', (WidgetTester tester) async {
final DraggableScrollableController controller = DraggableScrollableController();
expect(controller.isAttached, false);
expect(()=>controller.size, throwsAssertionError);
final Widget boilerplate = _boilerplate(
null,
minChildSize: 0.4,
controller: controller,
);
await tester.pumpWidget(boilerplate);
expect(controller.isAttached, true);
expect(controller.size, isNotNull);
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment