added main stub for web support, updated example, updated debug log
This commit is contained in:
parent
df6fe3f8ce
commit
85949e9858
|
@ -34,19 +34,16 @@ class _HeadlessInAppWebViewExampleScreenState
|
|||
print("CONSOLE MESSAGE: " + consoleMessage.message);
|
||||
},
|
||||
onLoadStart: (controller, url) async {
|
||||
print("onLoadStart $url");
|
||||
setState(() {
|
||||
this.url = url.toString();
|
||||
});
|
||||
},
|
||||
onLoadStop: (controller, url) async {
|
||||
print("onLoadStop $url");
|
||||
setState(() {
|
||||
this.url = url.toString();
|
||||
});
|
||||
},
|
||||
onUpdateVisitedHistory: (controller, url, androidIsReload) {
|
||||
print("onUpdateVisitedHistory $url");
|
||||
setState(() {
|
||||
this.url = url.toString();
|
||||
});
|
||||
|
@ -106,6 +103,9 @@ class _HeadlessInAppWebViewExampleScreenState
|
|||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
headlessWebView?.dispose();
|
||||
setState(() {
|
||||
this.url = "";
|
||||
});
|
||||
},
|
||||
child: Text("Dispose HeadlessInAppWebView")),
|
||||
)
|
||||
|
|
|
@ -19,19 +19,17 @@ class MyInAppBrowser extends InAppBrowser {
|
|||
|
||||
@override
|
||||
Future onLoadStart(url) async {
|
||||
print("\n\nStarted $url\n\n");
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
Future onLoadStop(url) async {
|
||||
pullToRefreshController?.endRefreshing();
|
||||
print("\n\nStopped $url\n\n");
|
||||
}
|
||||
|
||||
@override
|
||||
void onLoadError(url, code, message) {
|
||||
pullToRefreshController?.endRefreshing();
|
||||
print("Can't load $url.. Error: $message");
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -39,7 +37,6 @@ class MyInAppBrowser extends InAppBrowser {
|
|||
if (progress == 100) {
|
||||
pullToRefreshController?.endRefreshing();
|
||||
}
|
||||
print("Progress: $progress");
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -53,25 +50,6 @@ class MyInAppBrowser extends InAppBrowser {
|
|||
print("\n\nOverride ${navigationAction.request.url}\n\n");
|
||||
return NavigationActionPolicy.ALLOW;
|
||||
}
|
||||
|
||||
@override
|
||||
void onLoadResource(response) {
|
||||
print("Started at: " +
|
||||
response.startTime.toString() +
|
||||
"ms ---> duration: " +
|
||||
response.duration.toString() +
|
||||
"ms " +
|
||||
(response.url ?? '').toString());
|
||||
}
|
||||
|
||||
@override
|
||||
void onConsoleMessage(consoleMessage) {
|
||||
print("""
|
||||
console output:
|
||||
message: ${consoleMessage.message}
|
||||
messageLevel: ${consoleMessage.messageLevel.toValue()}
|
||||
""");
|
||||
}
|
||||
}
|
||||
|
||||
class InAppBrowserExampleScreen extends StatefulWidget {
|
||||
|
|
|
@ -19,10 +19,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
@JS()
|
||||
library flutter_inappwebview;
|
||||
|
||||
import 'package:js/js.dart';
|
||||
|
||||
export 'src/main.dart';
|
||||
export 'src/web/main.dart';
|
||||
export 'src/web/main_stub.dart' if (dart.library.html) 'src/web/main.dart';
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
import 'dart:typed_data';
|
||||
import 'dart:developer' as developer;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_inappwebview/src/util.dart';
|
||||
import '../util.dart';
|
||||
|
||||
import 'chrome_safari_browser_settings.dart';
|
||||
|
||||
|
@ -42,6 +44,13 @@ class ChromeSafariBrowserNotOpenedException implements Exception {
|
|||
///- Android native WebView
|
||||
///- iOS
|
||||
class ChromeSafariBrowser {
|
||||
///Enables [ChromeSafariBrowser] debug logging info.
|
||||
///
|
||||
///The default value is the same value of [kDebugMode],
|
||||
///so it is enabled by default when the application is compiled in debug mode
|
||||
///and disabled when it is not.
|
||||
static bool debugLogging = kDebugMode;
|
||||
|
||||
///View ID used internally.
|
||||
late final String id;
|
||||
|
||||
|
@ -60,7 +69,19 @@ class ChromeSafariBrowser {
|
|||
_isOpened = false;
|
||||
}
|
||||
|
||||
_debugLog(String method, dynamic args) {
|
||||
if (ChromeSafariBrowser.debugLogging) {
|
||||
String message =
|
||||
"ChromeSafariBrowser ID " + id + " calling \"" +
|
||||
method.toString() + "\" using " + args.toString();
|
||||
developer.log(message,
|
||||
name: this.runtimeType.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> handleMethod(MethodCall call) async {
|
||||
_debugLog(call.method, call.arguments);
|
||||
|
||||
switch (call.method) {
|
||||
case "onChromeSafariBrowserOpened":
|
||||
onOpened();
|
||||
|
|
|
@ -663,7 +663,7 @@ class _InAppWebViewState extends State<InAppWebView> {
|
|||
|
||||
@override
|
||||
void dispose() {
|
||||
int viewId = _controller.getViewId();
|
||||
dynamic viewId = _controller.getViewId();
|
||||
if (kIsWeb && WebPlatformManager.webViews.containsKey(viewId)) {
|
||||
WebPlatformManager.webViews.remove(viewId);
|
||||
}
|
||||
|
|
|
@ -105,14 +105,22 @@ class InAppWebViewController
|
|||
localStorage: LocalStorage(this), sessionStorage: SessionStorage(this));
|
||||
}
|
||||
|
||||
Future<dynamic> handleMethod(MethodCall call) async {
|
||||
|
||||
if (WebView.debugLogging && (call.method.startsWith("on") || call.method.startsWith("should")) &&
|
||||
call.method != "onCallJsHandler") {
|
||||
developer.log(
|
||||
call.method.toString() + ": using " + call.arguments.toString(),
|
||||
_debugLog(String method, dynamic args) {
|
||||
if (WebView.debugLogging) {
|
||||
String viewId = (getViewId() ?? _inAppBrowser?.id).toString();
|
||||
String message =
|
||||
(_inAppBrowser == null ? "WebView ID " : "InAppBrowser ID " + viewId) +
|
||||
" calling \"" +
|
||||
method.toString() + "\" using " + args.toString();
|
||||
developer.log(message,
|
||||
name: this.runtimeType.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> handleMethod(MethodCall call) async {
|
||||
if (WebView.debugLogging && call.method != "onCallJsHandler") {
|
||||
_debugLog(call.method, call.arguments);
|
||||
}
|
||||
|
||||
switch (call.method) {
|
||||
case "onLoadStart":
|
||||
|
@ -1032,11 +1040,7 @@ class InAppWebViewController
|
|||
// decode args to json
|
||||
List<dynamic> args = jsonDecode(call.arguments["args"]);
|
||||
|
||||
if (WebView.debugLogging && (handlerName.startsWith("on") || handlerName.startsWith("should"))) {
|
||||
developer.log(
|
||||
handlerName.toString() + ": using " + args.toString(),
|
||||
name: this.runtimeType.toString());
|
||||
}
|
||||
_debugLog(handlerName, args);
|
||||
|
||||
switch (handlerName) {
|
||||
case "onLoadResource":
|
||||
|
@ -3038,7 +3042,7 @@ class InAppWebViewController
|
|||
}
|
||||
|
||||
///Used internally.
|
||||
int getViewId() {
|
||||
dynamic getViewId() {
|
||||
return _id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import 'dart:collection';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview_web.dart';
|
||||
|
||||
import '../pull_to_refresh/pull_to_refresh_controller.dart';
|
||||
|
||||
import '../context_menu.dart';
|
||||
|
@ -10,10 +13,14 @@ import 'in_app_webview_controller.dart';
|
|||
import 'in_app_webview_settings.dart';
|
||||
import 'headless_in_app_webview.dart';
|
||||
|
||||
///Abstract class that represents a WebView. Used by [InAppWebView] and [HeadlessInAppWebView].
|
||||
///Abstract class that represents a WebView. Used by [InAppWebView], [HeadlessInAppWebView] and the WebView of [InAppBrowser].
|
||||
abstract class WebView {
|
||||
///Enables WebView debug logging info. Logging is on by default.
|
||||
static bool debugLogging = true;
|
||||
///Enables [WebView] debug logging info.
|
||||
///
|
||||
///The default value is the same value of [kDebugMode],
|
||||
///so it is enabled by default when the application is compiled in debug mode
|
||||
///and disabled when it is not.
|
||||
static bool debugLogging = kDebugMode;
|
||||
|
||||
///The window id of a [CreateWindowAction.windowId].
|
||||
final int? windowId;
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
///Stub for web support.
|
||||
class FlutterInAppWebViewWebPlatform {
|
||||
static void registerWith(dynamic registrar) {
|
||||
|
||||
}
|
||||
}
|
|
@ -35,7 +35,6 @@ flutter:
|
|||
pluginClass: FlutterInAppWebViewWebPlatform
|
||||
fileName: flutter_inappwebview_web.dart
|
||||
|
||||
|
||||
assets:
|
||||
- packages/flutter_inappwebview/assets/t_rex_runner/t-rex.html
|
||||
- packages/flutter_inappwebview/assets/t_rex_runner/t-rex.css
|
||||
|
|
Loading…
Reference in New Issue