mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Fix draggable scrollable sheet scroll notification (#45083)
This commit is contained in:
parent
5fb790e6ed
commit
a3eeb51a1b
@ -490,6 +490,8 @@ class _DraggableScrollableSheetScrollPosition
|
|||||||
velocity = ballisticController.velocity + (physics.tolerance.velocity * ballisticController.velocity.sign);
|
velocity = ballisticController.velocity + (physics.tolerance.velocity * ballisticController.velocity.sign);
|
||||||
super.goBallistic(velocity);
|
super.goBallistic(velocity);
|
||||||
ballisticController.stop();
|
ballisticController.stop();
|
||||||
|
} else if (ballisticController.isCompleted) {
|
||||||
|
super.goBallistic(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ void main() {
|
|||||||
double minChildSize = .25,
|
double minChildSize = .25,
|
||||||
double itemExtent,
|
double itemExtent,
|
||||||
Key containerKey,
|
Key containerKey,
|
||||||
|
NotificationListenerCallback<ScrollNotification> onScrollNotification,
|
||||||
}) {
|
}) {
|
||||||
return Directionality(
|
return Directionality(
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
@ -29,14 +30,17 @@ void main() {
|
|||||||
minChildSize: minChildSize,
|
minChildSize: minChildSize,
|
||||||
initialChildSize: initialChildSize,
|
initialChildSize: initialChildSize,
|
||||||
builder: (BuildContext context, ScrollController scrollController) {
|
builder: (BuildContext context, ScrollController scrollController) {
|
||||||
return Container(
|
return NotificationListener<ScrollNotification>(
|
||||||
key: containerKey,
|
onNotification: onScrollNotification,
|
||||||
color: const Color(0xFFABCDEF),
|
child: Container(
|
||||||
child: ListView.builder(
|
key: containerKey,
|
||||||
controller: scrollController,
|
color: const Color(0xFFABCDEF),
|
||||||
itemExtent: itemExtent,
|
child: ListView.builder(
|
||||||
itemCount: itemCount,
|
controller: scrollController,
|
||||||
itemBuilder: (BuildContext context, int index) => Text('Item $index'),
|
itemExtent: itemExtent,
|
||||||
|
itemCount: itemCount,
|
||||||
|
itemBuilder: (BuildContext context, int index) => Text('Item $index'),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -260,5 +264,49 @@ void main() {
|
|||||||
|
|
||||||
debugDefaultTargetPlatformOverride = null;
|
debugDefaultTargetPlatformOverride = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('ScrollNotification correctly dispatched when flung without covering its container', (WidgetTester tester) async {
|
||||||
|
final List<Type> notificationTypes = <Type>[];
|
||||||
|
await tester.pumpWidget(_boilerplate(
|
||||||
|
null,
|
||||||
|
onScrollNotification: (ScrollNotification notification) {
|
||||||
|
notificationTypes.add(notification.runtimeType);
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
|
await tester.fling(find.text('Item 1'), const Offset(0, -200), 200);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
// TODO(itome): Make sure UserScrollNotification and ScrollUpdateNotification are called correctly.
|
||||||
|
final List<Type> types = <Type>[
|
||||||
|
ScrollStartNotification,
|
||||||
|
ScrollEndNotification,
|
||||||
|
];
|
||||||
|
expect(notificationTypes, equals(types));
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('ScrollNotification correctly dispatched when flung with contents scroll', (WidgetTester tester) async {
|
||||||
|
final List<Type> notificationTypes = <Type>[];
|
||||||
|
await tester.pumpWidget(_boilerplate(
|
||||||
|
null,
|
||||||
|
onScrollNotification: (ScrollNotification notification) {
|
||||||
|
notificationTypes.add(notification.runtimeType);
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
|
await tester.flingFrom(const Offset(0, 325), const Offset(0, -325), 200);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
final List<Type> types = <Type>[
|
||||||
|
ScrollStartNotification,
|
||||||
|
UserScrollNotification,
|
||||||
|
...List<Type>.filled(5, ScrollUpdateNotification),
|
||||||
|
ScrollEndNotification,
|
||||||
|
UserScrollNotification,
|
||||||
|
];
|
||||||
|
expect(notificationTypes, types);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user