Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebView control #2049

Merged
merged 4 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion client/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
Expand Down
16 changes: 11 additions & 5 deletions client/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ PODS:
- SwiftyGif (5.4.3)
- url_launcher_ios (0.0.1):
- Flutter
- webview_flutter_wkwebview (0.0.1):
- Flutter

DEPENDENCIES:
- audioplayers_darwin (from `.symlinks/plugins/audioplayers_darwin/ios`)
Expand All @@ -60,8 +62,9 @@ DEPENDENCIES:
- integration_test (from `.symlinks/plugins/integration_test/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- sensors_plus (from `.symlinks/plugins/sensors_plus/ios`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/ios`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
- webview_flutter_wkwebview (from `.symlinks/plugins/webview_flutter_wkwebview/ios`)

SPEC REPOS:
trunk:
Expand All @@ -84,9 +87,11 @@ EXTERNAL SOURCES:
sensors_plus:
:path: ".symlinks/plugins/sensors_plus/ios"
shared_preferences_foundation:
:path: ".symlinks/plugins/shared_preferences_foundation/ios"
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"
url_launcher_ios:
:path: ".symlinks/plugins/url_launcher_ios/ios"
webview_flutter_wkwebview:
:path: ".symlinks/plugins/webview_flutter_wkwebview/ios"

SPEC CHECKSUMS:
audioplayers_darwin: 877d9a4d06331c5c374595e46e16453ac7eafa40
Expand All @@ -95,12 +100,13 @@ SPEC CHECKSUMS:
file_picker: ce3938a0df3cc1ef404671531facef740d03f920
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
integration_test: 13825b8a9334a850581300559b8839134b124670
path_provider_foundation: eaf5b3e458fc0e5fbb9940fb09980e853fe058b8
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
SDWebImage: 72f86271a6f3139cc7e4a89220946489d4b9a866
sensors_plus: 5717760720f7e6acd96fdbd75b7428f5ad755ec2
shared_preferences_foundation: 297b3ebca31b34ec92be11acd7fb0ba932c822ca
shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126
SwiftyGif: 6c3eafd0ce693cad58bb63d2b2fb9bacb8552780
url_launcher_ios: ae1517e5e344f5544fb090b079e11f399dfbe4d2
url_launcher_ios: 08a3dfac5fb39e8759aeb0abbd5d9480f30fc8b4
webview_flutter_wkwebview: 2e2d318f21a5e036e2c3f26171342e95908bd60a

PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3

Expand Down
2 changes: 1 addition & 1 deletion client/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
32 changes: 32 additions & 0 deletions client/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,38 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.2"
webview_flutter:
dependency: transitive
description:
name: webview_flutter
sha256: "82f6787d5df55907aa01e49bd9644f4ed1cc82af7a8257dd9947815959d2e755"
url: "https://pub.dev"
source: hosted
version: "4.2.4"
webview_flutter_android:
dependency: transitive
description:
name: webview_flutter_android
sha256: ddc167c6676f57c8b367d19fcbee267d6dc6adf81bd6c3cb87981d30746e0a6d
url: "https://pub.dev"
source: hosted
version: "3.10.1"
webview_flutter_platform_interface:
dependency: transitive
description:
name: webview_flutter_platform_interface
sha256: "6d9213c65f1060116757a7c473247c60f3f7f332cac33dc417c9e362a9a13e4f"
url: "https://pub.dev"
source: hosted
version: "2.6.0"
webview_flutter_wkwebview:
dependency: transitive
description:
name: webview_flutter_wkwebview
sha256: "485af05f2c5f83c7f78c20e236b170ad02df7153b299ae9917345be43871d29f"
url: "https://pub.dev"
source: hosted
version: "3.8.0"
win32:
dependency: transitive
description:
Expand Down
7 changes: 7 additions & 0 deletions package/lib/src/controls/create_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import 'textfield.dart';
import 'tooltip.dart';
import 'transparent_pointer.dart';
import 'vertical_divider.dart';
import 'webview.dart';
import 'window_drag_area.dart';

Widget createControl(Control? parent, String id, bool parentDisabled,
Expand Down Expand Up @@ -570,6 +571,12 @@ Widget createWidget(Key? key, ControlViewModel controlView, Control? parent,
control: controlView.control,
children: controlView.children,
parentDisabled: parentDisabled);
case "webview":
return WebViewControl(
key: key,
parent: parent,
control: controlView.control,
parentDisabled: parentDisabled);
default:
throw Exception("Unknown control type: ${controlView.control.type}");
}
Expand Down
95 changes: 95 additions & 0 deletions package/lib/src/controls/webview.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import 'dart:io' show Platform;
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:webview_flutter/webview_flutter.dart';

import '../flet_app_services.dart';
import '../models/app_state.dart';
import '../models/control.dart';
import '../models/control_tree_view_model.dart';
import '../utils/colors.dart';
import 'create_control.dart';
import 'error.dart';

class WebViewControl extends StatelessWidget {
final Control? parent;
final Control control;
final bool parentDisabled;

const WebViewControl(
{Key? key,
required this.parent,
required this.control,
required this.parentDisabled})
: super(key: key);

@override
Widget build(BuildContext context) {
var result = StoreConnector<AppState, ControlTreeViewModel>(
distinct: true,
converter: (store) => ControlTreeViewModel.fromStore(store, control),
builder: (context, viewModel) {
debugPrint("WebViewControl build: ${control.id}");

String url = control.attrString("url", "")!;
if (url == "") {
return const ErrorControl("WebView.url cannot be empty.");
}

bool javascriptEnabled =
control.attrBool("javascriptEnabled", false)!;
var bgcolor = HexColor.fromString(
Theme.of(context), control.attrString("bgcolor", "")!);
String preventLink = control.attrString("preventLink", "")!;

if (Platform.isIOS || Platform.isAndroid) {
var controller = WebViewController()
..setJavaScriptMode(javascriptEnabled
? JavaScriptMode.unrestricted
: JavaScriptMode.disabled)
..setNavigationDelegate(
NavigationDelegate(
onProgress: (int progress) {},
onPageStarted: (String url) {
FletAppServices.of(context).server.sendPageEvent(
eventTarget: control.id,
eventName: "page_started",
eventData: url);
},
onPageFinished: (String url) {
FletAppServices.of(context).server.sendPageEvent(
eventTarget: control.id,
eventName: "page_ended",
eventData: url);
},
onWebResourceError: (WebResourceError error) {
FletAppServices.of(context).server.sendPageEvent(
eventTarget: control.id,
eventName: "web_resource_error",
eventData: error.toString());
},
onNavigationRequest: (NavigationRequest request) {
if (preventLink != "" &&
request.url.startsWith(preventLink)) {
return NavigationDecision.prevent;
}
return NavigationDecision.navigate;
},
),
);
if (bgcolor != null) {
controller.setBackgroundColor(bgcolor);
}
controller.loadRequest(Uri.parse(url));
return WebViewWidget(controller: controller);
} else {
return const ErrorControl(
"WebView control is not supported on this platform yet.");
}
});

return constrainedControl(context, result, parent, control);
}
}
2 changes: 2 additions & 0 deletions package/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ dependencies:
js: ^0.6.5
fl_chart: ^0.64.0

webview_flutter: ^4.2.4

dev_dependencies:
flutter_test:
sdk: flutter
Expand Down
1 change: 1 addition & 0 deletions sdk/python/packages/flet-core/src/flet_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,5 +204,6 @@
from flet_core.vertical_divider import VerticalDivider
from flet_core.view import View
from flet_core.window_drag_area import WindowDragArea
from flet_core.webview import WebView
from flet_core.range_slider import RangeSlider
from flet_core.badge import Badge
Loading