Skip to content

Commit 9056c0b

Browse files
authored
made SelectionArea alignment consistent between web and other platform (flutter#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 flutter#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 flutter#148934 Fixes flutter#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].*
1 parent a3f6a2b commit 9056c0b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/flutter/lib/src/widgets/_platform_selectable_region_context_menu_web.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ class PlatformSelectableRegionContextMenu extends StatelessWidget {
135135
@override
136136
Widget build(BuildContext context) {
137137
return Stack(
138-
alignment: Alignment.center,
139138
children: <Widget>[
140139
const Positioned.fill(
141140
child: HtmlElementView(

packages/flutter/test/widgets/selectable_region_test.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3594,6 +3594,27 @@ void main() {
35943594
skip: kIsWeb, // [intended] Web uses its native context menu.
35953595
);
35963596

3597+
// Regression test for https://github.com/flutter/flutter/issues/121053.
3598+
testWidgets('Ensure SelectionArea does not affect the layout of its children', (WidgetTester tester) async {
3599+
await tester.pumpWidget(
3600+
const MaterialApp(
3601+
home: Column(
3602+
crossAxisAlignment: CrossAxisAlignment.stretch,
3603+
children: <Widget>[
3604+
SelectionArea(child: Text('row 1')),
3605+
Text('row 2'),
3606+
],
3607+
),
3608+
),
3609+
);
3610+
await tester.pumpAndSettle();
3611+
final double xOffset1 = tester.getTopLeft(find.text('row 1')).dx;
3612+
final double xOffset2 = tester.getTopLeft(find.text('row 2')).dx;
3613+
expect(xOffset1, xOffset2);
3614+
},
3615+
variant: TargetPlatformVariant.all(),
3616+
);
3617+
35973618
testWidgets('the selection behavior when clicking `Copy` item in mobile platforms', (WidgetTester tester) async {
35983619
List<ContextMenuButtonItem> buttonItems = <ContextMenuButtonItem>[];
35993620
final FocusNode focusNode = FocusNode();

0 commit comments

Comments
 (0)