webview_options.dart 45.4 KB
Newer Older
1 2
import 'dart:io';

3
import 'content_blocker.dart';
4
import 'types.dart';
5

6
class AndroidOptions {}
7

8
class IosOptions {}
9

10 11 12 13
class WebViewOptions {
  Map<String, dynamic> toMap() {
    return {};
  }
14 15 16 17

  static WebViewOptions fromMap(Map<String, dynamic> map) {
    return null;
  }
18 19
}

20 21 22 23
class BrowserOptions {
  Map<String, dynamic> toMap() {
    return {};
  }
24 25 26 27 28 29 30 31 32 33 34 35 36 37

  static BrowserOptions fromMap(Map<String, dynamic> map) {
    return null;
  }
}

class ChromeSafariBrowserOptions {
  Map<String, dynamic> toMap() {
    return {};
  }

  static ChromeSafariBrowserOptions fromMap(Map<String, dynamic> map) {
    return null;
  }
38 39
}

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
40
///This class represents all the cross-platform WebView options available.
41 42
class InAppWebViewOptions
    implements WebViewOptions, BrowserOptions, AndroidOptions, IosOptions {
Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
43
  ///Set to `true` to be able to listen at the [shouldOverrideUrlLoading] event. The default value is `false`.
44
  bool useShouldOverrideUrlLoading;
45

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
46
  ///Set to `true` to be able to listen at the [onLoadResource] event. The default value is `false`.
47
  bool useOnLoadResource;
48

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
49
  ///Set to `true` to be able to listen at the [onDownloadStart] event. The default value is `false`.
50
  bool useOnDownloadStart;
51

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
52
  ///Set to `true` to have all the browser's cache cleared before the new window is opened. The default value is `false`.
53
  bool clearCache;
54

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
55 56 57
  ///Sets the user-agent for the WebView.
  ///
  ///**NOTE**: available on iOS 9.0+.
58
  String userAgent;
59

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
60 61 62
  ///Append to the existing user-agent. Setting userAgent will override this.
  ///
  ///**NOTE**: available on Android 17+ and on iOS 9.0+.
63
  String applicationNameForUserAgent;
64

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
65
  ///Set to `true` to enable JavaScript. The default value is `true`.
66
  bool javaScriptEnabled;
67

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
68 69 70 71
  ///Enables debugging of web contents (HTML / CSS / JavaScript) loaded into any WebViews of this application.
  ///This flag can be enabled in order to facilitate debugging of web layouts and JavaScript code running inside WebViews. The default is `false`.
  ///
  ///**NOTE**: on iOS the debugging mode is always enabled.
72
  bool debuggingEnabled;
73

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
74
  ///Set to `true` to allow JavaScript open windows without user interaction. The default value is `false`.
75
  bool javaScriptCanOpenWindowsAutomatically;
76

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
77
  ///Set to `true` to prevent HTML5 audio or video from autoplaying. The default value is `true`.
Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
78 79
  ///
  ///**NOTE**: available on iOS 10.0+.
80
  bool mediaPlaybackRequiresUserGesture;
81

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
82
  ///Sets the minimum font size. The default value is `8` for Android, `0` for iOS.
83
  int minimumFontSize;
84

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
85
  ///Define whether the vertical scrollbar should be drawn or not. The default value is `true`.
86
  bool verticalScrollBarEnabled;
87

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
88
  ///Define whether the horizontal scrollbar should be drawn or not. The default value is `true`.
89
  bool horizontalScrollBarEnabled;
90

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
91
  ///List of custom schemes that the WebView must handle. Use the [onLoadResourceCustomScheme] event to intercept resource requests with custom scheme.
Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
92 93
  ///
  ///**NOTE**: available on iOS 11.0+.
94
  List<String> resourceCustomSchemes;
95

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
96
  ///List of [ContentBlocker] that are a set of rules used to block content in the browser window.
Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
97 98
  ///
  ///**NOTE**: available on iOS 11.0+.
99
  List<ContentBlocker> contentBlockers;
100

101
  ///Sets the content mode that the WebView needs to use when loading and rendering a webpage. The default value is [UserPreferredContentMode.RECOMMENDED].
Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
102 103
  ///
  ///**NOTE**: available on iOS 13.0+.
104
  UserPreferredContentMode preferredContentMode;
105

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
106
  ///Set to `true` to be able to listen at the [shouldInterceptAjaxRequest] event. The default value is `false`.
107
  bool useShouldInterceptAjaxRequest;
108

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
109
  ///Set to `true` to be able to listen at the [shouldInterceptFetchRequest] event. The default value is `false`.
110
  bool useShouldInterceptFetchRequest;
111

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
112 113 114
  ///Set to `true` to open a browser window with incognito mode. The default value is `false`.
  ///
  ///**NOTE**: available on iOS 9.0+.
115
  bool incognito;
116

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
117 118 119
  ///Sets whether WebView should use browser caching. The default value is `true`.
  ///
  ///**NOTE**: available on iOS 9.0+.
120
  bool cacheEnabled;
121

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
122
  ///Set to `true` to make the background of the WebView transparent. If your app has a dark theme, this can prevent a white flash on initialization. The default value is `false`.
123
  bool transparentBackground;
124

125 126
  ///Set to `true` to disable vertical scroll. The default value is `false`.
  bool disableVerticalScroll;
127

128 129
  ///Set to `true` to disable horizontal scroll. The default value is `false`.
  bool disableHorizontalScroll;
130

131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
  InAppWebViewOptions(
      {this.useShouldOverrideUrlLoading = false,
      this.useOnLoadResource = false,
      this.useOnDownloadStart = false,
      this.clearCache = false,
      this.userAgent = "",
      this.applicationNameForUserAgent = "",
      this.javaScriptEnabled = true,
      this.debuggingEnabled = false,
      this.javaScriptCanOpenWindowsAutomatically = false,
      this.mediaPlaybackRequiresUserGesture = true,
      this.minimumFontSize,
      this.verticalScrollBarEnabled = true,
      this.horizontalScrollBarEnabled = true,
      this.resourceCustomSchemes = const [],
      this.contentBlockers = const [],
      this.preferredContentMode =
148
          UserPreferredContentMode.RECOMMENDED,
149 150 151 152 153 154 155 156 157 158 159 160
      this.useShouldInterceptAjaxRequest = false,
      this.useShouldInterceptFetchRequest = false,
      this.incognito = false,
      this.cacheEnabled = true,
      this.transparentBackground = false,
      this.disableVerticalScroll = false,
      this.disableHorizontalScroll = false}) {
    if (this.minimumFontSize == null)
      this.minimumFontSize = Platform.isAndroid ? 8 : 0;
    assert(!this.resourceCustomSchemes.contains("http") &&
        !this.resourceCustomSchemes.contains("https"));
  }
161 162 163 164 165 166 167 168 169 170 171 172 173 174

  @override
  Map<String, dynamic> toMap() {
    List<Map<String, Map<String, dynamic>>> contentBlockersMapList = [];
    contentBlockers.forEach((contentBlocker) {
      contentBlockersMapList.add(contentBlocker.toMap());
    });

    return {
      "useShouldOverrideUrlLoading": useShouldOverrideUrlLoading,
      "useOnLoadResource": useOnLoadResource,
      "useOnDownloadStart": useOnDownloadStart,
      "clearCache": clearCache,
      "userAgent": userAgent,
175
      "applicationNameForUserAgent": applicationNameForUserAgent,
176
      "javaScriptEnabled": javaScriptEnabled,
177
      "debuggingEnabled": debuggingEnabled,
178 179
      "javaScriptCanOpenWindowsAutomatically":
          javaScriptCanOpenWindowsAutomatically,
180 181 182 183 184
      "mediaPlaybackRequiresUserGesture": mediaPlaybackRequiresUserGesture,
      "verticalScrollBarEnabled": verticalScrollBarEnabled,
      "horizontalScrollBarEnabled": horizontalScrollBarEnabled,
      "resourceCustomSchemes": resourceCustomSchemes,
      "contentBlockers": contentBlockersMapList,
185 186
      "preferredContentMode": preferredContentMode?.toValue(),
      "useShouldInterceptAjaxRequest": useShouldInterceptAjaxRequest,
187 188 189
      "useShouldInterceptFetchRequest": useShouldInterceptFetchRequest,
      "incognito": incognito,
      "cacheEnabled": cacheEnabled,
190 191 192
      "transparentBackground": transparentBackground,
      "disableVerticalScroll": disableVerticalScroll,
      "disableHorizontalScroll": disableHorizontalScroll
193 194
    };
  }
195 196 197 198 199 200 201

  static InAppWebViewOptions fromMap(Map<String, dynamic> map) {
    List<ContentBlocker> contentBlockers = [];
    List<dynamic> contentBlockersMapList = map["contentBlockers"];
    if (contentBlockersMapList != null) {
      contentBlockersMapList.forEach((contentBlocker) {
        contentBlockers.add(ContentBlocker.fromMap(
202 203
            Map<dynamic, Map<dynamic, dynamic>>.from(
                Map<dynamic, dynamic>.from(contentBlocker))));
204 205 206 207 208 209 210 211 212
      });
    }

    InAppWebViewOptions options = new InAppWebViewOptions();
    options.useShouldOverrideUrlLoading = map["useShouldOverrideUrlLoading"];
    options.useOnLoadResource = map["useOnLoadResource"];
    options.useOnDownloadStart = map["useOnDownloadStart"];
    options.clearCache = map["clearCache"];
    options.userAgent = map["userAgent"];
213
    options.applicationNameForUserAgent = map["applicationNameForUserAgent"];
214
    options.javaScriptEnabled = map["javaScriptEnabled"];
215
    options.debuggingEnabled = map["debuggingEnabled"];
216 217 218 219
    options.javaScriptCanOpenWindowsAutomatically =
        map["javaScriptCanOpenWindowsAutomatically"];
    options.mediaPlaybackRequiresUserGesture =
        map["mediaPlaybackRequiresUserGesture"];
220 221
    options.verticalScrollBarEnabled = map["verticalScrollBarEnabled"];
    options.horizontalScrollBarEnabled = map["horizontalScrollBarEnabled"];
222 223
    options.resourceCustomSchemes =
        List<String>.from(map["resourceCustomSchemes"] ?? []);
224
    options.contentBlockers = contentBlockers;
225
    options.preferredContentMode =
226
        UserPreferredContentMode.fromValue(
227 228 229 230 231
            map["preferredContentMode"]);
    options.useShouldInterceptAjaxRequest =
        map["useShouldInterceptAjaxRequest"];
    options.useShouldInterceptFetchRequest =
        map["useShouldInterceptFetchRequest"];
232 233 234
    options.incognito = map["incognito"];
    options.cacheEnabled = map["cacheEnabled"];
    options.transparentBackground = map["transparentBackground"];
235 236
    options.disableVerticalScroll = map["disableVerticalScroll"];
    options.disableHorizontalScroll = map["disableHorizontalScroll"];
237 238
    return options;
  }
239 240
}

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
241
///This class represents all the Android-only WebView options available.
242 243
class AndroidInAppWebViewOptions
    implements WebViewOptions, BrowserOptions, AndroidOptions {
244
  ///Sets the text zoom of the page in percent. The default value is `100`.
Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
245
  int textZoom;
246

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
247
  ///Set to `true` to have the session cookie cache cleared before the new window is opened.
248
  bool clearSessionCache;
249

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
250
  ///Set to `true` if the WebView should use its built-in zoom mechanisms. The default value is `false`.
251
  bool builtInZoomControls;
252

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
253
  ///Set to `true` if the WebView should display on-screen zoom controls when using the built-in zoom mechanisms. The default value is `false`.
254
  bool displayZoomControls;
255

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
256
  ///Set to `false` if the WebView should not support zooming using its on-screen zoom controls and gestures. The default value is `true`.
257
  bool supportZoom;
258

259
  ///Set to `true` if you want the database storage API is enabled. The default value is `true`.
260
  bool databaseEnabled;
261

262
  ///Set to `true` if you want the DOM storage API is enabled. The default value is `true`.
263
  bool domStorageEnabled;
264

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
265 266 267 268
  ///Set to `true` if the WebView should enable support for the "viewport" HTML meta tag or should use a wide viewport.
  ///When the value of the setting is false, the layout width is always set to the width of the WebView control in device-independent (CSS) pixels.
  ///When the value is true and the page contains the viewport meta tag, the value of the width specified in the tag is used.
  ///If the page does not contain the tag or does not provide a width, then a wide viewport will be used. The default value is `true`.
269
  bool useWideViewPort;
270

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
271 272 273 274
  ///Sets whether Safe Browsing is enabled. Safe Browsing allows WebView to protect against malware and phishing attacks by verifying the links.
  ///Safe Browsing is enabled by default for devices which support it.
  ///
  ///**NOTE**: available on Android 26+.
275
  bool safeBrowsingEnabled;
276

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
277 278 279
  ///Configures the WebView's behavior when a secure origin attempts to load a resource from an insecure origin.
  ///
  ///**NOTE**: available on Android 21+.
280
  AndroidMixedContentMode mixedContentMode;
281

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
282
  ///Enables or disables content URL access within WebView. Content URL access allows WebView to load content from a content provider installed in the system. The default value is `true`.
283
  bool allowContentAccess;
284

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
285 286
  ///Enables or disables file access within WebView. Note that this enables or disables file system access only.
  ///Assets and resources are still accessible using \file:///android_asset` and `file:///android_res`. The default value is `true`.
287
  bool allowFileAccess;
288

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
289 290 291
  ///Sets whether JavaScript running in the context of a file scheme URL should be allowed to access content from other file scheme URLs.
  ///Note that the value of this setting is ignored if the value of [allowFileAccessFromFileURLs] is `true`.
  ///Note too, that this setting affects only JavaScript access to file scheme resources. The default value is `false`.
292
  bool allowFileAccessFromFileURLs;
293

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
294 295 296
  ///Sets whether JavaScript running in the context of a file scheme URL should be allowed to access content from any origin.
  ///Note that this setting affects only JavaScript access to file scheme resources.
  ///This includes access to content from other file scheme URLs. The default value is `false`.
297
  bool allowUniversalAccessFromFileURLs;
298

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
299 300
  ///Sets the path to the Application Caches files. In order for the Application Caches API to be enabled, this option must be set a path to which the application can write.
  ///This option is used one time: repeated calls are ignored.
301
  String appCachePath;
302

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
303
  ///Sets whether the WebView should not load image resources from the network (resources accessed via http and https URI schemes). The default value is `false`.
304
  bool blockNetworkImage;
305

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
306
  ///Sets whether the WebView should not load resources from the network. The default value is `false`.
307
  bool blockNetworkLoads;
308

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
309
  ///Overrides the way the cache is used. The way the cache is used is based on the navigation type. For a normal page load, the cache is checked and content is re-validated as needed.
310 311
  ///When navigating back, content is not revalidated, instead the content is just retrieved from the cache. The default value is [AndroidCacheMode.LOAD_DEFAULT].
  AndroidCacheMode cacheMode;
312

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
313
  ///Sets the cursive font family name. The default value is `"cursive"`.
314
  String cursiveFontFamily;
315

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
316
  ///Sets the default fixed font size. The default value is `16`.
317
  int defaultFixedFontSize;
318

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
319
  ///Sets the default font size. The default value is `16`.
320
  int defaultFontSize;
321

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
322
  ///Sets the default text encoding name to use when decoding html pages. The default value is `"UTF-8"`.
323
  String defaultTextEncodingName;
324

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
325 326 327
  ///Disables the action mode menu items according to menuItems flag.
  ///
  ///**NOTE**: available on Android 24+.
328
  AndroidActionModeMenuItem disabledActionModeMenuItems;
329

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
330
  ///Sets the fantasy font family name. The default value is `"fantasy"`.
331
  String fantasyFontFamily;
332

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
333
  ///Sets the fixed font family name. The default value is `"monospace"`.
334
  String fixedFontFamily;
335

336
  ///Set the force dark mode for this WebView. The default value is [AndroidForceDark.FORCE_DARK_OFF].
Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
337 338
  ///
  ///**NOTE**: available on Android 29+.
339
  AndroidForceDark forceDark;
340

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
341
  ///Sets whether Geolocation API is enabled. The default value is `true`.
342
  bool geolocationEnabled;
343

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
344
  ///Sets the underlying layout algorithm. This will cause a re-layout of the WebView.
345
  AndroidLayoutAlgorithm layoutAlgorithm;
346

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
347 348 349
  ///Sets whether the WebView loads pages in overview mode, that is, zooms out the content to fit on screen by width.
  ///This setting is taken into account when the content width is greater than the width of the WebView control, for example, when [useWideViewPort] is enabled.
  ///The default value is `false`.
350
  bool loadWithOverviewMode;
351

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
352 353 354
  ///Sets whether the WebView should load image resources. Note that this method controls loading of all images, including those embedded using the data URI scheme.
  ///Note that if the value of this setting is changed from false to true, all images resources referenced by content currently displayed by the WebView are loaded automatically.
  ///The default value is `true`.
355
  bool loadsImagesAutomatically;
356

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
357
  ///Sets the minimum logical font size. The default is `8`.
358
  int minimumLogicalFontSize;
359

360
  ///Sets the initial scale for this WebView. 0 means default. The behavior for the default scale depends on the state of [useWideViewPort] and [loadWithOverviewMode].
Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
361 362 363 364 365
  ///If the content fits into the WebView control by width, then the zoom is set to 100%. For wide content, the behavior depends on the state of [loadWithOverviewMode].
  ///If its value is true, the content will be zoomed out to be fit by width into the WebView control, otherwise not.
  ///If initial scale is greater than 0, WebView starts with this value as initial scale.
  ///Please note that unlike the scale properties in the viewport meta tag, this method doesn't take the screen density into account.
  ///The default is `0`.
crazecoder's avatar
crazecoder committed
366
  int initialScale;
367

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
368
  ///Tells the WebView whether it needs to set a node. The default value is `true`.
369
  bool needInitialFocus;
370

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
371 372 373 374 375
  ///Sets whether this WebView should raster tiles when it is offscreen but attached to a window.
  ///Turning this on can avoid rendering artifacts when animating an offscreen WebView on-screen.
  ///Offscreen WebViews in this mode use more memory. The default value is `false`.
  ///
  ///**NOTE**: available on Android 23+.
376
  bool offscreenPreRaster;
377

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
378
  ///Sets the sans-serif font family name. The default value is `"sans-serif"`.
379
  String sansSerifFontFamily;
380

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
381
  ///Sets the serif font family name. The default value is `"sans-serif"`.
382
  String serifFontFamily;
383

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
384
  ///Sets the standard font family name. The default value is `"sans-serif"`.
385
  String standardFontFamily;
386

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
387 388
  ///Sets whether the WebView should save form data. In Android O, the platform has implemented a fully functional Autofill feature to store form data.
  ///Therefore, the Webview form data save feature is disabled. Note that the feature will continue to be supported on older versions of Android as before.
389
  ///The default value is `true`.
390
  bool saveFormData;
391

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
392 393 394 395 396
  ///Boolean value to enable third party cookies in the WebView.
  ///Used on Android Lollipop and above only as third party cookies are enabled by default on Android Kitkat and below and on iOS.
  ///The default value is `true`.
  ///
  ///**NOTE**: available on Android 21+.
397
  bool thirdPartyCookiesEnabled;
398

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
399 400
  ///Boolean value to enable Hardware Acceleration in the WebView.
  ///The default value is `true`.
401
  bool hardwareAcceleration;
402

403 404 405 406
  ///Sets whether the WebView whether supports multiple windows.
  ///If set to `true`, [onCreateWindow] event must be implemented by the host application. The default value is `false`.
  bool supportMultipleWindows;

407 408
  ///Regular expression used by [shouldOverrideUrlLoading] event to cancel navigation requests for frames that are not the main frame.
  ///If the url request of a subframe matches the regular expression, then the request of that subframe is canceled.
409 410
  String regexToCancelSubFramesLoading;

411 412 413 414 415 416 417
  AndroidInAppWebViewOptions(
      {this.textZoom = 100,
      this.clearSessionCache = false,
      this.builtInZoomControls = false,
      this.displayZoomControls = false,
      this.supportZoom = true,
      this.databaseEnabled = false,
418
      this.domStorageEnabled = true,
419 420 421 422 423 424 425 426 427 428
      this.useWideViewPort = true,
      this.safeBrowsingEnabled = true,
      this.mixedContentMode,
      this.allowContentAccess = true,
      this.allowFileAccess = true,
      this.allowFileAccessFromFileURLs = false,
      this.allowUniversalAccessFromFileURLs = false,
      this.appCachePath,
      this.blockNetworkImage = false,
      this.blockNetworkLoads = false,
429
      this.cacheMode = AndroidCacheMode.LOAD_DEFAULT,
430 431 432 433 434 435 436
      this.cursiveFontFamily = "cursive",
      this.defaultFixedFontSize = 16,
      this.defaultFontSize = 16,
      this.defaultTextEncodingName = "UTF-8",
      this.disabledActionModeMenuItems,
      this.fantasyFontFamily = "fantasy",
      this.fixedFontFamily = "monospace",
437
      this.forceDark = AndroidForceDark.FORCE_DARK_OFF,
438 439 440 441 442 443 444 445 446 447 448 449 450
      this.geolocationEnabled = true,
      this.layoutAlgorithm,
      this.loadWithOverviewMode = true,
      this.loadsImagesAutomatically = true,
      this.minimumLogicalFontSize = 8,
      this.needInitialFocus = true,
      this.offscreenPreRaster = false,
      this.sansSerifFontFamily = "sans-serif",
      this.serifFontFamily = "sans-serif",
      this.standardFontFamily = "sans-serif",
      this.saveFormData = true,
      this.thirdPartyCookiesEnabled = true,
      this.hardwareAcceleration = true,
451 452
      this.initialScale = 0,
      this.supportMultipleWindows = false,
453
      this.regexToCancelSubFramesLoading});
454 455 456 457

  @override
  Map<String, dynamic> toMap() {
    return {
Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
458
      "textZoom": textZoom,
459 460 461 462 463 464 465 466
      "clearSessionCache": clearSessionCache,
      "builtInZoomControls": builtInZoomControls,
      "displayZoomControls": displayZoomControls,
      "supportZoom": supportZoom,
      "databaseEnabled": databaseEnabled,
      "domStorageEnabled": domStorageEnabled,
      "useWideViewPort": useWideViewPort,
      "safeBrowsingEnabled": safeBrowsingEnabled,
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
      "mixedContentMode": mixedContentMode?.toValue(),
      "allowContentAccess": allowContentAccess,
      "allowFileAccess": allowFileAccess,
      "allowFileAccessFromFileURLs": allowFileAccessFromFileURLs,
      "allowUniversalAccessFromFileURLs": allowUniversalAccessFromFileURLs,
      "appCachePath": appCachePath,
      "blockNetworkImage": blockNetworkImage,
      "blockNetworkLoads": blockNetworkLoads,
      "cacheMode": cacheMode?.toValue(),
      "cursiveFontFamily": cursiveFontFamily,
      "defaultFixedFontSize": defaultFixedFontSize,
      "defaultFontSize": defaultFontSize,
      "defaultTextEncodingName": defaultTextEncodingName,
      "disabledActionModeMenuItems": disabledActionModeMenuItems?.toValue(),
      "fantasyFontFamily": fantasyFontFamily,
      "fixedFontFamily": fixedFontFamily,
      "forceDark": forceDark?.toValue(),
      "geolocationEnabled": geolocationEnabled,
      "layoutAlgorithm": layoutAlgorithm?.toValue(),
      "loadWithOverviewMode": loadWithOverviewMode,
      "loadsImagesAutomatically": loadsImagesAutomatically,
      "minimumLogicalFontSize": minimumLogicalFontSize,
crazecoder's avatar
crazecoder committed
489
      "initialScale": initialScale,
490 491 492 493
      "needInitialFocus": needInitialFocus,
      "offscreenPreRaster": offscreenPreRaster,
      "sansSerifFontFamily": sansSerifFontFamily,
      "serifFontFamily": serifFontFamily,
494 495 496
      "standardFontFamily": standardFontFamily,
      "saveFormData": saveFormData,
      "thirdPartyCookiesEnabled": thirdPartyCookiesEnabled,
497 498
      "hardwareAcceleration": hardwareAcceleration,
      "supportMultipleWindows": supportMultipleWindows,
499
      "regexToCancelSubFramesLoading": regexToCancelSubFramesLoading
500 501
    };
  }
502 503 504

  static AndroidInAppWebViewOptions fromMap(Map<String, dynamic> map) {
    AndroidInAppWebViewOptions options = new AndroidInAppWebViewOptions();
Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
505
    options.textZoom = map["textZoom"];
506 507 508 509 510 511 512 513
    options.clearSessionCache = map["clearSessionCache"];
    options.builtInZoomControls = map["builtInZoomControls"];
    options.displayZoomControls = map["displayZoomControls"];
    options.supportZoom = map["supportZoom"];
    options.databaseEnabled = map["databaseEnabled"];
    options.domStorageEnabled = map["domStorageEnabled"];
    options.useWideViewPort = map["useWideViewPort"];
    options.safeBrowsingEnabled = map["safeBrowsingEnabled"];
514
    options.mixedContentMode =
515
        AndroidMixedContentMode.fromValue(map["mixedContentMode"]);
516 517 518
    options.allowContentAccess = map["allowContentAccess"];
    options.allowFileAccess = map["allowFileAccess"];
    options.allowFileAccessFromFileURLs = map["allowFileAccessFromFileURLs"];
519 520
    options.allowUniversalAccessFromFileURLs =
        map["allowUniversalAccessFromFileURLs"];
521 522 523
    options.appCachePath = map["appCachePath"];
    options.blockNetworkImage = map["blockNetworkImage"];
    options.blockNetworkLoads = map["blockNetworkLoads"];
524
    options.cacheMode =
525
        AndroidCacheMode.fromValue(map["cacheMode"]);
526 527 528 529
    options.cursiveFontFamily = map["cursiveFontFamily"];
    options.defaultFixedFontSize = map["defaultFixedFontSize"];
    options.defaultFontSize = map["defaultFontSize"];
    options.defaultTextEncodingName = map["defaultTextEncodingName"];
530
    options.disabledActionModeMenuItems =
531
        AndroidActionModeMenuItem.fromValue(
532
            map["disabledActionModeMenuItems"]);
533 534
    options.fantasyFontFamily = map["fantasyFontFamily"];
    options.fixedFontFamily = map["fixedFontFamily"];
535
    options.forceDark =
536
        AndroidForceDark.fromValue(map["forceDark"]);
537
    options.geolocationEnabled = map["geolocationEnabled"];
538
    options.layoutAlgorithm =
539
        AndroidLayoutAlgorithm.fromValue(map["layoutAlgorithm"]);
540 541 542
    options.loadWithOverviewMode = map["loadWithOverviewMode"];
    options.loadsImagesAutomatically = map["loadsImagesAutomatically"];
    options.minimumLogicalFontSize = map["minimumLogicalFontSize"];
crazecoder's avatar
crazecoder committed
543
    options.initialScale = map["initialScale"];
544 545 546 547 548
    options.needInitialFocus = map["needInitialFocus"];
    options.offscreenPreRaster = map["offscreenPreRaster"];
    options.sansSerifFontFamily = map["sansSerifFontFamily"];
    options.serifFontFamily = map["serifFontFamily"];
    options.standardFontFamily = map["standardFontFamily"];
549 550 551
    options.saveFormData = map["saveFormData"];
    options.thirdPartyCookiesEnabled = map["thirdPartyCookiesEnabled"];
    options.hardwareAcceleration = map["hardwareAcceleration"];
552 553
    options.supportMultipleWindows = map["supportMultipleWindows"];
    options.regexToCancelSubFramesLoading = map["regexToCancelSubFramesLoading"];
554 555
    return options;
  }
556 557
}

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
558
///This class represents all the iOS-only WebView options available.
559
class IOSInAppWebViewOptions
560
    implements WebViewOptions, BrowserOptions, IosOptions {
Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
561
  ///Set to `true` to disable the bouncing of the WebView when the scrolling has reached an edge of the content. The default value is `false`.
562
  bool disallowOverScroll;
563

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
564
  ///Set to `true` to allow a viewport meta tag to either disable or restrict the range of user scaling. The default value is `false`.
565
  bool enableViewportScale;
566

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
567
  ///Set to `true` if you want the WebView suppresses content rendering until it is fully loaded into memory. The default value is `false`.
568
  bool suppressesIncrementalRendering;
569

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
570
  ///Set to `true` to allow AirPlay. The default value is `true`.
571
  bool allowsAirPlayForMediaPlayback;
572

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
573
  ///Set to `true` to allow the horizontal swipe gestures trigger back-forward list navigations. The default value is `true`.
574
  bool allowsBackForwardNavigationGestures;
575

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
576 577 578
  ///Set to `true` to allow that pressing on a link displays a preview of the destination for the link. The default value is `true`.
  ///
  ///**NOTE**: available on iOS 9.0+.
579
  bool allowsLinkPreview;
580

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
581 582
  ///Set to `true` if you want that the WebView should always allow scaling of the webpage, regardless of the author's intent.
  ///The ignoresViewportScaleLimits property overrides the `user-scalable` HTML property in a webpage. The default value is `false`.
583
  bool ignoresViewportScaleLimits;
584

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
585 586
  ///Set to `true` to allow HTML5 media playback to appear inline within the screen layout, using browser-supplied controls rather than native controls.
  ///For this to work, add the `webkit-playsinline` attribute to any `<video>` elements. The default value is `false`.
587
  bool allowsInlineMediaPlayback;
588

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
589 590 591
  ///Set to `true` to allow HTML5 videos play picture-in-picture. The default value is `true`.
  ///
  ///**NOTE**: available on iOS 9.0+.
592
  bool allowsPictureInPictureMediaPlayback;
593

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
594 595 596 597 598
  ///A Boolean value indicating whether warnings should be shown for suspected fraudulent content such as phishing or malware.
  ///According to the official documentation, this feature is currently available in the following region: China.
  ///The default value is `true`.
  ///
  ///**NOTE**: available on iOS 13.0+.
599
  bool isFraudulentWebsiteWarningEnabled;
600

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
601
  ///The level of granularity with which the user can interactively select content in the web view.
602 603
  ///The default value is [IOSWKSelectionGranularity.DYNAMIC]
  IOSWKSelectionGranularity selectionGranularity;
604

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
605
  ///Specifying a dataDetectoryTypes value adds interactivity to web content that matches the value.
606 607
  ///For example, Safari adds a link to “apple.com” in the text “Visit apple.com” if the dataDetectorTypes property is set to [IOSWKDataDetectorTypes.LINK].
  ///The default value is [IOSWKDataDetectorTypes.NONE].
Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
608 609
  ///
  ///**NOTE**: available on iOS 10.0+.
610
  List<IOSWKDataDetectorTypes> dataDetectorTypes;
611

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
612 613 614 615
  ///Set `true` if shared cookies from `HTTPCookieStorage.shared` should used for every load request in the WebView.
  ///The default value is `false`.
  ///
  ///**NOTE**: available on iOS 11.0+.
616
  bool sharedCookiesEnabled;
617

618 619 620 621 622 623
  ///Configures whether the scroll indicator insets are automatically adjusted by the system.
  ///The default value is `false`.
  ///
  ///**NOTE**: available on iOS 13.0+.
  bool automaticallyAdjustsScrollIndicatorInsets;

624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
  ///A Boolean value indicating whether the view ignores an accessibility request to invert its colors.
  ///The default value is `false`.
  ///
  ///**NOTE**: available on iOS 11.0+.
  bool accessibilityIgnoresInvertColors;

  ///A [IOSUIScrollViewDecelerationRate] value that determines the rate of deceleration after the user lifts their finger.
  ///The default value is [IOSUIScrollViewDecelerationRate.NORMAL].
  IOSUIScrollViewDecelerationRate decelerationRate;

  ///A Boolean value that determines whether bouncing always occurs when vertical scrolling reaches the end of the content.
  ///The default value is `false`.
  bool alwaysBounceVertical;

  ///A Boolean value that determines whether bouncing always occurs when horizontal scrolling reaches the end of the content view.
  ///The default value is `false`.
  bool alwaysBounceHorizontal;

  ///A Boolean value that controls whether the scroll-to-top gesture is enabled.
  ///The scroll-to-top gesture is a tap on the status bar. When a user makes this gesture,
  ///the system asks the scroll view closest to the status bar to scroll to the top.
  ///The default value is `true`.
  bool scrollsToTop;

  ///A Boolean value that determines whether paging is enabled for the scroll view.
  ///If the value of this property is true, the scroll view stops on multiples of the scroll view’s bounds when the user scrolls.
  ///The default value is `false`.
  bool isPagingEnabled;

  ///A floating-point value that specifies the maximum scale factor that can be applied to the scroll view's content.
  ///This value determines how large the content can be scaled.
  ///It must be greater than the minimum zoom scale for zooming to be enabled.
  ///The default value is `1.0`.
  double maximumZoomScale;

  ///A floating-point value that specifies the minimum scale factor that can be applied to the scroll view's content.
  ///This value determines how small the content can be scaled.
  ///The default value is `1.0`.
  double minimumZoomScale;

664
  IOSInAppWebViewOptions(
665 666 667 668 669 670 671 672 673 674
      {this.disallowOverScroll = false,
      this.enableViewportScale = false,
      this.suppressesIncrementalRendering = false,
      this.allowsAirPlayForMediaPlayback = true,
      this.allowsBackForwardNavigationGestures = true,
      this.allowsLinkPreview = true,
      this.ignoresViewportScaleLimits = false,
      this.allowsInlineMediaPlayback = false,
      this.allowsPictureInPictureMediaPlayback = true,
      this.isFraudulentWebsiteWarningEnabled = true,
675 676
      this.selectionGranularity = IOSWKSelectionGranularity.DYNAMIC,
      this.dataDetectorTypes = const [IOSWKDataDetectorTypes.NONE],
677
      this.sharedCookiesEnabled = false,
678 679 680 681 682 683 684 685 686
      this.automaticallyAdjustsScrollIndicatorInsets = false,
      this.accessibilityIgnoresInvertColors = false,
      this.decelerationRate = IOSUIScrollViewDecelerationRate.NORMAL,
      this.alwaysBounceVertical = false,
      this.alwaysBounceHorizontal = false,
      this.scrollsToTop = true,
      this.isPagingEnabled = false,
      this.maximumZoomScale = 1.0,
      this.minimumZoomScale = 1.0});
687 688 689

  @override
  Map<String, dynamic> toMap() {
690 691 692 693 694
    List<String> dataDetectorTypesList = [];
    dataDetectorTypes.forEach((dataDetectorType) {
      dataDetectorTypesList.add(dataDetectorType.toValue());
    });

695 696 697 698 699
    return {
      "disallowOverScroll": disallowOverScroll,
      "enableViewportScale": enableViewportScale,
      "suppressesIncrementalRendering": suppressesIncrementalRendering,
      "allowsAirPlayForMediaPlayback": allowsAirPlayForMediaPlayback,
700 701
      "allowsBackForwardNavigationGestures":
          allowsBackForwardNavigationGestures,
702 703 704
      "allowsLinkPreview": allowsLinkPreview,
      "ignoresViewportScaleLimits": ignoresViewportScaleLimits,
      "allowsInlineMediaPlayback": allowsInlineMediaPlayback,
705 706
      "allowsPictureInPictureMediaPlayback":
          allowsPictureInPictureMediaPlayback,
707 708
      "isFraudulentWebsiteWarningEnabled": isFraudulentWebsiteWarningEnabled,
      "selectionGranularity": selectionGranularity.toValue(),
709
      "dataDetectorTypes": dataDetectorTypesList,
710
      "sharedCookiesEnabled": sharedCookiesEnabled,
711 712 713 714 715 716 717 718 719
      "automaticallyAdjustsScrollIndicatorInsets": automaticallyAdjustsScrollIndicatorInsets,
      "accessibilityIgnoresInvertColors": accessibilityIgnoresInvertColors,
      "decelerationRate": decelerationRate.toValue(),
      "alwaysBounceVertical": alwaysBounceVertical,
      "alwaysBounceHorizontal": alwaysBounceHorizontal,
      "scrollsToTop": scrollsToTop,
      "isPagingEnabled": isPagingEnabled,
      "maximumZoomScale": maximumZoomScale,
      "minimumZoomScale": minimumZoomScale
720 721
    };
  }
722

723
  static IOSInAppWebViewOptions fromMap(Map<String, dynamic> map) {
724
    List<IOSWKDataDetectorTypes> dataDetectorTypes = [];
725 726
    List<String> dataDetectorTypesList =
        List<String>.from(map["dataDetectorTypes"] ?? []);
727
    dataDetectorTypesList.forEach((dataDetectorType) {
728
      dataDetectorTypes
729
          .add(IOSWKDataDetectorTypes.fromValue(dataDetectorType));
730 731
    });

732
    IOSInAppWebViewOptions options = new IOSInAppWebViewOptions();
733 734
    options.disallowOverScroll = map["disallowOverScroll"];
    options.enableViewportScale = map["enableViewportScale"];
735 736 737 738 739 740
    options.suppressesIncrementalRendering =
        map["suppressesIncrementalRendering"];
    options.allowsAirPlayForMediaPlayback =
        map["allowsAirPlayForMediaPlayback"];
    options.allowsBackForwardNavigationGestures =
        map["allowsBackForwardNavigationGestures"];
741 742 743
    options.allowsLinkPreview = map["allowsLinkPreview"];
    options.ignoresViewportScaleLimits = map["ignoresViewportScaleLimits"];
    options.allowsInlineMediaPlayback = map["allowsInlineMediaPlayback"];
744 745 746 747 748
    options.allowsPictureInPictureMediaPlayback =
        map["allowsPictureInPictureMediaPlayback"];
    options.isFraudulentWebsiteWarningEnabled =
        map["isFraudulentWebsiteWarningEnabled"];
    options.selectionGranularity =
749
        IOSWKSelectionGranularity.fromValue(
750
            map["selectionGranularity"]);
751
    options.dataDetectorTypes = dataDetectorTypes;
752
    options.sharedCookiesEnabled = map["sharedCookiesEnabled"];
753
    options.automaticallyAdjustsScrollIndicatorInsets = map["automaticallyAdjustsScrollIndicatorInsets"];
754 755 756 757 758 759 760 761
    options.accessibilityIgnoresInvertColors = map["accessibilityIgnoresInvertColors"];
    options.decelerationRate = IOSUIScrollViewDecelerationRate.fromValue(map["decelerationRate"]);
    options.alwaysBounceVertical = map["alwaysBounceVertical"];
    options.alwaysBounceHorizontal = map["alwaysBounceHorizontal"];
    options.scrollsToTop = map["scrollsToTop"];
    options.isPagingEnabled = map["isPagingEnabled"];
    options.maximumZoomScale = map["maximumZoomScale"];
    options.minimumZoomScale = map["minimumZoomScale"];
762 763
    return options;
  }
764 765
}

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
766
///This class represents all the cross-platform [InAppBrowser] options available.
767 768
class InAppBrowserOptions
    implements BrowserOptions, AndroidOptions, IosOptions {
Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
769 770
  ///Set to `true` to create the browser and load the page, but not show it. Omit or set to `false` to have the browser open and load normally.
  ///The default value is `false`.
771
  bool hidden;
772

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
773
  ///Set to `false` to hide the toolbar at the top of the WebView. The default value is `true`.
774
  bool toolbarTop;
775

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
776
  ///Set the custom background color of the toolbar at the top.
777
  String toolbarTopBackgroundColor;
778

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
779
  ///Set to `true` to hide the url bar on the toolbar at the top. The default value is `false`.
780 781
  bool hideUrlBar;

782 783 784 785 786
  InAppBrowserOptions(
      {this.hidden = false,
      this.toolbarTop = true,
      this.toolbarTopBackgroundColor = "",
      this.hideUrlBar = false});
787 788 789 790 791 792 793

  @override
  Map<String, dynamic> toMap() {
    return {
      "hidden": hidden,
      "toolbarTop": toolbarTop,
      "toolbarTopBackgroundColor": toolbarTopBackgroundColor,
794
      "hideUrlBar": hideUrlBar
795 796
    };
  }
797 798 799 800 801 802 803 804 805

  static InAppBrowserOptions fromMap(Map<String, dynamic> map) {
    InAppBrowserOptions options = new InAppBrowserOptions();
    options.hidden = map["hidden"];
    options.toolbarTop = map["toolbarTop"];
    options.toolbarTopBackgroundColor = map["toolbarTopBackgroundColor"];
    options.hideUrlBar = map["hideUrlBar"];
    return options;
  }
806 807
}

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
808
///This class represents all the Android-only [InAppBrowser] options available.
809
class AndroidInAppBrowserOptions implements BrowserOptions, AndroidOptions {
Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
810
  ///Set to `true` if you want the title should be displayed. The default value is `false`.
811
  bool hideTitleBar;
812

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
813 814
  ///Set the action bar's title.
  String toolbarTopFixedTitle;
815

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
816
  ///Set to `false` to not close the InAppBrowser when the user click on the back button and the WebView cannot go back to the history. The default value is `true`.
817
  bool closeOnCannotGoBack;
818

819
  ///Set to `false` to hide the progressz bar at the bottom of the toolbar at the top. The default value is `true`.
820 821
  bool progressBar;

822 823 824 825 826
  AndroidInAppBrowserOptions(
      {this.hideTitleBar = true,
      this.toolbarTopFixedTitle = "",
      this.closeOnCannotGoBack = true,
      this.progressBar = true});
827 828 829 830 831

