made SelectionArea alignment consistent between web and other platform (#150037)

Currently, when text is placed inside a SelectionArea widget that's nested within a Column widget, it results in misalignment, causing the text to appear centered instead of aligned as intended.

This was originally #149552 but had issues with my branch.

*List which issues are fixed by this PR. You must list at least one issue. An issue is not required if the PR fixes something trivial like a typo.*
Fixes #148934 
Fixes #121053 

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
This commit is contained in:
Limane Gaya 2024-06-21 18:41:14 +02:00 committed by GitHub
parent a3f6a2bdc7
commit 9056c0b192
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View file

@ -135,7 +135,6 @@ class PlatformSelectableRegionContextMenu extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Stack(
alignment: Alignment.center,
children: <Widget>[
const Positioned.fill(
child: HtmlElementView(

View file

@ -3594,6 +3594,27 @@ void main() {
skip: kIsWeb, // [intended] Web uses its native context menu.
);
// Regression test for https://github.com/flutter/flutter/issues/121053.
testWidgets('Ensure SelectionArea does not affect the layout of its children', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
home: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
SelectionArea(child: Text('row 1')),
Text('row 2'),
],
),
),
);
await tester.pumpAndSettle();
final double xOffset1 = tester.getTopLeft(find.text('row 1')).dx;
final double xOffset2 = tester.getTopLeft(find.text('row 2')).dx;
expect(xOffset1, xOffset2);
},
variant: TargetPlatformVariant.all(),
);
testWidgets('the selection behavior when clicking `Copy` item in mobile platforms', (WidgetTester tester) async {
List<ContextMenuButtonItem> buttonItems = <ContextMenuButtonItem>[];
final FocusNode focusNode = FocusNode();