open method

  1. @override
Future<void> open({
  1. WebUri? url,
  2. Map<String, String>? headers,
  3. List<WebUri>? otherLikelyURLs,
  4. WebUri? referrer,
  5. ChromeSafariBrowserSettings? settings,
})

Opens the PlatformChromeSafariBrowser instance with an url.

url - The url to load. On iOS, the url is required and must use the http or https scheme.

headers (Supported only on Android) - whitelisted cross-origin request headers. It is possible to attach non-whitelisted headers to cross-origin requests, when the server and client are related using a digital asset link.

otherLikelyURLs - Other likely destinations, sorted in decreasing likelihood order. Supported only on Android.

referrer - referrer header. Supported only on Android.

settings - Settings for the PlatformChromeSafariBrowser.

Officially Supported Platforms/Implementations:

  • Android
  • iOS

Implementation

@override
Future<void> open({
  WebUri? url,
  Map<String, String>? headers,
  List<WebUri>? otherLikelyURLs,
  WebUri? referrer,
  ChromeSafariBrowserSettings? settings,
}) async {
  assert(!_isOpened, 'The browser is already opened.');
  _isOpened = true;

  assert(url != null, 'The specified URL must not be null on iOS.');
  assert(
    ['http', 'https'].contains(url!.scheme),
    'The specified URL has an unsupported scheme. Only HTTP and HTTPS URLs are supported on iOS.',
  );
  if (url != null) {
    assert(url.toString().isNotEmpty, 'The specified URL must not be empty.');
  }

  _init();

  List<Map<String, dynamic>> menuItemList = [];
  _menuItems.forEach((key, value) {
    menuItemList.add(value.toMap());
  });

  var initialSettings =
      settings?.toJson() ?? ChromeSafariBrowserSettings().toJson();

  Map<String, dynamic> args = <String, dynamic>{};
  args.putIfAbsent('id', () => id);
  args.putIfAbsent('url', () => url?.toString());
  args.putIfAbsent('headers', () => headers);
  args.putIfAbsent(
    'otherLikelyURLs',
    () => otherLikelyURLs?.map((e) => e.toString()).toList(),
  );
  args.putIfAbsent('referrer', () => referrer?.toString());
  args.putIfAbsent('settings', () => initialSettings);
  args.putIfAbsent('menuItemList', () => menuItemList);
  await _staticChannel.invokeMethod('open', args);
}