launch method

Future<void> launch(
  1. String url, {
  2. Map<String, String>? headers,
  3. Set<JavascriptChannel> javascriptChannels = const <JavascriptChannel>{},
  4. bool withJavascript = true,
  5. bool clearCache = false,
  6. bool clearCookies = false,
  7. bool mediaPlaybackRequiresUserGesture = true,
  8. bool hidden = false,
  9. bool enableAppScheme = true,
  10. Rect? rect,
  11. String? userAgent,
  12. bool withZoom = false,
  13. bool displayZoomControls = false,
  14. bool withLocalStorage = true,
  15. bool withLocalUrl = false,
  16. String? localUrlScope,
  17. bool withOverviewMode = false,
  18. bool scrollBar = true,
  19. bool supportMultipleWindows = false,
  20. bool appCacheEnabled = false,
  21. bool allowFileURLs = false,
  22. bool useWideViewPort = false,
  23. String? invalidUrlRegex,
  24. bool geolocationEnabled = false,
  25. bool debuggingEnabled = false,
  26. bool ignoreSSLErrors = false,
})

Start the Webview with url

  • headers specify additional HTTP headers
  • withJavascript enable Javascript or not for the Webview
  • clearCache clear the cache of the Webview
  • clearCookies clear all cookies of the Webview
  • hidden not show
  • rect: show in rect, fullscreen if null
  • enableAppScheme: false will enable all schemes, true only for httt/https/about android: Not implemented yet
  • userAgent: set the User-Agent of WebView
  • withZoom: enable zoom on webview
  • withLocalStorage enable localStorage API on Webview Currently Android only. It is always enabled in UIWebView of iOS and can not be disabled.
  • withLocalUrl: allow url as a local path Allow local files on iOs > 9.0
  • localUrlScope: allowed folder for local paths iOS only. If null and withLocalUrl is true, then it will use the url as the scope, allowing only itself to be read.
  • scrollBar: enable or disable scrollbar
  • supportMultipleWindows enable multiple windows support in Android
  • invalidUrlRegex is the regular expression of URLs that web view shouldn't load. For example, when webview is redirected to a specific URL, you want to intercept this process by stopping loading this URL and replacing webview by another screen. Android only settings:
  • displayZoomControls: display zoom controls on webview
  • withOverviewMode: enable overview mode for Android webview ( setLoadWithOverviewMode )
  • useWideViewPort: use wide viewport for Android webview ( setUseWideViewPort )
  • ignoreSSLErrors: use to bypass Android/iOS SSL checks e.g. for self-signed certificates

Implementation

Future<void> launch(
  String url, {
  Map<String, String>? headers,
  Set<JavascriptChannel> javascriptChannels = const <JavascriptChannel>{},
  bool withJavascript = true,
  bool clearCache = false,
  bool clearCookies = false,
  bool mediaPlaybackRequiresUserGesture = true,
  bool hidden = false,
  bool enableAppScheme = true,
  Rect? rect,
  String? userAgent,
  bool withZoom = false,
  bool displayZoomControls = false,
  bool withLocalStorage = true,
  bool withLocalUrl = false,
  String? localUrlScope,
  bool withOverviewMode = false,
  bool scrollBar = true,
  bool supportMultipleWindows = false,
  bool appCacheEnabled = false,
  bool allowFileURLs = false,
  bool useWideViewPort = false,
  String? invalidUrlRegex,
  bool geolocationEnabled = false,
  bool debuggingEnabled = false,
  bool ignoreSSLErrors = false,
}) async {
  final args = <String, dynamic>{
    'url': url,
    'withJavascript': withJavascript,
    'clearCache': clearCache,
    'hidden': hidden,
    'clearCookies': clearCookies,
    'mediaPlaybackRequiresUserGesture': mediaPlaybackRequiresUserGesture,
    'enableAppScheme': enableAppScheme,
    'userAgent': userAgent,
    'withZoom': withZoom,
    'displayZoomControls': displayZoomControls,
    'withLocalStorage': withLocalStorage,
    'withLocalUrl': withLocalUrl,
    'localUrlScope': localUrlScope,
    'scrollBar': scrollBar,
    'supportMultipleWindows': supportMultipleWindows,
    'appCacheEnabled': appCacheEnabled,
    'allowFileURLs': allowFileURLs,
    'useWideViewPort': useWideViewPort,
    'invalidUrlRegex': invalidUrlRegex,
    'geolocationEnabled': geolocationEnabled,
    'withOverviewMode': withOverviewMode,
    'debuggingEnabled': debuggingEnabled,
    'ignoreSSLErrors': ignoreSSLErrors,
  };

  if (headers != null) {
    args['headers'] = headers;
  }

  _assertJavascriptChannelNamesAreUnique(javascriptChannels);

  javascriptChannels.forEach((channel) {
    _javascriptChannels[channel.name] = channel;
  });

  args['javascriptChannelNames'] =
      _extractJavascriptChannelNames(javascriptChannels).toList();

  if (rect != null) {
    args['rect'] = {
      'left': rect.left,
      'top': rect.top,
      'width': rect.width,
      'height': rect.height,
    };
  }
  await _channel.invokeMethod('launch', args);
}