From 08b392e8b13f40fa5b90809927041c1a78d17a24 Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Mon, 25 Nov 2019 23:04:17 +0100 Subject: [PATCH] updated docs, updated README.md --- .idea/workspace.xml | 395 ++--- README.md | 1456 ++++++----------- example/assets/certificate.pfx | Bin 5629 -> 0 bytes example/lib/in_app_webiew_example.screen.dart | 154 +- example/pubspec.yaml | 1 - lib/src/chrome_safari_browser.dart | 1 + lib/src/cookie_manager.dart | 3 +- lib/src/in_app_browser.dart | 52 +- lib/src/in_app_webview.dart | 68 +- lib/src/webview_options.dart | 4 +- 10 files changed, 779 insertions(+), 1355 deletions(-) delete mode 100644 example/assets/certificate.pfx diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 341d5213..5df4c9e9 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -16,14 +16,15 @@ - - - - - - + + - + + + + + + @@ -43,11 +44,25 @@ + + + + + + + + + + + + + + - - + + @@ -56,58 +71,10 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -124,22 +91,6 @@ - onReceivedHttpAuthRequest - onLoadHtt - onLoadError - startSafeBrowsing - onSafeBrowsingHit - dispose - onSafe - 192.1 - flutter - InAppWebView - onFindResultReceived - highlighted - onLoadErr - InAppWebViewInitialFileTest - InAppWebViewInitialDataTest - Fetch OnLoadHttpError ONnaviga InAppWebViewOnNavigationChangeTest @@ -154,12 +105,29 @@ InAppWebViewOnConsoleMessageTest Change: InAppWebViewOnScrollChangedTest + for Android + Event fired + an re + Event fires + only for Android. + isOpened + initialScale + e spinner when the WebView is loading a page. The default value i + reload + methods + class + HttpAuthCredentialDatabase + ### + ##### + loadFile + window. activity.getPreferences(0) Log. com.pichillilorenzo.flutter_inappbrowser flutter_inappbrowser + Event fired $PROJECT_DIR$/example/android @@ -171,9 +139,6 @@ @@ -276,6 +244,7 @@ - @@ -486,7 +432,7 @@ - + @@ -494,7 +440,7 @@ - + @@ -524,41 +470,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -566,16 +477,6 @@ - - - - - - - - - - @@ -586,16 +487,6 @@ - - - - - - - - - - @@ -897,65 +788,25 @@ - + + - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + @@ -964,18 +815,126 @@ - - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/README.md b/README.md index 9caeb112..95a62569 100644 --- a/README.md +++ b/README.md @@ -10,17 +10,20 @@ A Flutter plugin that allows you to add an inline webview or open an in-app browser window. ### Requirements -- Dart sdk: ">=2.1.0-dev.7.1 <3.0.0" -- Flutter: ">=0.10.1 <2.0.0" + +- Dart sdk: ">=2.0.0-dev.68.0 <3.0.0" +- Flutter: ">=1.9.1+hotfix.5 <2.0.0" - Android: `minSdkVersion 17` - iOS: `--ios-language swift` ### Note for Android + During the build, if Android fails with `Error: uses-sdk:minSdkVersion 16 cannot be smaller than version 17 declared in library`, it means that you need to update the `minSdkVersion` of your `build.gradle` file to at least `17`. Because of [Flutter AndroidX compatibility](https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility), the latest version that doesn't use `AndroidX` is `0.6.0`. ### IMPORTANT Note for iOS + If you are starting a new fresh app, you need to create the Flutter App with `flutter create -i swift` (see [flutter/flutter#13422 (comment)](https://github.com/flutter/flutter/issues/13422#issuecomment-392133780)), otherwise, you will get this message: ``` === BUILD TARGET flutter_inappbrowser OF PROJECT Pods WITH CONFIGURATION Debug === @@ -54,23 +57,54 @@ For help getting started with Flutter, view our online For help on editing plugin code, view the [documentation](https://flutter.io/developing-packages/#edit-plugin-package). ## Installation + First, add `flutter_inappbrowser` as a [dependency in your pubspec.yaml file](https://flutter.io/using-packages/). ## Usage + Classes: - [InAppWebView](#inappwebview-class): Flutter Widget for adding an **inline native WebView** integrated into the flutter widget tree. To use `InAppWebView` class on iOS you need to opt-in for the embedded views preview by adding a boolean property to the app's `Info.plist` file, with the key `io.flutter.embedded_views_preview` and the value `YES`. - [InAppBrowser](#inappbrowser-class): In-App Browser using native WebView. - [ChromeSafariBrowser](#chromesafaribrowser-class): In-App Browser using [Chrome Custom Tabs](https://developer.android.com/reference/android/support/customtabs/package-summary) on Android / [SFSafariViewController](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller) on iOS. - [InAppLocalhostServer](#inapplocalhostserver-class): This class allows you to create a simple server on `http://localhost:[port]/`. The default `port` value is `8080`. -- [CookieManager](#cookiemanager-class): Manages the cookies used by WebView instances. **NOTE for iOS**: available from iOS 11.0+. +- [CookieManager](#cookiemanager-class): This class implements a singleton object (shared instance) which manages the cookies used by WebView instances. **NOTE for iOS**: available from iOS 11.0+. +- [HttpAuthCredentialDatabase](#httpauthcredentialdatabase-class): This class implements a singleton object (shared instance) which manages the shared HTTP auth credentials cache. -See the online [docs](https://pub.dartlang.org/documentation/flutter_inappbrowser/latest/) to get the full documentation. +## API Reference + +See the online [API Reference](https://pub.dartlang.org/documentation/flutter_inappbrowser/latest/) to get the full documentation. + +### Load a file inside `assets` folder + +To be able to load your local files (assets, js, css, etc.), you need to add them in the `assets` section of the `pubspec.yaml` file, otherwise they cannot be found! + +Example of a `pubspec.yaml` file: +```yaml +... + +# The following section is specific to Flutter. +flutter: + + # The following line ensures that the Material Icons font is + # included with your application, so that you can use the icons in + # the material Icons class. + uses-material-design: true + + assets: + - assets/index.html + - assets/css/ + - assets/images/ + +... +``` ### `InAppWebView` class + Flutter Widget for adding an **inline native WebView** integrated into the flutter widget tree. The plugin relies on Flutter's mechanism (in developers preview) for embedding Android and iOS native views: [AndroidView](https://docs.flutter.io/flutter/widgets/AndroidView-class.html) and [UiKitView](https://docs.flutter.io/flutter/widgets/UiKitView-class.html). Known issues are tagged with the [platform-views](https://github.com/flutter/flutter/labels/a%3A%20platform-views) label in the [Flutter official repo](https://github.com/flutter/flutter). +Keyboard support within webviews is also experimental. To use `InAppWebView` class on iOS you need to opt-in for the embedded views preview by adding a boolean property to the app's `Info.plist` file, with the key `io.flutter.embedded_views_preview` and the value `YES`. @@ -111,96 +145,84 @@ class _MyAppState extends State { return MaterialApp( home: Scaffold( appBar: AppBar( - title: const Text('Inline WebView example app'), + title: const Text('InAppWebView Example'), ), body: Container( - child: Column( - children: [ - Container( - padding: EdgeInsets.all(20.0), - child: Text("CURRENT URL\n${ (url.length > 50) ? url.substring(0, 50) + "..." : url }"), - ), - (progress != 1.0) ? LinearProgressIndicator(value: progress) : Container(), - Expanded( - child: Container( - margin: const EdgeInsets.all(10.0), - decoration: BoxDecoration( - border: Border.all(color: Colors.blueAccent) - ), - child: InAppWebView( - initialUrl: "https://flutter.io/", - initialHeaders: { - - }, - initialOptions: { - - }, - onWebViewCreated: (InAppWebViewController controller) { - webView = controller; - }, - onLoadStart: (InAppWebViewController controller, String url) { - print("started $url"); - setState(() { - this.url = url; - }); - }, - onProgressChanged: (InAppWebViewController controller, int progress) { - setState(() { - this.progress = progress/100; - }); - }, + child: Column(children: [ + Container( + padding: EdgeInsets.all(20.0), + child: Text( + "CURRENT URL\n${(url.length > 50) ? url.substring(0, 50) + "..." : url}"), + ), + Container( + padding: EdgeInsets.all(10.0), + child: progress < 1.0 + ? LinearProgressIndicator(value: progress) + : Container()), + Expanded( + child: Container( + margin: const EdgeInsets.all(10.0), + decoration: + BoxDecoration(border: Border.all(color: Colors.blueAccent)), + child: InAppWebView( + initialUrl: "https://flutter.dev/", + initialHeaders: {}, + initialOptions: InAppWebViewWidgetOptions( + inAppWebViewOptions: InAppWebViewOptions( + debuggingEnabled: true, + ) ), + onWebViewCreated: (InAppWebViewController controller) { + webView = controller; + }, + onLoadStart: (InAppWebViewController controller, String url) { + setState(() { + this.url = url; + }); + }, + onLoadStop: (InAppWebViewController controller, String url) async { + setState(() { + this.url = url; + }); + }, + onProgressChanged: (InAppWebViewController controller, int progress) { + setState(() { + this.progress = progress / 100; + }); + }, ), ), - ButtonBar( - alignment: MainAxisAlignment.center, - children: [ - RaisedButton( - child: Icon(Icons.arrow_back), - onPressed: () { - if (webView != null) { - webView.goBack(); - } - }, - ), - RaisedButton( - child: Icon(Icons.arrow_forward), - onPressed: () { - if (webView != null) { - webView.goForward(); - } - }, - ), - RaisedButton( - child: Icon(Icons.refresh), - onPressed: () { - if (webView != null) { - webView.reload(); - } - }, - ), - ], - ), - ].where((Object o) => o != null).toList(), - ), - ), - bottomNavigationBar: BottomNavigationBar( - currentIndex: 0, - items: [ - BottomNavigationBarItem( - icon: Icon(Icons.home), - title: Text('Home'), ), - BottomNavigationBarItem( - icon: Icon(Icons.mail), - title: Text('Item 2'), + ButtonBar( + alignment: MainAxisAlignment.center, + children: [ + RaisedButton( + child: Icon(Icons.arrow_back), + onPressed: () { + if (webView != null) { + webView.goBack(); + } + }, + ), + RaisedButton( + child: Icon(Icons.arrow_forward), + onPressed: () { + if (webView != null) { + webView.goForward(); + } + }, + ), + RaisedButton( + child: Icon(Icons.refresh), + onPressed: () { + if (webView != null) { + webView.reload(); + } + }, + ), + ], ), - BottomNavigationBarItem( - icon: Icon(Icons.person), - title: Text('Item 3') - ) - ], - ), + ])), ), ); } @@ -216,441 +238,218 @@ Screenshots: ![ios](https://user-images.githubusercontent.com/5956938/54096363-e1e72000-43ab-11e9-85c2-983a830ab7a0.gif) -#### InAppWebView.initialUrl -Initial url that will be loaded. - -#### InAppWebView.initialFile -Initial asset file that will be loaded. See `InAppWebView.loadFile()` for explanation. - -#### InAppWebView.initialData -Initial `InAppWebViewInitialData` that will be loaded. - -#### InAppWebView.initialHeaders -Initial headers that will be used. - -#### InAppWebView.initialOptions -Initial options that will be used. - -All platforms support: - - __useShouldOverrideUrlLoading__: Set to `true` to be able to listen at the `shouldOverrideUrlLoading()` event. The default value is `false`. - - __useOnLoadResource__: Set to `true` to be able to listen at the `onLoadResource()` event. The default value is `false`. - - __clearCache__: Set to `true` to have all the browser's cache cleared before the new window is opened. The default value is `false`. - - __userAgent__: Set the custom WebView's user-agent. - - __javaScriptEnabled__: Set to `true` to enable JavaScript. The default value is `true`. - - __javaScriptCanOpenWindowsAutomatically__: Set to `true` to allow JavaScript open windows without user interaction. The default value is `false`. - - __mediaPlaybackRequiresUserGesture__: Set to `true` to prevent HTML5 audio or video from autoplaying. The default value is `true`. - - __transparentBackground__: Set to `true` to make the background of the WebView transparent. If your app has a dark theme, this can prevent a white flash on initialization. The default value is `false`. - - **Android** supports these additional options: - - - __clearSessionCache__: Set to `true` to have the session cookie cache cleared before the new window is opened. - - __builtInZoomControls__: Set to `true` if the WebView should use its built-in zoom mechanisms. The default value is `false`. - - __displayZoomControls__: Set to `true` if the WebView should display on-screen zoom controls when using the built-in zoom mechanisms. The default value is `false`. - - __supportZoom__: Set to `false` if the WebView should not support zooming using its on-screen zoom controls and gestures. The default value is `true`. - - __databaseEnabled__: Set to `true` if you want the database storage API is enabled. The default value is `false`. - - __domStorageEnabled__: Set to `true` if you want the DOM storage API is enabled. The default value is `false`. - - __useWideViewPort__: Set to `true` if the WebView should enable support for the "viewport" HTML meta tag or should use a wide viewport. When the value of the setting is false, the layout width is always set to the width of the WebView control in device-independent (CSS) pixels. When the value is true and the page contains the viewport meta tag, the value of the width specified in the tag is used. If the page does not contain the tag or does not provide a width, then a wide viewport will be used. The default value is `true`. - - __safeBrowsingEnabled__: Set to `true` if you want the Safe Browsing is enabled. Safe Browsing allows WebView to protect against malware and phishing attacks by verifying the links. The default value is `true`. - - __textZoom__: Set text scaling of the WebView. The default value is `100`. - - __mixedContentMode__: Configures the WebView's behavior when a secure origin attempts to load a resource from an insecure origin. By default, apps that target `Build.VERSION_CODES.KITKAT` or below default to `MIXED_CONTENT_ALWAYS_ALLOW`. Apps targeting `Build.VERSION_CODES.LOLLIPOP` default to `MIXED_CONTENT_NEVER_ALLOW`. The preferred and most secure mode of operation for the WebView is `MIXED_CONTENT_NEVER_ALLOW` and use of `MIXED_CONTENT_ALWAYS_ALLOW` is strongly discouraged. - - **iOS** supports these additional options: - - - __disallowOverScroll__: Set to `true` to disable the bouncing of the WebView when the scrolling has reached an edge of the content. The default value is `false`. - - __enableViewportScale__: Set to `true` to allow a viewport meta tag to either disable or restrict the range of user scaling. The default value is `false`. - - __suppressesIncrementalRendering__: Set to `true` if you want the WebView suppresses content rendering until it is fully loaded into memory.. The default value is `false`. - - __allowsAirPlayForMediaPlayback__: Set to `true` to allow AirPlay. The default value is `true`. - - __allowsBackForwardNavigationGestures__: Set to `true` to allow the horizontal swipe gestures trigger back-forward list navigations. The default value is `true`. - - __allowsLinkPreview__: Set to `true` to allow that pressing on a link displays a preview of the destination for the link. The default value is `true`. - - __ignoresViewportScaleLimits__: Set to `true` if you want that the WebView should always allow scaling of the webpage, regardless of the author's intent. The ignoresViewportScaleLimits property overrides the `user-scalable` HTML property in a webpage. The default value is `false`. - - __allowsInlineMediaPlayback__: Set to `true` to allow HTML5 media playback to appear inline within the screen layout, using browser-supplied controls rather than native controls. For this to work, add the `webkit-playsinline` attribute to any `