Skip to content

Commit

Permalink
updated code docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pichillilorenzo committed Nov 10, 2019
1 parent bb0e7f7 commit 44c17d1
Show file tree
Hide file tree
Showing 12 changed files with 296 additions and 351 deletions.
206 changes: 91 additions & 115 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void run() {
break;

case MAKE_HTTPS:
if (url.startsWith("http://")) {
if (scheme.equals("http") && (port == -1 || port == 80)) {
String urlHttps = url.replace("http://", "https://");

Request mRequest = new Request.Builder().url(urlHttps).build();
Expand Down
4 changes: 2 additions & 2 deletions example/lib/chrome_safari_example.screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_inappbrowser/flutter_inappbrowser.dart';

class MyChromeSafariBrowser extends ChromeSafariBrowser {
MyChromeSafariBrowser(browserFallback) : super(browserFallback);
MyChromeSafariBrowser(browserFallback) : super(bFallback: browserFallback);
@override
void onOpened() {
print("ChromeSafari browser opened");
Expand Down Expand Up @@ -36,7 +36,7 @@ class _ChromeSafariExampleScreenState extends State<ChromeSafariExampleScreen> {
return new Center(
child: new RaisedButton(
onPressed: () async {
await widget.browser.open("https://flutter.dev/",
await widget.browser.open(url: "https://flutter.dev/",
options: ChromeSafariBrowserClassOptions(
androidChromeCustomTabsOptions: AndroidChromeCustomTabsOptions(addShareButton: false),
iosSafariOptions: IosSafariOptions(barCollapsingEnabled: true)
Expand Down
31 changes: 16 additions & 15 deletions example/lib/inline_example.screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> {
resourceCustomSchemes: ["my-special-custom-scheme"],
contentBlockers: [
ContentBlocker(
ContentBlockerTrigger(".*",
trigger: ContentBlockerTrigger(
urlFilter: ".*",
resourceType: [ContentBlockerTriggerResourceType.IMAGE, ContentBlockerTriggerResourceType.STYLE_SHEET],
ifTopUrl: ["https://getbootstrap.com/"]),
ContentBlockerAction(ContentBlockerActionType.BLOCK)
action: ContentBlockerAction(type: ContentBlockerActionType.BLOCK)
)
]
),
Expand All @@ -125,11 +126,11 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> {
if (Platform.isAndroid)
webView.startSafeBrowsing();

webView.addJavaScriptHandler('handlerFoo', (args) {
webView.addJavaScriptHandler(handlerName:'handlerFoo', callback: (args) {
return new Foo(bar: 'bar_value', baz: 'baz_value');
});

webView.addJavaScriptHandler('handlerFooWithArgs', (args) {
webView.addJavaScriptHandler(handlerName: 'handlerFooWithArgs', callback: (args) {
print(args);
return [args[0] + 5, !args[1], args[2][0], args[3]['foo']];
});
Expand All @@ -155,20 +156,20 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> {
var tRexHtml = await controller.getTRexRunnerHtml();
var tRexCss = await controller.getTRexRunnerCss();

controller.loadData("""
controller.loadData(data: """
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no">
<style>${tRexCss}</style>
<style>$tRexCss</style>
</head>
<body>
${tRexHtml}
$tRexHtml
<p>
URL ${url} failed to load.
URL $url failed to load.
</p>
<p>
Error: ${code}, ${message}
Error: $code, $message
</p>
</body>
</html>
Expand All @@ -182,7 +183,7 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> {
},
shouldOverrideUrlLoading: (InAppWebViewController controller, String url) {
print("override $url");
controller.loadUrl(url);
controller.loadUrl(url: url);
},
onLoadResource: (InAppWebViewController controller, LoadedResource response) {
print("Resource type: '"+response.initiatorType + "' started at: " +
Expand Down Expand Up @@ -212,14 +213,14 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> {
onLoadResourceCustomScheme: (InAppWebViewController controller, String scheme, String url) async {
if (scheme == "my-special-custom-scheme") {
var bytes = await rootBundle.load("assets/" + url.replaceFirst("my-special-custom-scheme://", "", 0));
var response = new CustomSchemeResponse(bytes.buffer.asUint8List(), "image/svg+xml", contentEnconding: "utf-8");
var response = new CustomSchemeResponse(data: bytes.buffer.asUint8List(), contentType: "image/svg+xml", contentEnconding: "utf-8");
return response;
}
return null;
},
onTargetBlank: (InAppWebViewController controller, String url) {
print("target _blank: " + url);
controller.loadUrl(url);
controller.loadUrl(url: url);
},
onGeolocationPermissionsShowPrompt: (InAppWebViewController controller, String origin) async {
GeolocationPermissionShowPromptResponse response;
Expand All @@ -234,14 +235,14 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> {
FlatButton(
child: Text("Close"),
onPressed: () {
response = new GeolocationPermissionShowPromptResponse(origin, false, false);
response = new GeolocationPermissionShowPromptResponse(origin: origin, allow: false, retain: false);
Navigator.of(context).pop();
},
),
FlatButton(
child: Text("Accept"),
onPressed: () {
response = new GeolocationPermissionShowPromptResponse(origin, true, true);
response = new GeolocationPermissionShowPromptResponse(origin: origin, allow: true, retain: true);
Navigator.of(context).pop();
},
),
Expand Down Expand Up @@ -312,7 +313,7 @@ class _InlineExampleScreenState extends State<InlineExampleScreen> {
return fetchRequest;
},
onNavigationStateChange: (InAppWebViewController controller, String url) async {
print("NAVIGATION STATE CHANGE: ${url}");
print("NAVIGATION STATE CHANGE: $url");
setState(() {
this.url = url;
});
Expand Down
16 changes: 9 additions & 7 deletions example/lib/webview_example.screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_inappbrowser/flutter_inappbrowser.dart';

class MyInappBrowser extends InAppBrowser {
class MyInAppBrowser extends InAppBrowser {

@override
Future onBrowserCreated() async {
Expand Down Expand Up @@ -43,7 +43,7 @@ class MyInappBrowser extends InAppBrowser {
@override
void shouldOverrideUrlLoading(String url) {
print("\n\n override $url\n\n");
this.webViewController.loadUrl(url);
this.webViewController.loadUrl(url: url);
}

@override
Expand Down Expand Up @@ -75,11 +75,13 @@ class MyInappBrowser extends InAppBrowser {
@override
Future<CustomSchemeResponse> onLoadResourceCustomScheme(String scheme, String url) async {
print("custom scheme: " + scheme);
return null;
}

@override
Future<GeolocationPermissionShowPromptResponse> onGeolocationPermissionsShowPrompt(String origin) async {
print("request Geolocation permission API");
return null;
}

@override
Expand All @@ -89,18 +91,18 @@ class MyInappBrowser extends InAppBrowser {

@override
Future<JsConfirmResponse> onJsConfirm(String message) {

return null;
}

@override
Future<JsPromptResponse> onJsPrompt(String message, String defaultValue) {

return null;
}
}

class WebviewExampleScreen extends StatefulWidget {
final MyInappBrowser browser = new MyInappBrowser();
static BuildContext context = null;
final MyInAppBrowser browser = new MyInAppBrowser();
static BuildContext context;

@override
_WebviewExampleScreenState createState() => new _WebviewExampleScreenState();
Expand All @@ -119,7 +121,7 @@ class _WebviewExampleScreenState extends State<WebviewExampleScreen> {
child: new RaisedButton(
onPressed: () {
widget.browser.openFile(
"assets/index.html",
assetFilePath: "assets/index.html",
//url: "https://www.google.com/",
options: InAppBrowserClassOptions(
inAppWebViewWidgetOptions: InAppWebViewWidgetOptions(
Expand Down
35 changes: 9 additions & 26 deletions lib/src/chrome_safari_browser.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

import 'types.dart';
Expand All @@ -12,16 +13,16 @@ import 'in_app_browser.dart';
///This class uses native [Chrome Custom Tabs](https://developer.android.com/reference/android/support/customtabs/package-summary) on Android
///and [SFSafariViewController](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller) on iOS.
///
///[browserFallback] represents the [InAppBrowser] instance fallback in case [Chrome Custom Tabs]/[SFSafariViewController] is not available.
///[browserFallback] represents the [InAppBrowser] instance fallback in case `Chrome Custom Tabs`/`SFSafariViewController` is not available.
class ChromeSafariBrowser {
String uuid;
InAppBrowser browserFallback;
bool _isOpened = false;

///Initialize the [ChromeSafariBrowser] instance with an [InAppBrowser] fallback instance or `null`.
ChromeSafariBrowser (bf) {
ChromeSafariBrowser ({bFallback}) {
uuid = uuidGenerator.v4();
browserFallback = bf;
browserFallback = bFallback;
ChannelManager.addListener(uuid, handleMethod);
_isOpened = false;
}
Expand All @@ -45,32 +46,14 @@ class ChromeSafariBrowser {

///Opens an [url] in a new [ChromeSafariBrowser] instance.
///
///- [url]: The [url] to load. Call [encodeUriComponent()] on this if the [url] contains Unicode characters.
///[url]: The [url] to load. Call [encodeUriComponent()] on this if the [url] contains Unicode characters.
///
///- [options]: Options for the [ChromeSafariBrowser].
///[options]: Options for the [ChromeSafariBrowser].
///
///- [headersFallback]: The additional header of the [InAppBrowser] instance fallback to be used in the HTTP request for this URL, specified as a map from name to value.
///[headersFallback]: The additional header of the [InAppBrowser] instance fallback to be used in the HTTP request for this URL, specified as a map from name to value.
///
///- [optionsFallback]: Options used by the [InAppBrowser] instance fallback.
///
///**Android** supports these options:
///
///- __addShareButton__: Set to `false` if you don't want the default share button. The default value is `true`.
///- __showTitle__: Set to `false` if the title shouldn't be shown in the custom tab. The default value is `true`.
///- __toolbarBackgroundColor__: Set the custom background color of the toolbar.
///- __enableUrlBarHiding__: Set to `true` to enable the url bar to hide as the user scrolls down on the page. The default value is `false`.
///- __instantAppsEnabled__: Set to `true` to enable Instant Apps. The default value is `false`.
///
///**iOS** supports these options:
///
///- __entersReaderIfAvailable__: Set to `true` if Reader mode should be entered automatically when it is available for the webpage. The default value is `false`.
///- __barCollapsingEnabled__: Set to `true` to enable bar collapsing. The default value is `false`.
///- __dismissButtonStyle__: Set the custom style for the dismiss button. The default value is `0 //done`. See [SFSafariViewController.DismissButtonStyle](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller/dismissbuttonstyle) for all the available styles.
///- __preferredBarTintColor__: Set the custom background color of the navigation bar and the toolbar.
///- __preferredControlTintColor__: Set the custom color of the control buttons on the navigation bar and the toolbar.
///- __presentationStyle__: Set the custom modal presentation style when presenting the WebView. The default value is `0 //fullscreen`. See [UIModalPresentationStyle](https://developer.apple.com/documentation/uikit/uimodalpresentationstyle) for all the available styles.
///- __transitionStyle__: Set to the custom transition style when presenting the WebView. The default value is `0 //crossDissolve`. See [UIModalTransitionStyle](https://developer.apple.com/documentation/uikit/uimodaltransitionStyle) for all the available styles.
Future<void> open(String url, {ChromeSafariBrowserClassOptions options, Map<String, String> headersFallback = const {}, InAppBrowserClassOptions optionsFallback}) async {
///[optionsFallback]: Options used by the [InAppBrowser] instance fallback.
Future<void> open({@required String url, ChromeSafariBrowserClassOptions options, Map<String, String> headersFallback = const {}, InAppBrowserClassOptions optionsFallback}) async {
assert(url != null && url.isNotEmpty);
this.throwIsAlreadyOpened(message: 'Cannot open $url!');

Expand Down
Loading

0 comments on commit 44c17d1

Please sign in to comment.