2018-12-07 19:52:24 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_inappbrowser/flutter_inappbrowser.dart';
|
|
|
|
|
2019-11-10 13:11:30 +00:00
|
|
|
class MyInAppBrowser extends InAppBrowser {
|
2019-03-11 02:34:58 +00:00
|
|
|
|
|
|
|
@override
|
2018-12-07 19:52:24 +00:00
|
|
|
Future onBrowserCreated() async {
|
|
|
|
print("\n\nBrowser Ready!\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future onLoadStart(String url) async {
|
|
|
|
print("\n\nStarted $url\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future onLoadStop(String url) async {
|
|
|
|
print("\n\nStopped $url\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future onScrollChanged(int x, int y) async {
|
|
|
|
print("Scrolled: x:$x y:$y");
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void onLoadError(String url, int code, String message) {
|
|
|
|
print("Can't load $url.. Error: $message");
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void onProgressChanged(int progress) {
|
|
|
|
print("Progress: $progress");
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void onExit() {
|
|
|
|
print("\n\nBrowser closed!\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void shouldOverrideUrlLoading(String url) {
|
|
|
|
print("\n\n override $url\n\n");
|
2019-11-10 13:11:30 +00:00
|
|
|
this.webViewController.loadUrl(url: url);
|
2018-12-07 19:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2019-11-04 00:39:23 +00:00
|
|
|
void onLoadResource(LoadedResource response) {
|
2018-12-07 19:52:24 +00:00
|
|
|
print("Started at: " +
|
|
|
|
response.startTime.toString() +
|
|
|
|
"ms ---> duration: " +
|
|
|
|
response.duration.toString() +
|
|
|
|
"ms " +
|
|
|
|
response.url);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void onConsoleMessage(ConsoleMessage consoleMessage) {
|
2019-03-15 01:55:50 +00:00
|
|
|
print("""
|
|
|
|
console output:
|
|
|
|
sourceURL: ${consoleMessage.sourceURL}
|
|
|
|
lineNumber: ${consoleMessage.lineNumber}
|
|
|
|
message: ${consoleMessage.message}
|
2019-10-29 14:27:50 +00:00
|
|
|
messageLevel: ${consoleMessage.messageLevel.toValue()}
|
2019-03-15 01:55:50 +00:00
|
|
|
""");
|
2018-12-07 19:52:24 +00:00
|
|
|
}
|
2019-10-26 02:42:50 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void onDownloadStart(String url) {
|
|
|
|
print("Download of " + url);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<CustomSchemeResponse> onLoadResourceCustomScheme(String scheme, String url) async {
|
|
|
|
print("custom scheme: " + scheme);
|
2019-11-10 13:11:30 +00:00
|
|
|
return null;
|
2019-10-26 02:42:50 +00:00
|
|
|
}
|
2019-10-28 03:58:25 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Future<GeolocationPermissionShowPromptResponse> onGeolocationPermissionsShowPrompt(String origin) async {
|
|
|
|
print("request Geolocation permission API");
|
2019-11-10 13:11:30 +00:00
|
|
|
return null;
|
2019-10-28 03:58:25 +00:00
|
|
|
}
|
2019-10-29 11:16:31 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Future<JsAlertResponse> onJsAlert(String message) async {
|
|
|
|
return new JsAlertResponse(handledByClient: false, message: "coma iam");
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<JsConfirmResponse> onJsConfirm(String message) {
|
2019-11-10 13:11:30 +00:00
|
|
|
return null;
|
2019-10-29 11:16:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<JsPromptResponse> onJsPrompt(String message, String defaultValue) {
|
2019-11-10 13:11:30 +00:00
|
|
|
return null;
|
2019-10-29 11:16:31 +00:00
|
|
|
}
|
2018-12-07 19:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class WebviewExampleScreen extends StatefulWidget {
|
2019-11-10 13:11:30 +00:00
|
|
|
final MyInAppBrowser browser = new MyInAppBrowser();
|
|
|
|
static BuildContext context;
|
2019-10-29 11:16:31 +00:00
|
|
|
|
2018-12-07 19:52:24 +00:00
|
|
|
@override
|
|
|
|
_WebviewExampleScreenState createState() => new _WebviewExampleScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _WebviewExampleScreenState extends State<WebviewExampleScreen> {
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-10-29 11:16:31 +00:00
|
|
|
WebviewExampleScreen.context = context;
|
2018-12-07 19:52:24 +00:00
|
|
|
return new Center(
|
|
|
|
child: new RaisedButton(
|
|
|
|
onPressed: () {
|
2019-10-29 11:16:31 +00:00
|
|
|
widget.browser.openFile(
|
2019-11-10 13:11:30 +00:00
|
|
|
assetFilePath: "assets/index.html",
|
2019-10-29 11:16:31 +00:00
|
|
|
//url: "https://www.google.com/",
|
2019-11-04 00:39:23 +00:00
|
|
|
options: InAppBrowserClassOptions(
|
|
|
|
inAppWebViewWidgetOptions: InAppWebViewWidgetOptions(
|
|
|
|
inAppWebViewOptions: InAppWebViewOptions(
|
2019-10-29 11:16:31 +00:00
|
|
|
useShouldOverrideUrlLoading: true,
|
|
|
|
useOnLoadResource: true,
|
2019-11-04 00:39:23 +00:00
|
|
|
)
|
2019-10-29 11:16:31 +00:00
|
|
|
)
|
2019-11-04 00:39:23 +00:00
|
|
|
)
|
2019-06-07 00:13:56 +00:00
|
|
|
);
|
2018-12-07 19:52:24 +00:00
|
|
|
},
|
|
|
|
child: Text("Open Webview Browser")),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|