-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listcustomer: googleVarious Google teamsVarious Google teamsd: api docsIssues with https://api.flutter.dev/Issues with https://api.flutter.dev/f: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.
Description
Steps to Reproduce
Steps
- Render a scrollable container with
ListViewand aScrollController. - Listen to events on
ScrollController(e.g. viaaddListener). - Scroll the content all the way to the end. Observe that all events are fired.
- Shrink the content so that the
ScrollControlleris updated to the reducedmaxScrollExtent.
Expected results: ScrollController should notify that it was changed.
Actual results: It doesn't.
Here's a unit test that demonstrates it -- the last expectation fails.
I ran this as a flutter-web integration test.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
const _viewportWidth = 300.0;
class FooApp extends StatelessWidget {
final ScrollController scrollController;
final ValueNotifier<double> contentWidth;
FooApp(this.scrollController, this.contentWidth);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Material(
child: Wrap(
children: [
Container(
height: 40,
width: _viewportWidth,
child: ListView(
controller: scrollController,
scrollDirection: Axis.horizontal,
shrinkWrap: true,
children: [
ValueListenableBuilder(
valueListenable: contentWidth,
builder: (context, contentWidth, _) =>
SizedBox(height: 40, width: contentWidth),
),
],
),
),
],
),
),
);
}
}
void main() {
group('Scroll issues', () {
testWidgets(
'No scroll notification when scroll offset changes due to content shrinking',
(tester) async {
final contentWidth = ValueNotifier(500.0);
final scrollController = ScrollController();
// Listen to [scrollController] update notifications.
var scrollOffset = 0.0;
scrollController
.addListener(() => scrollOffset = scrollController.offset);
await tester.pumpWidget(FooApp(scrollController, contentWidth));
// When moving the scroll controller all the way to the end.
scrollController.jumpTo(scrollController.position.maxScrollExtent);
var expectedScrollPosition = contentWidth.value - _viewportWidth;
await tester.pumpAndSettle();
expect(scrollController.offset, expectedScrollPosition,
reason: 'Expect scrollController to update to scroll to the end.');
expect(scrollOffset, expectedScrollPosition,
reason: 'Expect scrollController to have broadcast notifications.');
// When shrinking the content so that the maxScrollExtent decreases.
contentWidth.value -= 100;
expectedScrollPosition = contentWidth.value - _viewportWidth;
// Wait as long as needed for everything to settle.
await tester.pumpAndSettle();
await tester.pumpAndSettle();
await tester.pumpAndSettle();
expect(scrollController.offset, expectedScrollPosition,
reason: 'Expect scrollController to update to the new end.');
// >>>>>>>>>> FAILS HERE: <<<<<<<<<<
expect(scrollOffset, expectedScrollPosition,
reason: 'Expect scrollController to have broadcast a notification.');
});
});
}Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listcustomer: googleVarious Google teamsVarious Google teamsd: api docsIssues with https://api.flutter.dev/Issues with https://api.flutter.dev/f: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.
Type
Projects
Status
Done