-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Labels
f: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.found in release: 1.22Found to occur in 1.22Found to occur in 1.22frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work on
Description
Steps to Reproduce
- Run the sample app below. It creates a grid of cells using a
ColumnofRows and twoSingleChildScrollViews--one forAxis.horizontaland the other forAxis.vertical.
Expected results:
Tapping any cell should center that cell in the viewport via ensureVisible.
Scrollable.ensureVisible(context,
alignment: .5,
duration: Duration(
milliseconds: 500,
));Actual results:
Cells are not centered as expected. This works correctly when using just a single SingleChildScrollView but not with two.
ensureVisible does traverse all the Scrollables in the context:
flutter/packages/flutter/lib/src/widgets/scrollable.dart
Lines 312 to 323 in a8281e3
| ScrollableState scrollable = Scrollable.of(context); | |
| while (scrollable != null) { | |
| futures.add(scrollable.position.ensureVisible( | |
| context.findRenderObject(), | |
| alignment: alignment, | |
| duration: duration, | |
| curve: curve, | |
| alignmentPolicy: alignmentPolicy, | |
| )); | |
| context = scrollable.context; | |
| scrollable = Scrollable.of(context); | |
| } |
But something about nesting the scrollviews will yield different values here:
| RevealedOffset getOffsetToReveal(RenderObject target, double alignment, { Rect rect }) { |
This behavior has been present since 2019 and is reproducible on the latest beta branch on both iOS and Android.
import 'package:flutter/material.dart';
void main() async {
runApp(
MaterialApp(
home: Scaffold(
body: Grid(),
),
),
);
}
class Grid extends StatelessWidget {
@override
Widget build(BuildContext context) {
List<Row> rows = List.generate(
15,
(y) => Row(
children: List.generate(
12,
(x) => Cell(
child: Text("$x,$y"),
),
),
),
);
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
children: rows,
),
),
);
}
}
class Cell extends StatelessWidget {
final Widget child;
const Cell({
this.child,
});
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () {
Scrollable.ensureVisible(context,
alignment: .5,
duration: Duration(
milliseconds: 500,
));
},
child: Container(
width: 100,
height: 100,
color: Colors.grey.withOpacity(.2),
margin: EdgeInsets.all(3),
child: Center(
child: child,
),
),
);
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
f: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.found in release: 1.22Found to occur in 1.22Found to occur in 1.22frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work on
