flet-webview 0.2.0.dev49__tar.gz → 0.2.0.dev66__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of flet-webview might be problematic. Click here for more details.

Files changed (31) hide show
  1. {flet_webview-0.2.0.dev49/src/flet_webview.egg-info → flet_webview-0.2.0.dev66}/PKG-INFO +6 -4
  2. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66}/README.md +5 -3
  3. flet_webview-0.2.0.dev66/pyproject.toml +97 -0
  4. flet_webview-0.2.0.dev66/src/flet_webview/__init__.py +19 -0
  5. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66}/src/flet_webview/types.py +28 -7
  6. flet_webview-0.2.0.dev66/src/flet_webview/webview.py +384 -0
  7. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66/src/flet_webview.egg-info}/PKG-INFO +6 -4
  8. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66}/src/flutter/flet_webview/lib/src/utils/webview.dart +8 -0
  9. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66}/src/flutter/flet_webview/lib/src/webview_mobile_and_mac.dart +3 -4
  10. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66}/src/flutter/flet_webview/pubspec.lock +60 -44
  11. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66}/src/flutter/flet_webview/pubspec.yaml +1 -1
  12. flet_webview-0.2.0.dev49/pyproject.toml +0 -71
  13. flet_webview-0.2.0.dev49/src/flet_webview/__init__.py +0 -8
  14. flet_webview-0.2.0.dev49/src/flet_webview/webview.py +0 -517
  15. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66}/LICENSE +0 -0
  16. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66}/setup.cfg +0 -0
  17. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66}/src/flet_webview.egg-info/SOURCES.txt +0 -0
  18. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66}/src/flet_webview.egg-info/dependency_links.txt +0 -0
  19. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66}/src/flet_webview.egg-info/requires.txt +0 -0
  20. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66}/src/flet_webview.egg-info/top_level.txt +0 -0
  21. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66}/src/flutter/flet_webview/CHANGELOG.md +0 -0
  22. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66}/src/flutter/flet_webview/LICENSE +0 -0
  23. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66}/src/flutter/flet_webview/README.md +0 -0
  24. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66}/src/flutter/flet_webview/analysis_options.yaml +0 -0
  25. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66}/src/flutter/flet_webview/lib/flet_webview.dart +0 -0
  26. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66}/src/flutter/flet_webview/lib/src/extension.dart +0 -0
  27. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66}/src/flutter/flet_webview/lib/src/webview.dart +0 -0
  28. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66}/src/flutter/flet_webview/lib/src/webview_web.dart +0 -0
  29. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66}/src/flutter/flet_webview/lib/src/webview_web_vain.dart +0 -0
  30. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66}/src/flutter/flet_webview/lib/src/webview_windows_and_linux.dart +0 -0
  31. {flet_webview-0.2.0.dev49 → flet_webview-0.2.0.dev66}/src/flutter/flet_webview/lib/src/webview_windows_and_linux_vain.dart +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flet-webview
3
- Version: 0.2.0.dev49
3
+ Version: 0.2.0.dev66
4
4
  Summary: Display web content in Flet apps using WebView.
5
5
  Author-email: Flet contributors <hello@flet.dev>
6
6
  License-Expression: Apache-2.0
@@ -42,7 +42,9 @@ This package supports the following platforms:
42
42
  | Android | ✅ |
43
43
  | Web | ✅ |
44
44
 
45
- ## Installation
45
+ ## Usage
46
+
47
+ ### Installation
46
48
 
47
49
  To install the `flet-webview` package and add it to your project dependencies:
48
50
 
@@ -62,6 +64,6 @@ To install the `flet-webview` package and add it to your project dependencies:
62
64
  poetry add flet-webview
