Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Having a null 'uri' is valid.
  • Loading branch information
ditman committed Feb 11, 2021
commit a5e0953337cf3c8ad9d6cbd50bee1c6df63571d1
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@ void main() {
expect(containerSize.width, 100.0);
expect(containerSize.height, 100.0);
});

// See: https://github.com/flutter/plugins/pull/3522#discussion_r574703724
testWidgets('uri can be null', (WidgetTester tester) async {
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: WebLinkDelegate(TestLinkInfo(
uri: null,
target: LinkTarget.defaultTarget,
builder: (BuildContext context, FollowLink? followLink) {
return Container(width: 100, height: 100);
},
)),
));
// Platform view creation happens asynchronously.
await tester.pumpAndSettle();

final html.Element anchor = _findSingleAnchor();
expect(anchor.hasAttribute('href'), false);
});
});
}

Expand Down Expand Up @@ -115,7 +134,7 @@ class TestLinkInfo extends LinkInfo {
final LinkWidgetBuilder builder;

@override
final Uri uri;
final Uri? uri;

@override
final LinkTarget target;
Expand Down
12 changes: 7 additions & 5 deletions packages/url_launcher/url_launcher_web/lib/src/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class WebLinkDelegateState extends State<WebLinkDelegate> {
void didUpdateWidget(WebLinkDelegate oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.link.uri != oldWidget.link.uri) {
_controller.setUri(widget.link.uri!);
_controller.setUri(widget.link.uri);
}
if (widget.link.target != oldWidget.link.target) {
_controller.setTarget(widget.link.target);
Expand All @@ -78,7 +78,7 @@ class WebLinkDelegateState extends State<WebLinkDelegate> {
onCreatePlatformView: (PlatformViewCreationParams params) {
_controller = LinkViewController.fromParams(params, context);
return _controller
..setUri(widget.link.uri!)
..setUri(widget.link.uri)
..setTarget(widget.link.target);
},
surfaceFactory:
Expand Down Expand Up @@ -193,7 +193,7 @@ class LinkViewController extends PlatformViewController {
return;
}

if (_uri.hasScheme) {
if (_uri != null && _uri!.hasScheme) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a future bug caught by null safety!

// External links will be handled by the browser, so we don't have to do
// anything.
return;
Expand All @@ -207,10 +207,12 @@ class LinkViewController extends PlatformViewController {
pushRouteNameToFramework(context, routeName);
}

late Uri _uri;
Uri? _uri;

/// Set the [Uri] value for this link.
void setUri(Uri uri) {
///
/// When Uri is null, the `href` attribute of the link is removed.
void setUri(Uri? uri) {
assert(_isInitialized);
_uri = uri;
if (uri == null) {
Expand Down