  @override
  Map<String, dynamic> toMap() {
    return {
      "hideTitleBar": hideTitleBar,
Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
832
      "toolbarTopFixedTitle": toolbarTopFixedTitle,
833 834 835 836
      "closeOnCannotGoBack": closeOnCannotGoBack,
      "progressBar": progressBar,
    };
  }
837 838 839 840

  static AndroidInAppBrowserOptions fromMap(Map<String, dynamic> map) {
    AndroidInAppBrowserOptions options = new AndroidInAppBrowserOptions();
    options.hideTitleBar = map["hideTitleBar"];
Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
841
    options.toolbarTopFixedTitle = map["toolbarTopFixedTitle"];
842 843 844 845
    options.closeOnCannotGoBack = map["closeOnCannotGoBack"];
    options.progressBar = map["progressBar"];
    return options;
  }
846 847
}

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
848
///This class represents all the iOS-only [InAppBrowser] options available.
849
class IOSInAppBrowserOptions implements BrowserOptions, IosOptions {
Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
850
  ///Set to `false` to hide the toolbar at the bottom of the WebView. The default value is `true`.
851
  bool toolbarBottom;
852

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
853
  ///Set the custom background color of the toolbar at the bottom.
854
  String toolbarBottomBackgroundColor;
855

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
856
  ///Set to `true` to set the toolbar at the bottom translucent. The default value is `true`.
857
  bool toolbarBottomTranslucent;
858

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
859
  ///Set the custom text for the close button.
860
  String closeButtonCaption;
861

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
862
  ///Set the custom color for the close button.
863
  String closeButtonColor;
864

865 866
  ///Set the custom modal presentation style when presenting the WebView. The default value is [IOSUIModalPresentationStyle.FULL_SCREEN].
  IOSUIModalPresentationStyle presentationStyle;
867

868 869
  ///Set to the custom transition style when presenting the WebView. The default value is [IOSUIModalTransitionStyle.COVER_VERTICAL].
  IOSUIModalTransitionStyle transitionStyle;
870

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
871
  ///Set to `false` to hide the spinner when the WebView is loading a page. The default value is `true`.
872 873
  bool spinner;

874
  IOSInAppBrowserOptions(
875 876 877 878 879
      {this.toolbarBottom = true,
      this.toolbarBottomBackgroundColor = "",
      this.toolbarBottomTranslucent = true,
      this.closeButtonCaption = "",
      this.closeButtonColor = "",
880 881
      this.presentationStyle = IOSUIModalPresentationStyle.FULL_SCREEN,
      this.transitionStyle = IOSUIModalTransitionStyle.COVER_VERTICAL,
882
      this.spinner = true});
883 884 885 886 887 888 889 890 891