63
65
  ```
64
66
 
65
- ## Examples
67
+ ### Examples
66
68
 
67
- For examples, see [this](./examples)
69
+ For examples, see [these](./examples).
@@ -26,7 +26,9 @@ This package supports the following platforms:
26
26
  | Android | ✅ |
27
27
  | Web | ✅ |
28
28
 
29
- ## Installation
29
+ ## Usage
30
+
31
+ ### Installation
30
32
 
31
33
  To install the `flet-webview` package and add it to your project dependencies:
32
34
 
@@ -46,6 +48,6 @@ To install the `flet-webview` package and add it to your project dependencies:
46
48
  poetry add flet-webview
47
49
  ```
48
50
 
49
- ## Examples
51
+ ### Examples
50
52
 
51
- For examples, see [this](./examples)
53
+ For examples, see [these](./examples).
@@ -0,0 +1,97 @@
1
+ [project]
2
+ name = "flet-webview"
3
+ version = "0.2.0.dev66"
4
+ description = "Display web content in Flet apps using WebView."
5
+ readme = "README.md"
6
+ authors = [{ name = "Flet contributors", email = "hello@flet.dev" }]
7
+ license = "Apache-2.0"
8
+ requires-python = ">=3.10"
9
+ dependencies = [
10
+ "flet >=0.70.0.dev0",
11
+ ]
12
+
13
+ [project.urls]
14
+ Homepage = "https://flet.dev"
15
+ Documentation = "https://flet-dev.github.io/flet-webview"
16
+ Repository = "https://github.com/flet-dev/flet-webview"
17
+ Issues = "https://github.com/flet-dev/flet-webview/issues"
18
+
19
+ [tool.setuptools.package-data]
20
+ "flutter.flet_webview" = ["**/*"]
21
+
22
+ [dependency-groups]
23
+ test = [
24
+ "pytest >=7.2.0",
25
+ ]
26
+ lint = [
27
+ "ruff >=0.11.7",
28
+ ]
29
+ dev = [
30
+ "pre-commit >=4.2.0",
31
+ { include-group = 'lint' },
32
+ { include-group = 'test' },
33
+ ]
34
+ docs-coverage = [
35
+ "docstr-coverage >=2.3.2",
36
+ ]
37
+ docs = [
38
+ "mkdocs >=1.6.1",
39
+ "mkdocs-material >=9.6.15",
40
+ "mkdocstrings-python >=1.16.12",
41
+ "mkdocstrings-python-xref >=1.16.3",
42
+ "mike >=2.1.3",
43
+ "markdown >=3.6",
44
+ "pymdown-extensions >=10.16",
45
+ "mkdocs-exclude >=1.0.2",
46
+ "mkdocs-glightbox >=0.4.0",
47
+ "mkdocs-open-in-new-tab >=1.0.8",
48
+ "mkdocs-section-index >=0.3.10",
49
+ "griffe-modernized-annotations >=1.0.8",
50
+ "griffe-warnings-deprecated >=1.1.0",
51
+ "pygments >=2.16",
52
+ "markdown-exec[ansi] >=1.11.0",
53
+ "pydocstyle >=6.3.0",
54
+ "linkcheckmd >=1.4.0",
55
+ "mkdocs-external-images",
56
+ { include-group = 'docs-coverage' },
57
+ ]
58
+ all = [
59
+ { include-group = 'dev' },
60
+ { include-group = 'docs' },
61
+ ]
62
+
63
+ [tool.uv.sources]
64
+ mkdocs-external-images = { git = "https://github.com/flet-dev/mkdocs-external-images", tag = "v0.2.0" }
65
+
66
+ [build-system]
67
+ requires = ["setuptools"]
68
+ build-backend = "setuptools.build_meta"
69
+
70
+ [tool.ruff]
71
+ line-length = 88
72
+ target-version = "py39"
73
+ fix = true
74
+ show-fixes = true
75
+
76
+ [tool.ruff.lint]
77
+ select = [
78
+ # pycodestyle
79
+ "E",
80
+ # Pyflakes
81
+ "F",
82
+ # pyupgrade
83
+ "UP",
84
+ # flake8-bugbear
85
+ "B",
86
+ # flake8-simplify
87
+ "SIM",
88
+ # isort
89
+ "I"
90
+ ]
91
+ preview = true
92
+ pydocstyle = { convention = 'google' }
93
+
94
+ [tool.ruff.format]
95
+ quote-style = "double"
96
+ indent-style = "space"
97
+ line-ending = "auto"
@@ -0,0 +1,19 @@
1
+ from flet_webview.types import (
2
+ JavaScriptMode,
3
+ LogLevelSeverity,
4
+ RequestMethod,
5
+ WebViewConsoleMessageEvent,
6
+ WebViewJavaScriptEvent,
7
+ WebViewScrollEvent,
8
+ )
9
+ from flet_webview.webview import WebView
10
+
11
+ __all__ = [
12
+ "JavaScriptMode",
13
+ "LogLevelSeverity",
14
+ "RequestMethod",
15
+ "WebView",
16
+ "WebViewConsoleMessageEvent",
17
+ "WebViewJavaScriptEvent",
18
+ "WebViewScrollEvent",
19
+ ]
@@ -1,14 +1,19 @@
1
1
  from dataclasses import dataclass
