Skip to content

Commit 860a42e

Browse files
v0.4.0
1 parent c7356f3 commit 860a42e

26 files changed

+1750
-1236
lines changed

.idea/workspace.xml

+172-105
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 0.4.0
2+
3+
- removed `target` parameter to `InAppBrowser.open()` method. To open the url on the system browser, use the `openWithSystemBrowser: true` option
4+
- fixes for the `_ChannelManager` private class
5+
- fixed `EXC_BAD_INSTRUCTION` onLoadStart in Swift
6+
- added `openWithSystemBrowser` and `isLocalFile` options
7+
- added `InAppBrowser.openWithSystemBrowser` method
8+
- added `InAppBrowser.openOnLocalhost` method
9+
- added `InAppBrowser.loadFile` method
10+
111
## 0.3.2
212

313
- fixed WebView.storyboard path for iOS

README.md

+104-43
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ class MyInAppBrowser extends InAppBrowser {
5656
await this.injectScriptCode("console.log({'testObject': 5});"); // the message will be: [object Object]
5757
await this.injectScriptCode("console.log('testObjectStringify', JSON.stringify({'testObject': 5}));"); // the message will be: testObjectStringify {"testObject": 5}
5858
await this.injectScriptCode("console.error('testError', false);"); // the message will be: testError false
59-
59+
6060
// add jquery library and custom javascript
6161
await this.injectScriptFile("https://code.jquery.com/jquery-3.3.1.min.js");
6262
this.injectScriptCode("""
6363
\$( "body" ).html( "Next Step..." )
6464
""");
65-
65+
6666
// add custom css
6767
this.injectStyleCode("""
6868
body {
@@ -81,7 +81,7 @@ class MyInAppBrowser extends InAppBrowser {
8181
void onExit() {
8282
print("\n\nBrowser closed!\n\n");
8383
}
84-
84+
8585
@override
8686
void shouldOverrideUrlLoading(String url) {
8787
print("\n\n override $url\n\n");
@@ -136,8 +136,8 @@ class _MyAppState extends State<MyApp> {
136136
title: const Text('Flutter InAppBrowser Plugin example app'),
137137
),
138138
body: new Center(
139-
child: new RaisedButton(onPressed: () {
140-
inAppBrowser.open(url: "https://flutter.io/", options: {
139+
child: new RaisedButton(onPressed: () async {
140+
await inAppBrowser.open(url: "https://flutter.io/", options: {
141141
"useShouldOverrideUrlLoading": true,
142142
"useOnLoadResource": true
143143
});
@@ -155,8 +155,10 @@ class _MyAppState extends State<MyApp> {
155155

156156
Opens a URL in a new InAppBrowser instance or the system browser.
157157

158+
**NOTE**: If you open the given `url` with the system browser (`openWithSystemBrowser: true`), you wont be able to use the `InAppBrowser` methods!
159+
158160
```dart
159-
inAppBrowser.open({String url = "about:blank", Map<String, String> headers = const {}, String target = "_self", Map<String, dynamic> options = const {}});
161+
inAppBrowser.open({String url = "about:blank", Map<String, String> headers = const {}, Map<String, dynamic> options = const {}});
160162
```
161163

162164
Opens an `url` in a new `InAppBrowser` instance or the system browser.
@@ -165,17 +167,13 @@ Opens an `url` in a new `InAppBrowser` instance or the system browser.
165167

166168
- `headers`: The additional headers to be used in the HTTP request for this URL, specified as a map from name to value.
167169

168-
- `target`: The target in which to load the `url`, an optional parameter that defaults to `_self`.
169-
170-
- `_self`: Opens in the `InAppBrowser`.
171-
- `_blank`: Opens in the `InAppBrowser`.
172-
- `_system`: Opens in the system's web browser.
173-
174170
- `options`: Options for the `InAppBrowser`.
175171

176172
All platforms support:
177173
- __useShouldOverrideUrlLoading__: Set to `true` to be able to listen at the `shouldOverrideUrlLoading` event. The default value is `false`.
178174
- __useOnLoadResource__: Set to `true` to be able to listen at the `onLoadResource()` event. The default value is `false`.
175+
- __openWithSystemBrowser__: Set to `true` to open the given `url` with the system browser. The default value is `false`.
176+
- __isLocalFile__: Set to `true` if the `url` is pointing to a local file (the file must be addded in the `assets` section of your `pubspec.yaml`. See `loadFile()` explanation). The default value is `false`.
179177
- __clearCache__: Set to `true` to have all the browser's cache cleared before the new window is opened. The default value is `false`.
180178
- __userAgent___: Set the custom WebView's user-agent.
181179
- __javaScriptEnabled__: Set to `true` to enable JavaScript. The default value is `true`.
@@ -185,9 +183,9 @@ Opens an `url` in a new `InAppBrowser` instance or the system browser.
185183
- __toolbarTopBackgroundColor__: Set the custom background color of the toolbat at the top.
186184
- __hideUrlBar__: Set to `true` to hide the url bar on the toolbar at the top. The default value is `false`.
187185
- __mediaPlaybackRequiresUserGesture__: Set to `true` to prevent HTML5 audio or video from autoplaying. The default value is `true`.
188-
186+
189187
**Android** supports these additional options:
190-
188+
191189
- __hideTitleBar__: Set to `true` if you want the title should be displayed. The default value is `false`.
192190
- __closeOnCannotGoBack__: Set to `false` to not close the InAppBrowser when the user click on the back button and the WebView cannot go back to the history. The default value is `true`.
193191
- __clearSessionCache__: Set to `true` to have the session cookie cache cleared before the new window is opened.
@@ -200,14 +198,14 @@ Opens an `url` in a new `InAppBrowser` instance or the system browser.
200198
- __progressBar__: Set to `false` to hide the progress bar at the bottom of the toolbar at the top. The default value is `true`.
201199

202200
**iOS** supports these additional options:
203-
201+
204202
- __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`.
205203
- __toolbarBottom__: Set to `false` to hide the toolbar at the bottom of the WebView. The default value is `true`.
206204
- __toolbarBottomBackgroundColor__: Set the custom background color of the toolbat at the bottom.
207205
- __toolbarBottomTranslucent__: Set to `true` to set the toolbar at the bottom translucent. The default value is `true`.
208206
- __closeButtonCaption__: Set the custom text for the close button.
209207
- __closeButtonColor__: Set the custom color for the close button.
210-
- __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.
208+
- __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.
211209
- __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.
212210
- __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`.
213211
- __suppressesIncrementalRendering__: Set to `true` if you want the WebView suppresses content rendering until it is fully loaded into memory.. The default value is `false`.
@@ -218,7 +216,7 @@ Opens an `url` in a new `InAppBrowser` instance or the system browser.
218216
- __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 `<video>` elements. The default value is `false`.
219217
- __allowsPictureInPictureMediaPlayback__: Set to `true` to allow HTML5 videos play picture-in-picture. The default value is `true`.
220218
- __spinner__: Set to `false` to hide the spinner when the WebView is loading a page. The default value is `true`.
221-
219+
222220
Example:
223221
```dart
224222
inAppBrowser.open('https://flutter.io/', options: {
@@ -231,39 +229,66 @@ inAppBrowser.open('https://flutter.io/', options: {
231229
"toolbarBottomTranslucent": false,
232230
"allowsLinkPreview": false
233231
});
234-
```
232+
```
233+
234+
#### static Future\<void\> InAppBrowser.openWithSystemBrowser
235+
236+
This is a static method that opens an `url` in the system browser.
237+
This has the same behaviour of an `InAppBrowser` instance calling the `open()` method with option `openWithSystemBrowser: true`.
238+
239+
```dart
240+
InAppBrowser.openWithSystemBrowser(String url);
241+
```
242+
243+
#### Future\<void\> InAppBrowser.openOnLocalhost
244+
245+
Serve the `assetFilePath` from Flutter assets on http://localhost:`port`/. It is similar to `InAppBrowser.open()` with option `isLocalFile: true`, but it starts a server.
246+
247+
**NOTE for iOS**: For the iOS Platform, you need to add the `NSAllowsLocalNetworking` key with `true` in the `Info.plist` file (See [ATS Configuration Basics](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW35):
248+
```xml
249+
<key>NSAppTransportSecurity</key>
250+
<dict>
251+
<key>NSAllowsLocalNetworking</key>
252+
<true/>
253+
</dict>
254+
```
255+
The `NSAllowsLocalNetworking` key is available since **iOS 10**.
256+
257+
```dart
258+
inAppBrowser.openOnLocalhost(String assetFilePath, {int port = 8080, Map<String, String> headers = const {}, Map<String, dynamic> options = const {}});
259+
```
235260

236261
#### Events
237262

238263
Event fires when the `InAppBrowser` starts to load an `url`.
239264
```dart
240265
@override
241266
void onLoadStart(String url) {
242-
267+
243268
}
244269
```
245270

246271
Event fires when the `InAppBrowser` finishes loading an `url`.
247272
```dart
248273
@override
249274
void onLoadStop(String url) {
250-
275+
251276
}
252277
```
253278

254279
Event fires when the `InAppBrowser` encounters an error loading an `url`.
255280
```dart
256281
@override
257282
void onLoadError(String url, String code, String message) {
258-
283+
259284
}
260285
```
261286

262287
Event fires when the `InAppBrowser` window is closed.
263288
```dart
264289
@override
265290
void onExit() {
266-
291+
267292
}
268293
```
269294

@@ -305,105 +330,141 @@ Loads the given `url` with optional `headers` specified as a map from name to va
305330
inAppBrowser.loadUrl(String url, {Map<String, String> headers = const {}});
306331
```
307332

333+
#### Future\<void\> InAppBrowser.loadFile
334+
335+
Loads the given `assetFilePath` with optional `headers` specified as a map from name to value.
336+
337+
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!
338+
339+
Example of a `pubspec.yaml` file:
340+
```yaml
341+
...
342+
343+
# The following section is specific to Flutter.
344+
flutter:
345+
346+
# The following line ensures that the Material Icons font is
347+
# included with your application, so that you can use the icons in
348+
# the material Icons class.
349+
uses-material-design: true
350+
351+
assets:
352+
- assets/index.html
353+
- assets/css/
354+
- assets/images/
355+
356+
...
357+
```
358+
Example of a `main.dart` file:
359+
```dart
360+
...
361+
inAppBrowser.loadFile("assets/index.html");
362+
...
363+
```
364+
365+
```dart
366+
inAppBrowser.loadFile(String assetFilePath, {Map<String, String> headers = const {}});
367+
```
368+
308369
#### Future\<void\> InAppBrowser.show
309370

310371
Displays an `InAppBrowser` window that was opened hidden. Calling this has no effect if the `InAppBrowser` was already visible.
311372

312373
```dart
313374
inAppBrowser.show();
314-
```
375+
```
315376

316377
#### Future\<void\> InAppBrowser.hide
317378

318379
Hides the `InAppBrowser` window. Calling this has no effect if the `InAppBrowser` was already hidden.
319380

320381
```dart
321382
inAppBrowser.hide();
322-
```
383+
```
323384

324385
#### Future\<void\> InAppBrowser.close
325386

326387
Closes the `InAppBrowser` window.
327388

328389
```dart
329390
inAppBrowser.close();
330-
```
391+
```
331392

332393
#### Future\<void\> InAppBrowser.reload
333394

334395
Reloads the `InAppBrowser` window.
335396

336397
```dart
337398
inAppBrowser.reload();
338-
```
399+
```
339400

340401
#### Future\<void\> InAppBrowser.goBack
341402

342403
Goes back in the history of the `InAppBrowser` window.
343404

344405
```dart
345406
inAppBrowser.goBack();
346-
```
407+
```
347408

348409
#### Future\<void\> InAppBrowser.goForward
349410

350411
Goes forward in the history of the `InAppBrowser` window.
351412

352413
```dart
353414
inAppBrowser.goForward();
354-
```
415+
```
355416

356417
#### Future\<bool\> InAppBrowser.isLoading
357418

358419
Check if the Web View of the `InAppBrowser` instance is in a loading state.
359420

360421
```dart
361422
inAppBrowser.isLoading();
362-
```
423+
```
363424

364425
#### Future\<void\> InAppBrowser.stopLoading
365426

366427
Stops the Web View of the `InAppBrowser` instance from loading.
367428

368429
```dart
369430
inAppBrowser.stopLoading();
370-
```
431+
```
371432

372433
#### Future\<bool\> InAppBrowser.isHidden
373434

374435
Check if the Web View of the `InAppBrowser` instance is hidden.
375436

376437
```dart
377438
inAppBrowser.isHidden();
378-
```
439+
```
379440

380441
#### Future\<String\> InAppBrowser.injectScriptCode
381442

382-
Injects JavaScript code into the `InAppBrowser` window and returns the result of the evaluation. (Only available when the target is set to `_blank` or to `_self`)
443+
Injects JavaScript code into the `InAppBrowser` window and returns the result of the evaluation.
383444

384445
```dart
385446
inAppBrowser.injectScriptCode(String source);
386-
```
447+
```
387448

388449
#### Future\<void\> InAppBrowser.injectScriptFile
389450

390-
Injects a JavaScript file into the `InAppBrowser` window. (Only available when the target is set to `_blank` or to `_self`)
451+
Injects a JavaScript file into the `InAppBrowser` window.
391452

392453
```dart
393454
inAppBrowser.injectScriptFile(String urlFile);
394-
```
455+
```
395456

396457
#### Future\<void\> InAppBrowser.injectStyleCode
397458

398-
Injects CSS into the `InAppBrowser` window. (Only available when the target is set to `_blank` or to `_self`)
459+
Injects CSS into the `InAppBrowser` window.
399460

400461
```dart
401462
inAppBrowser.injectStyleCode(String source);
402-
```
463+
```
403464

404465
#### Future\<void\> InAppBrowser.injectStyleFile
405466

406-
Injects a CSS file into the `InAppBrowser` window. (Only available when the target is set to `_blank` or to `_self`)
467+
Injects a CSS file into the `InAppBrowser` window.
407468

408469
```dart
409470
inAppBrowser.injectStyleFile(String urlFile);
@@ -462,13 +523,13 @@ class MyInAppBrowser extends InAppBrowser {
462523
void onExit() {
463524
print("\n\nBrowser closed!\n\n");
464525
}
465-
526+
466527
}
467528
468529
MyInAppBrowser inAppBrowserFallback = new MyInAppBrowser();
469530
470531
class MyChromeSafariBrowser extends ChromeSafariBrowser {
471-
532+
472533
MyChromeSafariBrowser(browserFallback) : super(browserFallback);
473534
474535
@override
@@ -579,23 +640,23 @@ Event fires when the `ChromeSafariBrowser` is opened.
579640
```dart
580641
@override
581642
void onOpened() {
582-
643+
583644
}
584645
```
585646

586647
Event fires when the `ChromeSafariBrowser` is loaded.
587648
```dart
588649
@override
589650
void onLoaded() {
590-
651+
591652
}
592653
```
593654

594655
Event fires when the `ChromeSafariBrowser` is closed.
595656
```dart
596657
@override
597658
void onClosed() {
598-
659+
599660
}
600661
```
601662

0 commit comments

Comments
 (0)