  @override
  Map<String, dynamic> toMap() {
    return {
      "toolbarBottom": toolbarBottom,
      "toolbarBottomBackgroundColor": toolbarBottomBackgroundColor,
      "toolbarBottomTranslucent": toolbarBottomTranslucent,
      "closeButtonCaption": closeButtonCaption,
      "closeButtonColor": closeButtonColor,
892 893
      "presentationStyle": presentationStyle.toValue(),
      "transitionStyle": transitionStyle.toValue(),
894
      "spinner": spinner
895 896 897
    };
  }

898 899
  static IOSInAppBrowserOptions fromMap(Map<String, dynamic> map) {
    IOSInAppBrowserOptions options = new IOSInAppBrowserOptions();
900 901 902 903 904
    options.toolbarBottom = map["toolbarBottom"];
    options.toolbarBottomBackgroundColor = map["toolbarBottomBackgroundColor"];
    options.toolbarBottomTranslucent = map["toolbarBottomTranslucent"];
    options.closeButtonCaption = map["closeButtonCaption"];
    options.closeButtonColor = map["closeButtonColor"];
905
    options.presentationStyle =
906
        IOSUIModalPresentationStyle.fromValue(map["presentationStyle"]);
907
    options.transitionStyle =
908
        IOSUIModalTransitionStyle.fromValue(map["transitionStyle"]);
909 910
    options.spinner = map["spinner"];
    return options;
911 912 913
  }
}

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
914
///This class represents all the Android-only [ChromeSafariBrowser] options available.
915 916
class AndroidChromeCustomTabsOptions
    implements ChromeSafariBrowserOptions, AndroidOptions {
917 918
  ///Set to `false` if you don't want the default share item to the menu. The default value is `true`.
  bool addDefaultShareMenuItem;
919

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
920
  ///Set to `false` if the title shouldn't be shown in the custom tab. The default value is `true`.
921
  bool showTitle;
922

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
923
  ///Set the custom background color of the toolbar.
924
  String toolbarBackgroundColor;
925

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
926
  ///Set to `true` to enable the url bar to hide as the user scrolls down on the page. The default value is `false`.
927
  bool enableUrlBarHiding;
928

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
929
  ///Set to `true` to enable Instant Apps. The default value is `false`.
930 931
  bool instantAppsEnabled;

932 933 934 935 936 937 938 939 940 941
  ///Set an explicit application package name that limits
  ///the components this Intent will resolve to.  If left to the default
  ///value of null, all components in all applications will considered.
  ///If non-null, the Intent can only match the components in the given
  ///application package.
  String packageName;

  ///Set to `true` to enable Keep Alive. The default value is `false`.
  bool keepAliveEnabled;

942
  AndroidChromeCustomTabsOptions(
943
      {this.addDefaultShareMenuItem = true,
944 945 946
      this.showTitle = true,
      this.toolbarBackgroundColor = "",
      this.enableUrlBarHiding = false,
947 948 949
      this.instantAppsEnabled = false,
      this.packageName,
      this.keepAliveEnabled = false});
950 951 952 953

  @override
  Map<String, dynamic> toMap() {
    return {
954
      "addDefaultShareMenuItem": addDefaultShareMenuItem,
955 956 957
      "showTitle": showTitle,
      "toolbarBackgroundColor": toolbarBackgroundColor,
      "enableUrlBarHiding": enableUrlBarHiding,
958 959 960
      "instantAppsEnabled": instantAppsEnabled,
      "packageName": packageName,
      "keepAliveEnabled": keepAliveEnabled
961 962
    };
  }
963 964

  static AndroidChromeCustomTabsOptions fromMap(Map<String, dynamic> map) {
965 966
    AndroidChromeCustomTabsOptions options =
        new AndroidChromeCustomTabsOptions();
967
    options.addDefaultShareMenuItem = map["addDefaultShareMenuItem"];
968 969 970 971
    options.showTitle = map["showTitle"];
    options.toolbarBackgroundColor = map["toolbarBackgroundColor"];
    options.enableUrlBarHiding = map["enableUrlBarHiding"];
    options.instantAppsEnabled = map["instantAppsEnabled"];
972 973
    options.packageName = map["packageName"];
    options.keepAliveEnabled = map["keepAliveEnabled"];
974 975
    return options;
  }
976 977
}

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
978
///This class represents all the iOS-only [ChromeSafariBrowser] options available.
979
class IOSSafariOptions implements ChromeSafariBrowserOptions, IosOptions {
Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
980
  ///Set to `true` if Reader mode should be entered automatically when it is available for the webpage. The default value is `false`.
981
  bool entersReaderIfAvailable;
982

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
983
  ///Set to `true` to enable bar collapsing. The default value is `false`.
984
  bool barCollapsingEnabled;
985

986
  ///Set the custom style for the dismiss button. The default value is [IOSSafariDismissButtonStyle.DONE].
987 988
  ///
  ///**NOTE**: available on iOS 11.0+.
989
  IOSSafariDismissButtonStyle dismissButtonStyle;
990

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
991
  ///Set the custom background color of the navigation bar and the toolbar.
992 993
  ///
  ///**NOTE**: available on iOS 10.0+.
994
  String preferredBarTintColor;
995

Lorenzo Pichilli's avatar
Lorenzo Pichilli committed
996
  ///Set the custom color of the control buttons on the navigation bar and the toolbar.
997 998
  ///
  ///**NOTE**: available on iOS 10.0+.
999
  String preferredControlTintColor;
1000

1001 1002
  ///Set the custom modal presentation style when presenting the WebView. The default value is [IOSUIModalPresentationStyle.FULL_SCREEN].
  IOSUIModalPresentationStyle presentationStyle;
1003

1004 1005
  ///Set to the custom transition style when presenting the WebView. The default value is [IOSUIModalTransitionStyle.COVER_VERTICAL].
  IOSUIModalTransitionStyle transitionStyle;
1006

1007
  IOSSafariOptions(
1008 1009
      {this.entersReaderIfAvailable = false,
      this.barCollapsingEnabled = false,
1010
      this.dismissButtonStyle = IOSSafariDismissButtonStyle.DONE,
1011 1012
      this.preferredBarTintColor = "",
      this.preferredControlTintColor = "",
1013 1014
      this.presentationStyle = IOSUIModalPresentationStyle.FULL_SCREEN,
      this.transitionStyle = IOSUIModalTransitionStyle.COVER_VERTICAL});
1015 1016 1017 1018 1019 1020