2
2
  from enum import Enum
3
+ from typing import TYPE_CHECKING
3
4
 
4
5
  import flet as ft
5
6
 
7
+ if TYPE_CHECKING:
8
+ from flet_webview.webview import WebView # noqa
9
+
6
10
  __all__ = [
7
- "RequestMethod",
11
+ "JavaScriptMode",
8
12
  "LogLevelSeverity",
9
- "WebViewScrollEvent",
13
+ "RequestMethod",
10
14
  "WebViewConsoleMessageEvent",
11
15
  "WebViewJavaScriptEvent",
16
+ "WebViewScrollEvent",
12
17
  ]
13
18
 
14
19
 
@@ -44,17 +49,33 @@ class LogLevelSeverity(Enum):
44
49
  """Indicates a log message was logged using the `console.log` method."""
45
50
 
46
51
 
52
+ class JavaScriptMode(Enum):
53
+ """Defines the state of JavaScript support in the `WebView`."""
54
+
55
+ UNRESTRICTED = "unrestricted"
56
+ """JavaScript execution is unrestricted."""
57
+
58
+ DISABLED = "disabled"
59
+ """JavaScript execution is disabled."""
60
+
61
+
47
62
  @dataclass
48
- class WebViewScrollEvent(ft.Event[ft.EventControlType]):
63
+ class WebViewScrollEvent(ft.Event["WebView"]):
49
64
  x: float
50
- """The value of the horizontal offset with the origin being at the leftmost of the `WebView`."""
65
+ """
66
+ The value of the horizontal offset with the origin being at the
67
+ leftmost of the `WebView`.
68
+ """
51
69
 
52
70
  y: float
53
- """The value of the vertical offset with the origin being at the topmost of the `WebView`."""
71
+ """
72
+ The value of the vertical offset with the origin being at the
73
+ topmost of the `WebView`.
74
+ """
54
75
 
55
76
 
56
77
  @dataclass
57
- class WebViewConsoleMessageEvent(ft.Event[ft.EventControlType]):
78
+ class WebViewConsoleMessageEvent(ft.Event["WebView"]):
58
79
  message: str
59
80
  """The message written to the console."""
60
81
 
@@ -63,7 +84,7 @@ class WebViewConsoleMessageEvent(ft.Event[ft.EventControlType]):
63
84
 
64
85
 
65
86
  @dataclass
66
- class WebViewJavaScriptEvent(ft.Event[ft.EventControlType]):
87
+ class WebViewJavaScriptEvent(ft.Event["WebView"]):
67
88
  message: str
68
89
  """The message to be displayed in the window."""
69
90
 
