mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
don't break sheet's snap from physics (#171157)
Fixes https://github.com/flutter/flutter/issues/169712 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord].
This commit is contained in:
parent
bff5cb4a90
commit
77ac8dbbb0
@ -1185,6 +1185,10 @@ class _SnappingSimulation extends Simulation {
|
||||
return pixelSnapSizes.first;
|
||||
}
|
||||
final double nextSize = pixelSnapSizes[indexOfNextSize];
|
||||
// If already snapped - keep this as target size
|
||||
if (nextSize == position) {
|
||||
return nextSize;
|
||||
}
|
||||
final double previousSize = pixelSnapSizes[indexOfNextSize - 1];
|
||||
if (initialVelocity.abs() <= tolerance.velocity) {
|
||||
// If velocity is zero, snap to the nearest snap size with the minimum velocity.
|
||||
|
||||
@ -1906,4 +1906,81 @@ void main() {
|
||||
);
|
||||
expect(lastExtent, .25);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'DraggableScrollableSheet with BouncingScrollPhysics snaps when bouncing over max extent',
|
||||
(WidgetTester tester) async {
|
||||
double? lastExtent;
|
||||
|
||||
final DraggableScrollableController controller = DraggableScrollableController();
|
||||
addTearDown(controller.dispose);
|
||||
|
||||
final List<Widget> children = List<Widget>.generate(12, (int index) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: Container(color: Colors.green, height: 100, child: Text('Item $index')),
|
||||
);
|
||||
});
|
||||
children.insert(0, Container(color: Colors.green, height: 100));
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: StatefulBuilder(
|
||||
builder: (BuildContext context, StateSetter setState) {
|
||||
return Scaffold(
|
||||
body: DraggableScrollableSheet(
|
||||
initialChildSize: 0.25,
|
||||
snap: true,
|
||||
snapSizes: const <double>[0.25, 0.5, 1.0],
|
||||
controller: controller,
|
||||
builder: (BuildContext context, ScrollController scrollController) {
|
||||
return NotificationListener<DraggableScrollableNotification>(
|
||||
onNotification: (DraggableScrollableNotification notification) {
|
||||
lastExtent = notification.extent;
|
||||
return false;
|
||||
},
|
||||
child: ColoredBox(
|
||||
color: const Color(0xFFABCDEF),
|
||||
child: CustomScrollView(
|
||||
physics: const BouncingScrollPhysics(),
|
||||
controller: scrollController,
|
||||
slivers: <Widget>[
|
||||
SliverList(
|
||||
delegate: SliverChildBuilderDelegate((_, int index) {
|
||||
return children[index];
|
||||
}, childCount: children.length),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
final double itemHeight = tester.getSize(find.text('Item 0')).height;
|
||||
|
||||
controller.jumpTo(1.0);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.fling(find.text('Item 0'), Offset(0, -itemHeight), 100);
|
||||
await tester.pumpFrames(
|
||||
tester.widget(find.byType(MaterialApp)),
|
||||
const Duration(milliseconds: 500),
|
||||
);
|
||||
|
||||
await tester.fling(find.text('Item 2'), Offset(0, itemHeight), 500);
|
||||
await tester.pumpFrames(
|
||||
tester.widget(find.byType(MaterialApp)),
|
||||
const Duration(milliseconds: 500),
|
||||
);
|
||||
|
||||
expect(lastExtent, 1.0);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user