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
Migrate Link to null safety, and update pubspec.yaml
  • Loading branch information
ditman committed Feb 10, 2021
commit ac7429c2c9d3c6fb58a84177dad5dc117e5106dc
48 changes: 25 additions & 23 deletions packages/url_launcher/url_launcher_web/lib/src/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ class WebLinkDelegate extends StatefulWidget {
/// For external URIs, it lets the browser do its thing. For app route names, it
/// pushes the route name to the framework.
class WebLinkDelegateState extends State<WebLinkDelegate> {
LinkViewController _controller;
late LinkViewController _controller;

@override
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);
_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 @@ -126,15 +126,15 @@ class LinkViewController extends PlatformViewController {
static Map<int, LinkViewController> _instances = <int, LinkViewController>{};

static html.Element _viewFactory(int viewId) {
return _instances[viewId]?._element;
return _instances[viewId]!._element;
}

static int _hitTestedViewId;
static int? _hitTestedViewId;

static StreamSubscription _clickSubscription;
static late StreamSubscription _clickSubscription;

static void _onGlobalClick(html.MouseEvent event) {
final int viewId = getViewIdFromTarget(event);
final int? viewId = getViewIdFromTarget(event);
_instances[viewId]?._onDomClick(event);
// After the DOM click event has been received, clean up the hit test state
// so we can start fresh on the next click.
Expand All @@ -161,7 +161,7 @@ class LinkViewController extends PlatformViewController {
/// The context of the [Link] widget that created this controller.
final BuildContext context;

html.Element _element;
late html.Element _element;
bool get _isInitialized => _element != null;

Future<void> _initialize() async {
Expand Down Expand Up @@ -207,7 +207,7 @@ class LinkViewController extends PlatformViewController {
pushRouteNameToFramework(context, routeName);
}

Uri _uri;
late Uri _uri;

/// Set the [Uri] value for this link.
void setUri(Uri uri) {
Expand Down Expand Up @@ -264,8 +264,8 @@ class LinkViewController extends PlatformViewController {
}

/// Finds the view id of the DOM element targeted by the [event].
int getViewIdFromTarget(html.Event event) {
final html.Element linkElement = getLinkElementFromTarget(event);
int? getViewIdFromTarget(html.Event event) {
final html.Element? linkElement = getLinkElementFromTarget(event);
if (linkElement != null) {
return getProperty(linkElement, linkViewIdProperty);
}
Expand All @@ -275,22 +275,24 @@ int getViewIdFromTarget(html.Event event) {
/// Finds the targeted DOM element by the [event].
///
/// It handles the case where the target element is inside a shadow DOM too.
html.Element getLinkElementFromTarget(html.Event event) {
final html.Element target = event.target;
if (isLinkElement(target)) {
return target;
}
if (target.shadowRoot != null) {
final html.Element child = target.shadowRoot.lastChild;
if (isLinkElement(child)) {
return child;
html.Element? getLinkElementFromTarget(html.Event event) {
final html.EventTarget? target = event.target;
if (target != null && target is html.Element) {
if (isLinkElement(target)) {
return target;
}
if (target.shadowRoot != null) {
final html.Node? child = target.shadowRoot!.lastChild;
if (child != null && child is html.Element && isLinkElement(child)) {
return child;
}
}
}
return null;
}

/// Checks if the given [element] is a link that was created by
/// [LinkViewController].
bool isLinkElement(html.Element element) {
return element.tagName == 'A' && hasProperty(element, linkViewIdProperty);
bool isLinkElement(html.Element? element) {
return element != null && element.tagName == 'A' && hasProperty(element, linkViewIdProperty);
}
23 changes: 7 additions & 16 deletions 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+3
version: 2.0.0-nullsafety

flutter:
plugin:
Expand All @@ -14,13 +14,7 @@ flutter:
fileName: url_launcher_web.dart

dependencies:
url_launcher_platform_interface: ^1.0.9
# TODO(mvanbeusekom): Update to use pub.dev once null safety version is published.
# url_launcher_platform_interface:
# git:
# url: https://github.com/flutter/plugins.git
# ref: nnbd
# path: packages/url_launcher/url_launcher_platform_interface
url_launcher_platform_interface: ^2.0.0-nullsafety
flutter:
sdk: flutter
flutter_web_plugins:
Expand All @@ -30,15 +24,12 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
url_launcher: ^5.2.5
# TODO(mvanbeusekom): Update to use pub.dev once null safety version is published.
# url_launcher:
# path: ../url_launcher
url_launcher: ^6.0.0-nullsafety.6
pedantic: ^1.10.0-nullsafety.1
mockito: ^4.1.1
mockito: ^5.0.0-nullsafety.5
integration_test:
path: ../../integration_test
sdk: flutter

environment:
sdk: ">=2.2.0 <3.0.0"
flutter: ">=1.10.0"
sdk: ">=2.12.0-0 <3.0.0"
flutter: ">=1.26.0-0" # For integration_test from sdk