@@ -0,0 +1,384 @@
1
+ from typing import Optional
2
+
3
+ import flet as ft
4
+
5
+ from flet_webview.types import (
6
+ JavaScriptMode,
7
+ RequestMethod,
8
+ WebViewConsoleMessageEvent,
9
+ WebViewJavaScriptEvent,
10
+ WebViewScrollEvent,
11
+ )
12
+
13
+ __all__ = ["WebView"]
14
+
15
+
16
+ @ft.control("WebView")
17
+ class WebView(ft.ConstrainedControl):
18
+ """
19
+ Easily load webpages while allowing user interaction.
20
+
21
+ Note:
22
+ Works only on the following platforms: iOS, Android, macOS and Web.
23
+ """
24
+
25
+ url: str
26
+ """The URL of the web page to load."""
27
+
28
+ prevent_links: Optional[list[str]] = None
29
+ """List of url-prefixes that should not be followed/loaded/downloaded."""
30
+
31
+ bgcolor: Optional[ft.ColorValue] = None
32
+ """Defines the background color of the WebView."""
33
+
34
+ on_page_started: Optional[ft.ControlEventHandler["WebView"]] = None
35
+ """
36
+ Fires soon as the first loading process of the webview page is started.
37
+
38
+ Event handler argument's [`data`][flet.Event.data] property is of type
39
+ `str` and contains the URL.
40
+
41
+ Note:
42
+ Works only on the following platforms: iOS, Android and macOS.
43
+ """
44
+
45
+ on_page_ended: Optional[ft.ControlEventHandler["WebView"]] = None
46
+ """
47
+ Fires when all the webview page loading processes are ended.
48
+
49
+ Event handler argument's [`data`][flet.Event.data] property is of type `str`
50
+ and contains the URL.
51
+
52
+ Note:
53
+ Works only on the following platforms: iOS, Android and macOS.
54
+ """
55
+
56
+ on_web_resource_error: Optional[ft.ControlEventHandler["WebView"]] = None
57
+ """
58
+ Fires when there is error with loading a webview page resource.
59
+
60
+ Event handler argument's [`data`][flet.Event.data] property is of type
61
+ `str` and contains the error message.
62
+
63
+ Note:
64
+ Works only on the following platforms: iOS, Android and macOS.
65
+ """
66
+
67
+ on_progress: Optional[ft.ControlEventHandler["WebView"]] = None
68
+ """
69
+ Fires when the progress of the webview page loading is changed.
70
+
71
+ Event handler argument's [`data`][flet.Event.data] property is of type
72
+ `int` and contains the progress value.
73
+
74
+ Note:
75
+ Works only on the following platforms: iOS, Android and macOS.
76
+ """
77
+
78
+ on_url_change: Optional[ft.ControlEventHandler["WebView"]] = None
79
+ """
80
+ Fires when the URL of the webview page is changed.
81
+
82
+ Event handler argument's [`data`][flet.Event.data] property is of type
83
+ `str` and contains the new URL.
84
+
85
+ Note:
86
+ Works only on the following platforms: iOS, Android and macOS.
87
+ """
88
+
89
+ on_scroll: Optional[ft.EventHandler[WebViewScrollEvent]] = None
90
+ """
91
+ Fires when the web page's scroll position changes.
92
+
93
+ Note:
94
+ Works only on the following platforms: iOS, Android and macOS.
95
+ """
96
+
97
+ on_console_message: Optional[ft.EventHandler[WebViewConsoleMessageEvent]] = None
98
+ """
99
+ Fires when a log message is written to the JavaScript console.
100
+
101
+ Note:
102
+ Works only on the following platforms: iOS, Android and macOS.
103
+ """
104
+
105
+ on_javascript_alert_dialog: Optional[ft.EventHandler[WebViewJavaScriptEvent]] = None
106
+ """
107
+ Fires when the web page attempts to display a JavaScript alert() dialog.
108
+
109
+ Note:
110
+ Works only on the following platforms: iOS, Android and macOS.
111
+ """
112
+
113
+ def _check_mobile_or_mac_platform(self):
114
+ """
115
+ Checks/Validates support for the current platform (iOS, Android, or macOS).
116
+ """
117
+ assert self.page is not None, "WebView must be added to page first."
118
+ if self.page.web or self.page.platform not in [
119
+ ft.PagePlatform.ANDROID,
120
+ ft.PagePlatform.IOS,
121
+ ft.PagePlatform.MACOS,
122
+ ]:
123
+ raise ft.FletUnsupportedPlatformException(
124
+ "This method is supported on Android, iOS and macOS platforms only."
125
+ )
126
+
127
+ async def reload(self):
128
+ """
129
+ Reloads the current URL.
130
+
131
+ Note:
132
+ Works only on the following platforms: iOS, Android and macOS.
133
+ """
134
+ self._check_mobile_or_mac_platform()
135
+ await self._invoke_method("reload")
136
+
137
+ async def can_go_back(self) -> bool:
138
+ """
139
+ Whether there's a back history item.
140
+
141
+ Note:
142
+ Works only on the following platforms: iOS, Android and macOS.
143
+
144
+ Returns:
145
+ `True` if there is a back history item, `False` otherwise.
146
+ """
147
+ self._check_mobile_or_mac_platform()
148
+ return await self._invoke_method("can_go_back")
149
+
150
+ async def can_go_forward(self) -> bool:
151
+ """
152
+ Whether there's a forward history item.
153
+
154
+ Note:
155
+ Works only on the following platforms: iOS, Android and macOS.
156
+
157
+ Returns:
158
+ `True` if there is a forward history item, `False` otherwise.
159
+ """
160
+ self._check_mobile_or_mac_platform()
161
+ return await self._invoke_method("can_go_forward")
162
+
163
+ async def go_back(self):
164
+ """
165
+ Goes back in the history of the webview, if `can_go_back()` is `True`.
166
+
167
+ Note:
168
+ Works only on the following platforms: iOS, Android and macOS.
169
+ """
170
+ self._check_mobile_or_mac_platform()
171
+ await self._invoke_method("go_back")
172
+
173
+ async def go_forward(self):
174
+ """
175
+ Goes forward in the history of the webview,
176
+ if [`can_go_forward()`][(c).can_go_forward] is `True`.
177
+
178
+ Note:
179
+ Works only on the following platforms: iOS, Android and macOS.
180
+ """
181
+ self._check_mobile_or_mac_platform()
182
+ await self._invoke_method("go_forward")
183
+
184
+ async def enable_zoom(self):
185
+ """
186
+ Enables zooming using the on-screen zoom controls and gestures.
187
+
188
+ Note:
189
+ Works only on the following platforms: iOS, Android and macOS.
190
+ """
191
+ self._check_mobile_or_mac_platform()
192
+ await self._invoke_method("enable_zoom")
193
+
194
+ async def disable_zoom(self):
195
+ """
196
+ Disables zooming using the on-screen zoom controls and gestures.
197
+
198
+ Note:
199
+ Works only on the following platforms: iOS, Android and macOS.
200
+ """
201
+ self._check_mobile_or_mac_platform()
202
+ await self._invoke_method("disable_zoom")
203
+
204
+ async def clear_cache(self):
205
+ """
206
+ Clears all caches used by the WebView.
207
+
208
+ The following caches are cleared:
209
+ - Browser HTTP Cache
210
+ - Cache API caches. Service workers tend to use this cache.
211
+ - Application cache
212
+
213
+ Note:
214
+ Works only on the following platforms: iOS, Android and macOS.
215
+ """
216
+ self._check_mobile_or_mac_platform()
217
+ await self._invoke_method("clear_cache")
218
+
219
+ async def clear_local_storage(self):
220
+ """
221
+ Clears the local storage used by the WebView.
222
+
223
+ Note:
224
+ Works only on the following platforms: iOS, Android and macOS.
225
+ """
226
+ self._check_mobile_or_mac_platform()
227
+ await self._invoke_method("clear_local_storage")
228
+
229
+ async def get_current_url(self) -> Optional[str]:
230
+ """
231
+ Gets the current URL that the WebView is displaying or `None`
232
+ if no URL was ever loaded.
233
+
234
+ Note:
235
+ Works only on the following platforms: iOS, Android and macOS.
236
+
237
+ Returns:
238
+ The current URL that the WebView is displaying or `None`
239
+ if no URL was ever loaded.
240
+ """
241
+ self._check_mobile_or_mac_platform()
242
+ return await self._invoke_method("get_current_url")
243
+
244
+ async def get_title(self) -> Optional[str]:
245
+ """
246
+ Get the title of the currently loaded page.
247
+
248
+ Note:
249
+ Works only on the following platforms: iOS, Android and macOS.
250
+
251
+ Returns:
252
+ The title of the currently loaded page.
253
+ """
254
+ self._check_mobile_or_mac_platform()
255
+ return await self._invoke_method("get_title")
256
+
257
+ async def get_user_agent(self) -> Optional[str]:
258
+ """
259
+ Get the value used for the HTTP `User-Agent:` request header.
260
+
261
+ Note:
262
+ Works only on the following platforms: iOS, Android and macOS.
263
+
264
+ Returns:
265
+ The value used for the HTTP `User-Agent:` request header.
266
+ """
267
+ self._check_mobile_or_mac_platform()
268
+ return await self._invoke_method("get_user_agent")
269
+
270
+ async def load_file(self, path: str):
271
+ """
272
+ Loads the provided local file.
273
+
274
+ Note:
275
+ Works only on the following platforms: iOS, Android and macOS.
276
+
277
+ Args:
278
+ path: The absolute path to the file.
279
+ """
280
+ self._check_mobile_or_mac_platform()
281
+ await self._invoke_method(
282
+ method_name="load_file",
283
+ arguments={"path": path},
284
+ )
285
+
286
+ async def load_request(self, url: str, method: RequestMethod = RequestMethod.GET):
287
+ """
288
+ Makes an HTTP request and loads the response in the webview.
289
+
290
+ Args:
291
+ url: The URL to load.
292
+ method: The HTTP method to use.
293
+
294
+ Note:
295
+ Works only on the following platforms: iOS, Android and macOS.
296
+ """
297
+ self._check_mobile_or_mac_platform()
298
+ await self._invoke_method(
299
+ "load_request", arguments={"url": url, "method": method}
300
+ )
301
+
302
+ async def run_javascript(self, value: str):
303
+ """
304
+ Runs the given JavaScript in the context of the current page.
305
+
306
+ Args:
307
+ value: The JavaScript code to run.
308
+
309
+ Note:
310
+ Works only on the following platforms: iOS, Android and macOS.
311
+ """
312
+ self._check_mobile_or_mac_platform()
313
+ await self._invoke_method(
314
+ method_name="run_javascript",
315
+ arguments={"value": value},
316
+ )
317
+
318
+ async def load_html(self, value: str, base_url: Optional[str] = None):
319
+ """
320
+ Loads the provided HTML string.
321
+
322
+ Note:
323
+ Works only on the following platforms: iOS, Android and macOS.
324
+
325
+ Args:
326
+ value: The HTML string to load.
327
+ base_url: The base URL to use when resolving relative URLs within the value.
328
+ """
329
+ self._check_mobile_or_mac_platform()
330
+ await self._invoke_method(
331
+ "load_html", arguments={"value": value, "base_url": base_url}
332
+ )
333
+
334
+ async def scroll_to(self, x: int, y: int):
335
+ """
336
+ Scrolls to the provided position of webview pixels.
337
+
338
+ Note:
339
+ Works only on the following platforms: iOS, Android and macOS.
340
+
341
+ Args:
342
+ x: The x-coordinate of the scroll position.
343
+ y: The y-coordinate of the scroll position.
344
+ """
345
+ self._check_mobile_or_mac_platform()
346
+ await self._invoke_method(
347
+ method_name="scroll_to",
348
+ arguments={"x": x, "y": y},
349
+ )
350
+
351
+ async def scroll_by(self, x: int, y: int):
352
+ """
353
+ Scrolls by the provided number of webview pixels.
354
+
355
+ Note:
356
+ Works only on the following platforms: iOS, Android and macOS.
357
+
358
+ Args:
359
+ x: The number of pixels to scroll by on the x-axis.
360
+ y: The number of pixels to scroll by on the y-axis.
361
+ """
362
+ self._check_mobile_or_mac_platform()
363
+ await self._invoke_method(
364
+ method_name="scroll_by",
365
+ arguments={"x": x, "y": y},
366
+ )
367
+
368
+ async def set_javascript_mode(self, mode: JavaScriptMode):
369
+ """
370
+ Sets the JavaScript mode of the WebView.
371
+
372
+ Note:
373
+ - Works only on the following platforms: iOS, Android and macOS.
374
+ - Disabling the JavaScript execution on the page may result to
375
+ unexpected web page behaviour.
376
+
377
+ Args:
378
+ mode: The JavaScript mode to set.
379
+ """
380
+ self._check_mobile_or_mac_platform()
381
+ await self._invoke_method(
382
+ method_name="set_javascript_mode",
383
+ arguments={"mode": mode},
384
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flet-webview
3
- Version: 0.2.0.dev49
3
+ Version: 0.2.0.dev66
4
4
  Summary: Display web content in Flet apps using WebView.
5
5
  Author-email: Flet contributors <hello@flet.dev>
6
6
  License-Expression: Apache-2.0
@@ -42,7 +42,9 @@ This package supports the following platforms:
42
42
  | Android | ✅ |
43
43
  | Web | ✅ |
44
44
 
45
- ## Installation
45
+ ## Usage
46
+
47
+ ### Installation
46
48
 
47
49
  To install the `flet-webview` package and add it to your project dependencies:
48
50
 
@@ -62,6 +64,6 @@ To install the `flet-webview` package and add it to your project dependencies:
62
64
  poetry add flet-webview
63
65
  ```
64
66
 
65
- ## Examples
67
+ ### Examples
66
68
 
67
- For examples, see [this](./examples)
69
+ For examples, see [these](./examples).
@@ -8,3 +8,11 @@ LoadRequestMethod? parseLoadRequestMethod(String? value,
8
8
  (e) => e.name.toLowerCase() == value.toLowerCase()) ??
9
9
  defaultValue;
10
10
  }
11
+
12
+ JavaScriptMode? parseJavaScriptMode(String? value,
13
+ [JavaScriptMode? defaultValue]) {
14
+ if (value == null) return defaultValue;
15
+ return JavaScriptMode.values.firstWhereOrNull(
16
+ (e) => e.name.toLowerCase() == value.toLowerCase()) ??
17
+ defaultValue;
18
+ }
@@ -154,10 +154,9 @@ class _WebviewMobileAndMacState extends State<WebviewMobileAndMac> {
154
154
  }
155
155
  break;
156
156
  case "set_javascript_mode":
157
- var value = parseBool(args["value"]);
158
- if (value != null) {
159
- await controller.setJavaScriptMode(
160
- value ? JavaScriptMode.unrestricted : JavaScriptMode.disabled);
157
+ var mode = parseJavaScriptMode(args["mode"]);
158
+ if (mode != null) {
159
+ await controller.setJavaScriptMode(mode);
161
160
  }
162
161
  break;
163
162
  default: