Skip to content

Commit db65f7a

Browse files
updated README.md and documentation
1 parent b3cdd8b commit db65f7a

File tree

8 files changed

+458
-182
lines changed

8 files changed

+458
-182
lines changed

.idea/workspace.xml

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

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## 0.2.0
22

3-
- added support of Chrome CustomTabs for android
3+
- added support of Chrome CustomTabs for Android
44
- added support of SFSafariViewController for iOS
55
- added the ability to create multiple instances of browsers
66

README.md

+198-18
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ For help on editing plugin code, view the [documentation](https://flutter.io/dev
1616
First, add `flutter_inappbrowser` as a [dependency in your pubspec.yaml file](https://flutter.io/using-packages/).
1717

1818
## Usage
19+
Classes:
20+
- [InAppBrowser](#inappbrowser): Native WebView.
21+
- [ChromeSafariBrowser](#chromesafaribrowser): [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.
22+
23+
Screenshots [here](#screenshots).
24+
25+
### `InAppBrowser` class
1926
Create a Class that extends the `InAppBrowser` Class in order to override the callbacks to manage the browser events.
2027
Example:
2128
```dart
2229
import 'package:flutter/material.dart';
23-
2430
import 'package:flutter_inappbrowser/flutter_inappbrowser.dart';
2531
2632
class MyInAppBrowser extends InAppBrowser {
@@ -107,7 +113,7 @@ class _MyAppState extends State<MyApp> {
107113
}
108114
```
109115

110-
### Future\<void\> InAppBrowser.open
116+
#### Future\<void\> InAppBrowser.open
111117

112118
Opens a URL in a new InAppBrowser instance or the system browser.
113119

@@ -188,7 +194,7 @@ inAppBrowser.open('https://flutter.io/', options: {
188194
});
189195
```
190196

191-
### Events
197+
#### Events
192198

193199
Event fires when the `InAppBrowser` starts to load an `url`.
194200
```dart
@@ -231,124 +237,298 @@ In order to be able to listen this event, you need to set `useShouldOverrideUrlL
231237
}
232238
```
233239

234-
### Future\<void\> InAppBrowser.loadUrl
240+
#### Future\<void\> InAppBrowser.loadUrl
235241

236242
Loads the given `url` with optional `headers` specified as a map from name to value.
237243

238244
```dart
239245
inAppBrowser.loadUrl(String url, {Map<String, String> headers = const {}});
240246
```
241247

242-
### Future\<void\> InAppBrowser.show
248+
#### Future\<void\> InAppBrowser.show
243249

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

246252
```dart
247253
inAppBrowser.show();
248254
```
249255

250-
### Future\<void\> InAppBrowser.hide
256+
#### Future\<void\> InAppBrowser.hide
251257

252258
Hides the `InAppBrowser` window. Calling this has no effect if the `InAppBrowser` was already hidden.
253259

254260
```dart
255261
inAppBrowser.hide();
256262
```
257263

258-
### Future\<void\> InAppBrowser.close
264+
#### Future\<void\> InAppBrowser.close
259265

260266
Closes the `InAppBrowser` window.
261267

262268
```dart
263269
inAppBrowser.close();
264270
```
265271

266-
### Future\<void\> InAppBrowser.reload
272+
#### Future\<void\> InAppBrowser.reload
267273

268274
Reloads the `InAppBrowser` window.
269275

270276
```dart
271277
inAppBrowser.reload();
272278
```
273279

274-
### Future\<void\> InAppBrowser.goBack
280+
#### Future\<void\> InAppBrowser.goBack
275281

276282
Goes back in the history of the `InAppBrowser` window.
277283

278284
```dart
279285
inAppBrowser.goBack();
280286
```
281287

282-
### Future\<void\> InAppBrowser.goForward
288+
#### Future\<void\> InAppBrowser.goForward
283289

284290
Goes forward in the history of the `InAppBrowser` window.
285291

286292
```dart
287293
inAppBrowser.goForward();
288294
```
289295

290-
### Future\<bool\> InAppBrowser.isLoading
296+
#### Future\<bool\> InAppBrowser.isLoading
291297

292298
Check if the Web View of the `InAppBrowser` instance is in a loading state.
293299

294300
```dart
295301
inAppBrowser.isLoading();
296302
```
297303

298-
### Future\<void\> InAppBrowser.stopLoading
304+
#### Future\<void\> InAppBrowser.stopLoading
299305

300306
Stops the Web View of the `InAppBrowser` instance from loading.
301307

302308
```dart
303309
inAppBrowser.stopLoading();
304310
```
305311

306-
### Future\<bool\> InAppBrowser.isHidden
312+
#### Future\<bool\> InAppBrowser.isHidden
307313

308314
Check if the Web View of the `InAppBrowser` instance is hidden.
309315

310316
```dart
311317
inAppBrowser.isHidden();
312318
```
313319

314-
### Future\<String\> InAppBrowser.injectScriptCode
320+
#### Future\<String\> InAppBrowser.injectScriptCode
315321

316322
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`)
317323

318324
```dart
319325
inAppBrowser.injectScriptCode(String source);
320326
```
321327

322-
### Future\<void\> InAppBrowser.injectScriptFile
328+
#### Future\<void\> InAppBrowser.injectScriptFile
323329

324330
Injects a JavaScript file into the `InAppBrowser` window. (Only available when the target is set to `_blank` or to `_self`)
325331

326332
```dart
327333
inAppBrowser.injectScriptFile(String urlFile);
328334
```
329335

330-
### Future\<void\> InAppBrowser.injectStyleCode
336+
#### Future\<void\> InAppBrowser.injectStyleCode
331337

332338
Injects CSS into the `InAppBrowser` window. (Only available when the target is set to `_blank` or to `_self`)
333339

334340
```dart
335341
inAppBrowser.injectStyleCode(String source);
336342
```
337343

338-
### Future\<void\> InAppBrowser.injectStyleFile
344+
#### Future\<void\> InAppBrowser.injectStyleFile
339345

340346
Injects a CSS file into the `InAppBrowser` window. (Only available when the target is set to `_blank` or to `_self`)
341347

342348
```dart
343349
inAppBrowser.injectStyleFile(String urlFile);
344350
```
345351

352+
### `ChromeSafariBrowser` class
353+
Create a Class that extends the `ChromeSafariBrowser` Class in order to override the callbacks to manage the browser events. Example:
354+
```dart
355+
import 'package:flutter/material.dart';
356+
import 'package:flutter_inappbrowser/flutter_inappbrowser.dart';
357+
358+
class MyInAppBrowser extends InAppBrowser {
359+
360+
@override
361+
Future onLoadStart(String url) async {
362+
print("\n\nStarted $url\n\n");
363+
}
364+
365+
@override
366+
Future onLoadStop(String url) async {
367+
print("\n\nStopped $url\n\n");
368+
}
369+
370+
@override
371+
void onLoadError(String url, int code, String message) {
372+
print("\n\nCan't load $url.. Error: $message\n\n");
373+
}
374+
375+
@override
376+
void onExit() {
377+
print("\n\nBrowser closed!\n\n");
378+
}
379+
380+
}
381+
382+
MyInAppBrowser inAppBrowserFallback = new MyInAppBrowser();
383+
384+
class MyChromeSafariBrowser extends ChromeSafariBrowser {
385+
386+
MyChromeSafariBrowser(browserFallback) : super(browserFallback);
387+
388+
@override
389+
void onOpened() {
390+
print("ChromeSafari browser opened");
391+
}
392+
393+
@override
394+
void onLoaded() {
395+
print("ChromeSafari browser loaded");
396+
}
397+
398+
@override
399+
void onClosed() {
400+
print("ChromeSafari browser closed");
401+
}
402+
}
403+
404+
MyChromeSafariBrowser chromeSafariBrowser = new MyChromeSafariBrowser(inAppBrowserFallback);
405+
406+
407+
void main() => runApp(new MyApp());
408+
409+
class MyApp extends StatefulWidget {
410+
@override
411+
_MyAppState createState() => new _MyAppState();
412+
}
413+
414+
class _MyAppState extends State<MyApp> {
415+
416+
@override
417+
void initState() {
418+
super.initState();
419+
}
420+
421+
@override
422+
Widget build(BuildContext context) {
423+
return new MaterialApp(
424+
home: new Scaffold(
425+
appBar: new AppBar(
426+
title: const Text('Flutter InAppBrowser Plugin example app'),
427+
),
428+
body: new Center(
429+
child: new RaisedButton(onPressed: () {
430+
chromeSafariBrowser.open("https://flutter.io/", options: {
431+
"addShareButton": false,
432+
"toolbarBackgroundColor": "#000000",
433+
"dismissButtonStyle": 1,
434+
"preferredBarTintColor": "#000000",
435+
},
436+
optionsFallback: {
437+
"toolbarTopBackgroundColor": "#000000",
438+
"closeButtonCaption": "Close"
439+
});
440+
},
441+
child: Text("Open ChromeSafariBrowser")
442+
),
443+
),
444+
),
445+
);
446+
}
447+
}
448+
449+
```
450+
451+
#### Future\<void\> ChromeSafariBrowser.open
452+
Opens an `url` in a new `ChromeSafariBrowser` instance or the system browser.
453+
454+
- `url`: The `url` to load. Call `encodeUriComponent()` on this if the `url` contains Unicode characters.
455+
456+
- `options`: Options for the `ChromeSafariBrowser`.
457+
458+
- `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.
459+
460+
- `optionsFallback`: Options used by the `InAppBrowser` instance fallback.
461+
462+
**Android** supports these options:
463+
464+
- __addShareButton__: Set to `false` if you don't want the default share button. The default value is `true`.
465+
- __showTitle__: Set to `false` if the title shouldn't be shown in the custom tab. The default value is `true`.
466+
- __toolbarBackgroundColor__: Set the custom background color of the toolbar.
467+
- __enableUrlBarHiding__: Set to `true` to enable the url bar to hide as the user scrolls down on the page. The default value is `false`.
468+
- __instantAppsEnabled__: Set to `true` to enable Instant Apps. The default value is `false`.
469+
470+
**iOS** supports these options:
471+
472+
- __entersReaderIfAvailable__: Set to `true` if Reader mode should be entered automatically when it is available for the webpage. The default value is `false`.
473+
- __barCollapsingEnabled__: Set to `true` to enable bar collapsing. The default value is `false`.
474+
- __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.
475+
- __preferredBarTintColor__: Set the custom background color of the navigation bar and the toolbar.
476+
- __preferredControlTintColor__: Set the custom color of the control buttons on the navigation bar and the toolbar.
477+
- __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.
478+
- __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.
479+
480+
Example:
481+
```dart
482+
chromeSafariBrowser.open("https://flutter.io/", options: {
483+
"addShareButton": false,
484+
"toolbarBackgroundColor": "#000000",
485+
"dismissButtonStyle": 1,
486+
"preferredBarTintColor": "#000000",
487+
});
488+
```
489+
490+
#### Events
491+
492+
Event fires when the `ChromeSafariBrowser` is opened.
493+
```dart
494+
@override
495+
void onOpened() {
496+
497+
}
498+
```
499+
500+
Event fires when the `ChromeSafariBrowser` is loaded.
501+
```dart
502+
@override
503+
void onLoaded() {
504+
505+
}
506+
```
507+
508+
Event fires when the `ChromeSafariBrowser` is closed.
509+
```dart
510+
@override
511+
void onClosed() {
512+
513+
}
514+
```
515+
346516
## Screenshots:
347517

518+
#### InAppBrowser
348519
iOS:
349520

350521
![ios](https://user-images.githubusercontent.com/5956938/45934084-2a935400-bf99-11e8-9d71-9e1758b5b8c6.gif)
351522

352523
Android:
353524

354-
![android](https://user-images.githubusercontent.com/5956938/45934080-26ffcd00-bf99-11e8-8136-d39a81bd83e7.gif)
525+
![android](https://user-images.githubusercontent.com/5956938/45934080-26ffcd00-bf99-11e8-8136-d39a81bd83e7.gif)
526+
527+
#### ChromeSafariBrowser
528+
iOS:
529+
530+
![ios](https://user-images.githubusercontent.com/5956938/46532148-0c362e00-c8a0-11e8-9a0e-343e049dcf35.gif)
531+
532+
Android:
533+
534+
![android](https://user-images.githubusercontent.com/5956938/46532149-0c362e00-c8a0-11e8-8134-9af18f38a746.gif)

0 commit comments

Comments
 (0)