-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Found while implementing ensureVisible for 2D
When focus is traversing a scrollable widget, Scrollable.ensureVisible is called to bring a newly focused node into view if it is not currently. This calls ScrollPosition.ensureVisible and then RenderViewport.getOffsetToReveal.
When the default focus request callback does this, it extrapolates the ScrollPositionAlignmentPolicy (where the node should be located when it comes into view) based on the directionality of the keyboard input. This does not however account for the actual axis direction of the scrollable. The focus callback does not actually know anything about the scrollable or if one exists (ensureVisible is a static method).
In the below case, the alignment policy was being set to keepVisibleAtStart, but in the case of a reversed scrollable, this should be flipped.
Expected:
Screen.Recording.2023-06-12.at.5.51.53.PM.mov
Actual:
Screen.Recording.2023-06-12.at.5.44.07.PM.mov
import 'dart:math' as math;
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main() {
runApp(const SimpleTest());
}
class SimpleTest extends StatelessWidget {
const SimpleTest({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body:
ListView(
reverse: true,
primary: true,
children: List.generate(50, (int index) {
return SizedBox(
height: 200.0,
width: 200.0,
child: Column(
children: [
Checkbox(value: false, onChanged: (value){}),
Text(index.toString()),
],
),
);
})
),
),
);
}
}