Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
[url_launcher_web] Fix Link misalignment issue (#3476)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mdebbar authored Jan 29, 2021
1 parent 8c9ad11 commit 815beaf
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/url_launcher/url_launcher_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.1.5+3

- Fix Link misalignment [issue](https://github.com/flutter/flutter/issues/70053).

# 0.1.5+2

- Update Flutter SDK constraint.
Expand Down
1 change: 1 addition & 0 deletions packages/url_launcher/url_launcher_web/lib/src/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class WebLinkDelegateState extends State<WebLinkDelegate> {
@override
Widget build(BuildContext context) {
return Stack(
fit: StackFit.passthrough,
children: <Widget>[
widget.link.builder(
context,
Expand Down
2 changes: 1 addition & 1 deletion packages/url_launcher/url_launcher_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/u
# 0.1.y+z is compatible with 1.0.0, if you land a breaking change bump
# the version to 2.0.0.
# See more details: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0
version: 0.1.5+2
version: 0.1.5+3

flutter:
plugin:
Expand Down
5 changes: 4 additions & 1 deletion packages/url_launcher/url_launcher_web/test/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return Text('Testing... Look at the console output for results!');
return Directionality(
textDirection: TextDirection.ltr,
child: Text('Testing... Look at the console output for results!'),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.9
import 'dart:html' as html;
import 'dart:js_util';
import 'package:flutter/widgets.dart';
Expand Down Expand Up @@ -271,6 +272,38 @@ void main() {
expect(anchor.getAttribute('href'), uri2.toString());
expect(anchor.getAttribute('target'), '_self');
});

testWidgets('sizes itself correctly', (WidgetTester tester) async {
final Key containerKey = GlobalKey();
final Uri uri = Uri.parse('http://foobar');
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: ConstrainedBox(
constraints: BoxConstraints.tight(Size(100.0, 100.0)),
child: WebLinkDelegate(TestLinkInfo(
uri: uri,
target: LinkTarget.blank,
builder: (BuildContext context, FollowLink followLink) {
return Container(
key: containerKey,
child: SizedBox(width: 50.0, height: 50.0),
);
},
)),
),
),
));
await tester.pumpAndSettle();

final Size containerSize = tester.getSize(find.byKey(containerKey));
// The Stack widget inserted by the `WebLinkDelegate` shouldn't loosen the
// constraints before passing them to the inner container. So the inner
// container should respect the tight constraints given by the ancestor
// `ConstrainedBox` widget.
expect(containerSize.width, 100.0);
expect(containerSize.height, 100.0);
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.9
import 'package:integration_test/integration_test_driver.dart';

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

0 comments on commit 815beaf

Please sign in to comment.