Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Add Android debug mode #1497

Closed
wants to merge 3 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
FlutterWebView(Context context, BinaryMessenger messenger, int id, Map<String, Object> params) {
webView = new WebView(context);
platformThreadHandler = new Handler(context.getMainLooper());
boolean debug = (boolean) params.get("debug") || false;

WebView.setWebContentsDebuggingEnabled(debug);

// Allow local storage.
webView.getSettings().setDomStorageEnabled(true);

Expand Down
1 change: 1 addition & 0 deletions packages/webview_flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class WebViewExample extends StatelessWidget {
onPageFinished: (String url) {
print('Page finished loading: $url');
},
debug: true,
);
}),
floatingActionButton: favoriteButton(),
Expand Down
39 changes: 23 additions & 16 deletions packages/webview_flutter/lib/webview_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,17 @@ class WebView extends StatefulWidget {
/// `onWebViewCreated` callback once the web view is created.
///
/// The `javascriptMode` parameter must not be null.
const WebView({
Key key,
this.onWebViewCreated,
this.initialUrl,
this.javascriptMode = JavascriptMode.disabled,
this.javascriptChannels,
this.navigationDelegate,
this.gestureRecognizers,
this.onPageFinished,
}) : assert(javascriptMode != null),
const WebView(
{Key key,
this.onWebViewCreated,
this.initialUrl,
this.javascriptMode = JavascriptMode.disabled,
this.javascriptChannels,
this.navigationDelegate,
this.gestureRecognizers,
this.onPageFinished,
this.debug})
: assert(javascriptMode != null),
super(key: key);

/// If not null invoked once the web view is created.
Expand Down Expand Up @@ -204,6 +205,7 @@ class WebView extends StatefulWidget {
/// directly in the HTML has been loaded and code injected with
/// [WebViewController.evaluateJavascript] can assume this.
final PageFinishedCallback onPageFinished;
final bool debug;

@override
State<StatefulWidget> createState() => _WebViewState();
Expand Down Expand Up @@ -294,28 +296,33 @@ Set<String> _extractChannelNames(Set<JavascriptChannel> channels) {

class _CreationParams {
_CreationParams(
{this.initialUrl, this.settings, this.javascriptChannelNames});
{this.initialUrl,
this.settings,
this.javascriptChannelNames,
this.debug});

static _CreationParams fromWidget(WebView widget) {
return _CreationParams(
initialUrl: widget.initialUrl,
settings: _WebSettings.fromWidget(widget),
javascriptChannelNames:
_extractChannelNames(widget.javascriptChannels).toList(),
);
initialUrl: widget.initialUrl,
settings: _WebSettings.fromWidget(widget),
javascriptChannelNames:
_extractChannelNames(widget.javascriptChannels).toList(),
debug: widget.debug);
}

final String initialUrl;

final _WebSettings settings;

final List<String> javascriptChannelNames;
final bool debug;

Map<String, dynamic> toMap() {
return <String, dynamic>{
'initialUrl': initialUrl,
'settings': settings.toMap(),
'javascriptChannelNames': javascriptChannelNames,
'debug': debug
};
}
}
Expand Down