Skip to content

Commit

Permalink
update to latest versions on pub
Browse files Browse the repository at this point in the history
  • Loading branch information
rodydavis committed Jun 24, 2024
1 parent 4c31c14 commit 2e7099d
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 71 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.0.0

* Updated dependencies to latest versions
* Updated to Dart >=3.0.0 <4.0.0

## 1.6.0

* Adding windows platform
Expand Down
2 changes: 1 addition & 1 deletion example/lib/examples/basic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class _BasicExampleState extends State<BasicExample> {
),
Expanded(
flex: 1,
child: Container(
child: SizedBox(
width: (open) ? 500 : 0,
child: EasyWebView(
src: src3,
Expand Down
17 changes: 8 additions & 9 deletions example/lib/examples/html_to_pdf.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:convert';
import 'dart:developer';
import 'dart:typed_data';
import 'package:file_saver/file_saver.dart';

import 'package:easy_web_view/easy_web_view.dart';
Expand Down Expand Up @@ -75,17 +74,17 @@ class _HtmlToPdfTestState extends State<HtmlToPdfTest> {
// final pdfResult = utf8.decode(res);
if (kIsWeb) {
await FileSaver.instance.saveFile(
'easy_web_view_invoice',
res,
'pdf',
mimeType: MimeType.PDF,
name: 'easy_web_view_invoice',
bytes: res,
ext: 'pdf',
mimeType: MimeType.pdf,
);
} else {
await FileSaver.instance.saveAs(
'easy_web_view_invoice',
res,
'pdf',
MimeType.PDF,
name: 'easy_web_view_invoice',
bytes: res,
ext: 'pdf',
mimeType: MimeType.pdf,
);
}

Expand Down
4 changes: 4 additions & 0 deletions example/linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

#include "generated_plugin_registrant.h"

#include <file_saver/file_saver_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) file_saver_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSaverPlugin");
file_saver_plugin_register_with_registrar(file_saver_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
Expand Down
1 change: 1 addition & 0 deletions example/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
file_saver
url_launcher_linux
)

Expand Down
10 changes: 7 additions & 3 deletions example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ import Foundation
import audio_session
import file_saver
import just_audio
import path_provider_macos
import package_info_plus
import path_provider_foundation
import sqflite
import url_launcher_macos
import wakelock_macos
import video_player_avfoundation
import wakelock_plus

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AudioSessionPlugin.register(with: registry.registrar(forPlugin: "AudioSessionPlugin"))
FileSaverPlugin.register(with: registry.registrar(forPlugin: "FileSaverPlugin"))
JustAudioPlugin.register(with: registry.registrar(forPlugin: "JustAudioPlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
WakelockMacosPlugin.register(with: registry.registrar(forPlugin: "WakelockMacosPlugin"))
FVPVideoPlayerPlugin.register(with: registry.registrar(forPlugin: "FVPVideoPlayerPlugin"))
WakelockPlusMacosPlugin.register(with: registry.registrar(forPlugin: "WakelockPlusMacosPlugin"))
}
5 changes: 3 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ environment:
dependencies:
flutter:
sdk: flutter
file_saver: ^0.0.10
file_saver: ^0.2.13
easy_web_view:
path: ../

async: any
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^1.0.0
flutter_lints: ^4.0.0

flutter:
uses-material-design: true
Expand Down
9 changes: 4 additions & 5 deletions lib/src/platforms/base.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:webview_windows/webview_windows.dart'
show WebviewPopupWindowPolicy;
Expand All @@ -11,7 +12,6 @@ import 'package:flutter_widget_from_html/flutter_widget_from_html.dart'
OnErrorBuilder,
OnLoadingBuilder,
ImageMetadata,
RebuildTriggers,
RenderMode;

import 'package:flutter/material.dart';
Expand Down Expand Up @@ -83,7 +83,6 @@ class CrossWindowEvent {
});
}


typedef OnLoaded = void Function(EasyWebViewControllerWrapperBase controller);

abstract class EasyWebViewControllerWrapperBase {
Expand Down Expand Up @@ -143,12 +142,12 @@ class WidgetsWebViewOptions {
this.onLoadingBuilder,
this.onTapImage,
this.onTapUrl,
this.rebuildTriggers,
this.textStyle,
this.isSelectable = false,
this.enableCaching = true,
this.onSelectionChanged,
this.renderMode = RenderMode.column,
this.rebuildTriggers,
});

final bool? buildAsync;
Expand All @@ -160,11 +159,11 @@ class WidgetsWebViewOptions {
final CustomWidgetBuilder? customWidgetBuilder;
final OnErrorBuilder? onErrorBuilder;
final OnLoadingBuilder? onLoadingBuilder;
final SelectionChangedCallback? onSelectionChanged;
final ValueChanged<SelectedContent?>? onSelectionChanged;
final void Function(ImageMetadata)? onTapImage;
final FutureOr<bool> Function(String)? onTapUrl;
final RebuildTriggers? rebuildTriggers;
final RenderMode renderMode;
final List<dynamic>? rebuildTriggers;
final TextStyle? textStyle;
}

Expand Down
76 changes: 39 additions & 37 deletions lib/src/platforms/native.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'dart:io';
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart' as wv;
Expand Down Expand Up @@ -34,12 +34,13 @@ class EasyWebViewControllerWrapper extends EasyWebViewControllerWrapperBase {

@override
Future<void> evaluateJSMobile(String js) {
return _controller.runJavascript(js);
return _controller.runJavaScript(js);
}

@override
Future<String> evaluateJSWithResMobile(String js) {
return _controller.runJavascriptReturningResult(js);
Future<String> evaluateJSWithResMobile(String js) async {
final result = await _controller.runJavaScriptReturningResult(js);
return jsonEncode(result);
}

@override
Expand All @@ -56,9 +57,36 @@ class NativeWebViewState extends WebViewState<NativeWebView> {
@override
void initState() {
super.initState();

// Enable hybrid composition.
if (Platform.isAndroid) wv.WebView.platform = wv.SurfaceAndroidWebView();
controller = wv.WebViewController()
..setJavaScriptMode(wv.JavaScriptMode.unrestricted)
..setNavigationDelegate(
wv.NavigationDelegate(
onPageFinished: (url) {
if (widget.onLoaded != null) {
widget.onLoaded!(EasyWebViewControllerWrapper._(controller));
}
},
onNavigationRequest: (request) async {
if (widget.options.navigationDelegate == null) {
return wv.NavigationDecision.navigate;
}
final _navDecision = await widget //
.options
.navigationDelegate!(WebNavigationRequest(request.url));
return _navDecision == WebNavigationDecision.prevent
? wv.NavigationDecision.prevent
: wv.NavigationDecision.navigate;
},
),
);
for (final event in widget.options.crossWindowEvents) {
controller.addJavaScriptChannel(
event.name,
onMessageReceived: (javascriptMessage) {
event.eventAction(javascriptMessage.message);
},
);
}
}

@override
Expand All @@ -70,41 +98,15 @@ class NativeWebViewState extends WebViewState<NativeWebView> {
}

reload() {
controller.loadUrl(url);
final uri = Uri.parse(url);
controller.loadRequest(uri);
}

@override
Widget builder(BuildContext context, Size size, String contents) {
return wv.WebView(
return wv.WebViewWidget(
key: widget.key,
initialUrl: url,
javascriptMode: wv.JavascriptMode.unrestricted,
onWebViewCreated: (value) {
controller = value;
if (widget.onLoaded != null) {
widget.onLoaded!(EasyWebViewControllerWrapper._(value));
}
},
navigationDelegate: (navigationRequest) async {
if (widget.options.navigationDelegate == null) {
return wv.NavigationDecision.navigate;
}
final _navDecision = await widget.options
.navigationDelegate!(WebNavigationRequest(navigationRequest.url));
return _navDecision == WebNavigationDecision.prevent
? wv.NavigationDecision.prevent
: wv.NavigationDecision.navigate;
},
javascriptChannels: widget.options.crossWindowEvents.isNotEmpty
? widget.options.crossWindowEvents
.map((event) => wv.JavascriptChannel(
name: event.name,
onMessageReceived: (javascriptMessage) {
event.eventAction(javascriptMessage.message);
},
))
.toSet()
: Set<wv.JavascriptChannel>(),
controller: controller,
);
}
}
11 changes: 8 additions & 3 deletions lib/src/platforms/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,29 @@ class WidgetsWebViewState extends WebViewState<WidgetsWebView> {
@override
Widget builder(BuildContext context, Size size, String contents) {
final options = widget.options.widgets;
return wv.HtmlWidget(
Widget child = wv.HtmlWidget(
contents.toHtml(),
buildAsync: options.buildAsync,
enableCaching: options.enableCaching,
factoryBuilder: options.factoryBuilder,
isSelectable: options.isSelectable,
key: widget.key,
baseUrl: options.baseUrl,
customStylesBuilder: options.customStylesBuilder,
customWidgetBuilder: options.customWidgetBuilder,
onErrorBuilder: options.onErrorBuilder,
onLoadingBuilder: options.onLoadingBuilder,
onSelectionChanged: options.onSelectionChanged,
onTapImage: options.onTapImage,
onTapUrl: options.onTapUrl,
rebuildTriggers: options.rebuildTriggers,
renderMode: options.renderMode,
textStyle: options.textStyle,
);
if (options.isSelectable) {
child = SelectionArea(
child: child,
onSelectionChanged: options.onSelectionChanged,
);
}
return child;
}
}
22 changes: 11 additions & 11 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
name: easy_web_view
description: A super simple webview for Flutter Web, Mobile and Desktop
version: 1.6.0
version: 2.0.0
homepage: https://github.com/rodydavis/easy_web_view
repository: https://github.com/rodydavis/plugins
repository: https://github.com/rodydavis/easy_web_view
maintainer: Rody Davis (@rodydavis)
environment:
sdk: ">=2.12.0 <3.0.0"
sdk: ">=3.0.0 <4.0.0"

dependencies:
flutter:
sdk: flutter
flutter_markdown: ^0.6.6
flutter_widget_from_html: ^0.8.5
flutter_markdown: ^0.7.2+1
flutter_widget_from_html: ^0.15.1
html2md: ^1.2.5
http: ^0.13.3
markdown: ^4.0.0
permission_handler: ^9.2.0
http: ^1.2.1
markdown: ^7.2.2
permission_handler: ^11.3.1
url_launcher: ^6.0.12
webview_flutter: ^3.0.2
webview_windows: ^0.1.6
webview_flutter: ^4.8.0
webview_windows: ^0.4.0

dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^1.0.0
flutter_lints: ^4.0.0

flutter:
uses-material-design: true

0 comments on commit 2e7099d

Please sign in to comment.