-
Notifications
You must be signed in to change notification settings - Fork 28.9k
feat(FixedExtentScrollController): Add parent class properties to the constructor. #163190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,6 +117,80 @@ void main() { | |
expect(detach, 1); | ||
}); | ||
|
||
// Regression test for https://github.com/flutter/flutter/issues/162972 | ||
testWidgets('FixedExtentScrollController keepScrollOffset', (WidgetTester tester) async { | ||
final PageStorageBucket bucket = PageStorageBucket(); | ||
|
||
Widget buildFrame(ScrollController controller) { | ||
return Directionality( | ||
textDirection: TextDirection.ltr, | ||
child: PageStorage( | ||
bucket: bucket, | ||
child: KeyedSubtree( | ||
key: const PageStorageKey<String>('ListWheelScrollView'), | ||
child: ListWheelScrollView( | ||
key: UniqueKey(), | ||
itemExtent: 100.0, | ||
controller: controller, | ||
children: | ||
List<Widget>.generate(100, (int index) { | ||
return SizedBox(height: 100.0, width: 400.0, child: Text('Item $index')); | ||
}).toList(), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
|
||
FixedExtentScrollController controller = FixedExtentScrollController(initialItem: 2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this test, to check that keep scroll offset is working, can you check the actual scroll offset, controller.offset? I might check the existing tests for ScrollController.keepScrollOffset for comparison. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course, I have updated it. |
||
addTearDown(controller.dispose); | ||
await tester.pumpWidget(buildFrame(controller)); | ||
expect(controller.selectedItem, 2); | ||
expect(controller.offset, 200.0); | ||
expect( | ||
tester.getTopLeft(find.widgetWithText(SizedBox, 'Item 2')), | ||
offsetMoreOrLessEquals(const Offset(200.0, 250.0)), | ||
); | ||
|
||
controller.jumpToItem(20); | ||
await tester.pump(); | ||
expect(controller.selectedItem, 20); | ||
expect(controller.offset, 2000.0); | ||
expect( | ||
tester.getTopLeft(find.widgetWithText(SizedBox, 'Item 20')), | ||
offsetMoreOrLessEquals(const Offset(200.0, 250.0)), | ||
); | ||
|
||
controller = FixedExtentScrollController(initialItem: 25); | ||
addTearDown(controller.dispose); | ||
await tester.pumpWidget(buildFrame(controller)); | ||
expect(controller.selectedItem, 20); | ||
expect(controller.offset, 2000.0); | ||
expect( | ||
tester.getTopLeft(find.widgetWithText(SizedBox, 'Item 20')), | ||
offsetMoreOrLessEquals(const Offset(200.0, 250.0)), | ||
); | ||
|
||
controller = FixedExtentScrollController(keepScrollOffset: false, initialItem: 10); | ||
addTearDown(controller.dispose); | ||
await tester.pumpWidget(buildFrame(controller)); | ||
expect(controller.selectedItem, 10); | ||
expect(controller.offset, 1000.0); | ||
expect( | ||
tester.getTopLeft(find.widgetWithText(SizedBox, 'Item 10')), | ||
offsetMoreOrLessEquals(const Offset(200.0, 250.0)), | ||
); | ||
}); | ||
|
||
// Regression test for https://github.com/flutter/flutter/issues/162972 | ||
test('FixedExtentScrollController debugLabel', () { | ||
final FixedExtentScrollController controller = FixedExtentScrollController( | ||
debugLabel: 'MyCustomWidget', | ||
); | ||
expect(controller.debugLabel, 'MyCustomWidget'); | ||
expect(controller.toString(), contains('MyCustomWidget')); | ||
}); | ||
|
||
testWidgets('ListWheelScrollView needs positive magnification', (WidgetTester tester) async { | ||
expect(() { | ||
ListWheelScrollView( | ||
|
Uh oh!
There was an error while loading. Please reload this page.