Commit a9bcbe1f authored by Joao Paulo Marquesini's avatar Joao Paulo Marquesini

fixing a problem in safari webview and adding tabs to examples

parent 8b5a6347
.DS_Store .DS_Store
.dart_tool/ .dart_tool/
.vscode/
.packages .packages
.pub/ .pub/
pubspec.lock pubspec.lock
......
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_inappbrowser/flutter_inappbrowser.dart';
class MyChromeSafariBrowser extends ChromeSafariBrowser {
MyChromeSafariBrowser(browserFallback) : super(browserFallback);
@override
void onOpened() {
print("ChromeSafari browser opened");
}
@override
void onLoaded() {
print("ChromeSafari browser loaded");
}
@override
void onClosed() {
print("ChromeSafari browser closed");
}
}
class ChromeSafariExampleScreen extends StatefulWidget {
final ChromeSafariBrowser browser = new MyChromeSafariBrowser(new InAppBrowser());
@override
_ChromeSafariExampleScreenState createState() => new _ChromeSafariExampleScreenState();
}
class _ChromeSafariExampleScreenState extends State<ChromeSafariExampleScreen> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return new Center(
child: new RaisedButton(
onPressed: () async {
await widget.browser.open("https://flutter.io/");
},
child: Text("Open Chrome Safari Browser")),
);
}
}
import 'package:flutter/material.dart';
import 'package:flutter_inappbrowser/flutter_inappbrowser.dart';
class InlineExampleScreen extends StatefulWidget {
@override
_InlineExampleScreenState createState() => new _InlineExampleScreenState();
}
class _InlineExampleScreenState extends State<InlineExampleScreen> {
InAppWebViewController webView;
String url = "";
double progress = 0;
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return Container(
child: Column(children: <Widget>[
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) : null
),
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;
});
},
),
),
),
ButtonBar(
alignment: MainAxisAlignment.center,
children: <Widget>[
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();
}
},
),
],
),
]));
}
}
This diff is collapsed.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_inappbrowser/flutter_inappbrowser.dart';
class MyInappBrowser extends InAppBrowser {
@override
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");
this.webViewController.loadUrl(url);
}
@override
void onLoadResource(
WebResourceResponse response, WebResourceRequest request) {
print("Started at: " +
response.startTime.toString() +
"ms ---> duration: " +
response.duration.toString() +
"ms " +
response.url);
}
@override
void onConsoleMessage(ConsoleMessage consoleMessage) {
print(consoleMessage.message);
}
}
class WebviewExampleScreen extends StatefulWidget {
final InAppBrowser browser = new InAppBrowser();
@override
_WebviewExampleScreenState createState() => new _WebviewExampleScreenState();
}
class _WebviewExampleScreenState extends State<WebviewExampleScreen> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return new Center(
child: new RaisedButton(
onPressed: () {
widget.browser.open(url:"https://flutter.io/");
},
child: Text("Open Webview Browser")),
);
}
}
...@@ -26,7 +26,7 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi ...@@ -26,7 +26,7 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi
scrollView.delegate = self scrollView.delegate = self
} }
required init(coder aDecoder: NSCoder) { required public init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)! super.init(coder: aDecoder)!
} }
......
...@@ -487,6 +487,7 @@ class ChromeSafariBrowser { ...@@ -487,6 +487,7 @@ class ChromeSafariBrowser {
args.putIfAbsent('headers', () => headersFallback); args.putIfAbsent('headers', () => headersFallback);
args.putIfAbsent('options', () => options); args.putIfAbsent('options', () => options);
args.putIfAbsent('optionsFallback', () => optionsFallback); args.putIfAbsent('optionsFallback', () => optionsFallback);
args.putIfAbsent('isData', () => false);
args.putIfAbsent('useChromeSafariBrowser', () => true); args.putIfAbsent('useChromeSafariBrowser', () => true);
await _ChannelManager.channel.invokeMethod('open', args); await _ChannelManager.channel.invokeMethod('open', args);
this._isOpened = true; this._isOpened = true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment