Skip to content

Commit 815beaf

Browse files
authored
[url_launcher_web] Fix Link misalignment issue (flutter#3476)
The Link widget builds a Stack on the web. The Stack by default loosens the constraints passed by the parent. This is what was causing the misalignment. In order to fix it, we just need to pass fit: StackFit.passthrough to the Stack.
1 parent 8c9ad11 commit 815beaf

File tree

6 files changed

+44
-2
lines changed

6 files changed

+44
-2
lines changed

packages/url_launcher/url_launcher_web/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.1.5+3
2+
3+
- Fix Link misalignment [issue](https://github.com/flutter/flutter/issues/70053).
4+
15
# 0.1.5+2
26

37
- Update Flutter SDK constraint.

packages/url_launcher/url_launcher_web/lib/src/link.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class WebLinkDelegateState extends State<WebLinkDelegate> {
6666
@override
6767
Widget build(BuildContext context) {
6868
return Stack(
69+
fit: StackFit.passthrough,
6970
children: <Widget>[
7071
widget.link.builder(
7172
context,

packages/url_launcher/url_launcher_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/u
44
# 0.1.y+z is compatible with 1.0.0, if you land a breaking change bump
55
# the version to 2.0.0.
66
# See more details: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0
7-
version: 0.1.5+2
7+
version: 0.1.5+3
88

99
flutter:
1010
plugin:

packages/url_launcher/url_launcher_web/test/lib/main.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class MyApp extends StatefulWidget {
1717
class _MyAppState extends State<MyApp> {
1818
@override
1919
Widget build(BuildContext context) {
20-
return Text('Testing... Look at the console output for results!');
20+
return Directionality(
21+
textDirection: TextDirection.ltr,
22+
child: Text('Testing... Look at the console output for results!'),
23+
);
2124
}
2225
}

packages/url_launcher/url_launcher_web/test/test_driver/url_launcher_web_integration.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
// @dart = 2.9
56
import 'dart:html' as html;
67
import 'dart:js_util';
78
import 'package:flutter/widgets.dart';
@@ -271,6 +272,38 @@ void main() {
271272
expect(anchor.getAttribute('href'), uri2.toString());
272273
expect(anchor.getAttribute('target'), '_self');
273274
});
275+
276+
testWidgets('sizes itself correctly', (WidgetTester tester) async {
277+
final Key containerKey = GlobalKey();
278+
final Uri uri = Uri.parse('http://foobar');
279+
await tester.pumpWidget(Directionality(
280+
textDirection: TextDirection.ltr,
281+
child: Center(
282+
child: ConstrainedBox(
283+
constraints: BoxConstraints.tight(Size(100.0, 100.0)),
284+
child: WebLinkDelegate(TestLinkInfo(
285+
uri: uri,
286+
target: LinkTarget.blank,
287+
builder: (BuildContext context, FollowLink followLink) {
288+
return Container(
289+
key: containerKey,
290+
child: SizedBox(width: 50.0, height: 50.0),
291+
);
292+
},
293+
)),
294+
),
295+
),
296+
));
297+
await tester.pumpAndSettle();
298+
299+
final Size containerSize = tester.getSize(find.byKey(containerKey));
300+
// The Stack widget inserted by the `WebLinkDelegate` shouldn't loosen the
301+
// constraints before passing them to the inner container. So the inner
302+
// container should respect the tight constraints given by the ancestor
303+
// `ConstrainedBox` widget.
304+
expect(containerSize.width, 100.0);
305+
expect(containerSize.height, 100.0);
306+
});
274307
});
275308
}
276309

packages/url_launcher/url_launcher_web/test/test_driver/url_launcher_web_integration_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
// @dart = 2.9
56
import 'package:integration_test/integration_test_driver.dart';
67

78
Future<void> main() async => integrationDriver();

0 commit comments

Comments
 (0)