Skip to content

Conversation

@caseycrogers
Copy link
Contributor

@caseycrogers caseycrogers commented Sep 19, 2021

Currently, DraggableScrollableSheet saves copies of widget parameters (snap, minChildSize, etc.) to a private instance variable in the state object and then does not update that object when the widget is rebuilt with new parameters. This PR fixes this issue.

Additional logic is included to update the current position of the sheet if the new parameters necessitate it. eg if the sheet is at .9 and is rebuilt with a new max size of .8, the sheet will be rebuilt with a current size of .8.

This PR takes some logic from #69724
Fixes #41599

Here is a gist I made for playing around with and visualizing the new behavior.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt.
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added the framework flutter/packages/flutter repository. See also f: labels. label Sep 19, 2021
@google-cla google-cla bot added the cla: yes label Sep 19, 2021
testWidgets('Setting snapSizes to $snapSizes resolves to min and max', (WidgetTester tester) async {
const Key stackKey = ValueKey<String>('stack');
const Key containerKey = ValueKey<String>('container');
await tester.pumpWidget(_boilerplate(null,
Copy link
Contributor Author

@caseycrogers caseycrogers Sep 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not particularly related to this PR, but this code was improperly formatted.

/// Rebuilding the sheet with a new [initialChildSize] will only move the
/// the sheet to the new value if the sheet has not yet been dragged since it
/// was first built or since the last call to [DraggableScrollableActuator.reset].
///
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed like the most intuitive/desirable behavior, but I'd love some input here as this was just a judgement call.

Also see documentation changes for snap and snapSizes immediately below.

@caseycrogers caseycrogers changed the title [WIP] Make DraggableScrollableSheet Reflect Parameter Updates Make DraggableScrollableSheet Reflect Parameter Updates Sep 19, 2021
@caseycrogers
Copy link
Contributor Author

cc @dnfield could you review this for me? It adds didUpdateWidget to DSS.

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a couple nitpicks

context: context,
oldPosition: oldPosition,
extent: extent,
controller: this,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all private so it's probably not a big deal, but it seems wrong to give a position knowledge of the controller.

It would probably be better to have an abstract class like

abstract class _DraggableSheetExtentHolder {
  _DraggableSheetExtent extent;
}

and make the controller implement that, to make sure that no one comes along later and starts tinkering with controller API in the position and messes something up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about providing an anonymous function that returns extent? This feels a little lighter weight and I think makes the intent more obvious (to provide mutable state). However, the extent holder seems fine too.

I just pushed the function version, let me know if you prefer the holder version and I'll switch to it.

}

@override
_DraggableScrollableSheetScrollPosition get position =>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed so we can access .goBallistic from _replaceExtent.

super.dispose();
}

void _replaceExtent() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I named this _replaceExtent instead of _updateExtent so that it wouldn't get confused with extent.updateExtent.

@caseycrogers
Copy link
Contributor Author

@dnfield It appears this one got stuck in CI limbo too? Are we able to get it through anyway? (sorry to ping you so much, let me know if you want me to cut back on the mentions).

@dnfield
Copy link
Contributor

dnfield commented Sep 22, 2021

Looks like just google testing is waiting, which can take a bit. I added the label, if google testing doesn't complete in the next day or so we can revisit. No worries about the pings :)

@Piinks
Copy link
Contributor

Piinks commented Sep 22, 2021

(Triage) Confirmed the G testing shard passed, will manually merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DraggableScrollableSheet with dynamic height

4 participants