  @override
  Map<String, dynamic> toMap() {
    return {
      "entersReaderIfAvailable": entersReaderIfAvailable,
      "barCollapsingEnabled": barCollapsingEnabled,
1021
      "dismissButtonStyle": dismissButtonStyle.toValue(),
1022 1023
      "preferredBarTintColor": preferredBarTintColor,
      "preferredControlTintColor": preferredControlTintColor,
1024
      "presentationStyle": presentationStyle.toValue(),
1025
      "transitionStyle": transitionStyle.toValue()
1026 1027
    };
  }
1028

1029 1030
  static IOSSafariOptions fromMap(Map<String, dynamic> map) {
    IOSSafariOptions options = new IOSSafariOptions();
1031 1032
    options.entersReaderIfAvailable = map["entersReaderIfAvailable"];
    options.barCollapsingEnabled = map["barCollapsingEnabled"];
1033
    options.dismissButtonStyle =
1034
        IOSSafariDismissButtonStyle.fromValue(map["dismissButtonStyle"]);
1035 1036
    options.preferredBarTintColor = map["preferredBarTintColor"];
    options.preferredControlTintColor = map["preferredControlTintColor"];
1037
    options.presentationStyle =
1038
        IOSUIModalPresentationStyle.fromValue(map["presentationStyle"]);
1039
    options.transitionStyle =
1040
        IOSUIModalTransitionStyle.fromValue(map["transitionStyle"]);
1041 1042
    return options;
  }
1043
}