Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/url_launcher/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.0.5

* Add `enableDomStorage` field to `launch` to enable DOM storage in Android WebView.

## 5.0.4

* Update Dart code to conform to current Dart formatter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ private void launch(MethodCall call, Result result, String url) {
Intent launchIntent;
boolean useWebView = call.argument("useWebView");
boolean enableJavaScript = call.argument("enableJavaScript");
boolean enableDomStorage = call.argument("enableDomStorage");
Activity activity = mRegistrar.activity();
if (activity == null) {
result.error("NO_ACTIVITY", "Launching a URL requires a foreground activity.", null);
Expand All @@ -77,6 +78,7 @@ private void launch(MethodCall call, Result result, String url) {
launchIntent = new Intent(activity, WebViewActivity.class);
launchIntent.putExtra("url", url);
launchIntent.putExtra("enableJavaScript", enableJavaScript);
launchIntent.putExtra("enableDomStorage", enableDomStorage);
} else {
launchIntent = new Intent(Intent.ACTION_VIEW);
launchIntent.setData(Uri.parse(url));
Expand Down Expand Up @@ -105,10 +107,14 @@ public void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
String url = intent.getStringExtra("url");
Boolean enableJavaScript = intent.getBooleanExtra("enableJavaScript", false);
Boolean enableDomStorage = intent.getBooleanExtra("enableDomStorage", false);
webview.loadUrl(url);
if (enableJavaScript) {
webview.getSettings().setJavaScriptEnabled(enableJavaScript);
}
if (enableDomStorage) {
webview.getSettings().setDomStorageEnabled(enableDomStorage);
}
// Open new urls inside the webview itself.
webview.setWebViewClient(
new WebViewClient() {
Expand Down
147 changes: 84 additions & 63 deletions packages/url_launcher/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ class _MyHomePageState extends State<MyHomePage> {
}
}

Future<void> _launchInWebViewWithDomStorage(String url) async {
if (await canLaunch(url)) {
await launch(
url,
forceSafariVC: true,
forceWebView: true,
enableDomStorage: true,
);
} else {
throw 'Could not launch $url';
}
}

Future<void> _launchUniversalLinkIos(String url) async {
if (await canLaunch('https://youtube.com')) {
final bool nativeAppLaunchSucceeded = await launch(
Expand Down Expand Up @@ -104,69 +117,77 @@ class _MyHomePageState extends State<MyHomePage> {
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: TextField(
onChanged: (String text) => _phone = text,
decoration: const InputDecoration(
hintText: 'Input the phone number to launch')),
),
RaisedButton(
onPressed: () => setState(() {
_launched = _makePhoneCall('tel:$_phone');
}),
child: const Text('Make phone call'),
),
const Padding(
padding: EdgeInsets.all(16.0),
child: Text(toLaunch),
),
RaisedButton(
onPressed: () => setState(() {
_launched = _launchInBrowser(toLaunch);
}),
child: const Text('Launch in browser'),
),
const Padding(padding: EdgeInsets.all(16.0)),
RaisedButton(
onPressed: () => setState(() {
_launched = _launchInWebViewOrVC(toLaunch);
}),
child: const Text('Launch in app'),
),
const Padding(padding: EdgeInsets.all(16.0)),
RaisedButton(
onPressed: () => setState(() {
_launched = _launchInWebViewWithJavaScript(toLaunch);
}),
child: const Text('Launch in app(JavaScript ON)'),
),
RaisedButton(
onPressed: () => setState(() {
_launched = _launchUniversalLinkIos(toLaunch);
}),
child: const Text(
'Launch a universal link in a native app, fallback to Safari.(Youtube)'),
),
const Padding(padding: EdgeInsets.all(16.0)),
RaisedButton(
onPressed: () => setState(() {
_launched = _launchInWebViewOrVC(toLaunch);
Timer(const Duration(seconds: 5), () {
print('Closing WebView after 5 seconds...');
closeWebView();
});
}),
child: const Text('Launch in app + close after 5 seconds'),
),
const Padding(padding: EdgeInsets.all(16.0)),
FutureBuilder<void>(future: _launched, builder: _launchStatus),
],
),
body: ListView(
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: TextField(
onChanged: (String text) => _phone = text,
decoration: const InputDecoration(
hintText: 'Input the phone number to launch')),
),
RaisedButton(
onPressed: () => setState(() {
_launched = _makePhoneCall('tel:$_phone');
}),
child: const Text('Make phone call'),
),
const Padding(
padding: EdgeInsets.all(16.0),
child: Text(toLaunch),
),
RaisedButton(
onPressed: () => setState(() {
_launched = _launchInBrowser(toLaunch);
}),
child: const Text('Launch in browser'),
),
const Padding(padding: EdgeInsets.all(16.0)),
RaisedButton(
onPressed: () => setState(() {
_launched = _launchInWebViewOrVC(toLaunch);
}),
child: const Text('Launch in app'),
),
RaisedButton(
onPressed: () => setState(() {
_launched = _launchInWebViewWithJavaScript(toLaunch);
}),
child: const Text('Launch in app(JavaScript ON)'),
),
RaisedButton(
onPressed: () => setState(() {
_launched = _launchInWebViewWithDomStorage(toLaunch);
}),
child: const Text('Launch in app(DOM storage ON)'),
),
const Padding(padding: EdgeInsets.all(16.0)),
RaisedButton(
onPressed: () => setState(() {
_launched = _launchUniversalLinkIos(toLaunch);
}),
child: const Text(
'Launch a universal link in a native app, fallback to Safari.(Youtube)'),
),
const Padding(padding: EdgeInsets.all(16.0)),
RaisedButton(
onPressed: () => setState(() {
_launched = _launchInWebViewOrVC(toLaunch);
Timer(const Duration(seconds: 5), () {
print('Closing WebView after 5 seconds...');
closeWebView();
});
}),
child: const Text('Launch in app + close after 5 seconds'),
),
const Padding(padding: EdgeInsets.all(16.0)),
FutureBuilder<void>(future: _launched, builder: _launchStatus),
],
),
],
),
);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/url_launcher/lib/url_launcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const MethodChannel _channel = MethodChannel('plugins.flutter.io/url_launcher');
/// WebViews.
/// [enableJavaScript] is an Android only setting. If true, WebView enable
/// javascript.
/// [enableDomStorage] is an Android only setting. If true, WebView enable
/// DOM storage.
///
/// Note that if any of the above are set to true but the URL is not a web URL,
/// this will throw a [PlatformException].
Expand All @@ -57,6 +59,7 @@ Future<bool> launch(
bool forceSafariVC,
bool forceWebView,
bool enableJavaScript,
bool enableDomStorage,
bool universalLinksOnly,
Brightness statusBarBrightness,
}) async {
Expand Down Expand Up @@ -86,6 +89,7 @@ Future<bool> launch(
'useSafariVC': forceSafariVC ?? isWebURL,
'useWebView': forceWebView ?? false,
'enableJavaScript': enableJavaScript ?? false,
'enableDomStorage': enableDomStorage ?? false,
'universalLinksOnly': universalLinksOnly ?? false,
},
);
Expand Down
2 changes: 1 addition & 1 deletion packages/url_launcher/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for launching a URL on Android and iOS. Supports
web, phone, SMS, and email schemes.
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher
version: 5.0.4
version: 5.0.5

flutter:
plugin:
Expand Down
24 changes: 24 additions & 0 deletions packages/url_launcher/test/url_launcher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void main() {
'useSafariVC': true,
'useWebView': false,
'enableJavaScript': false,
'enableDomStorage': false,
'universalLinksOnly': false,
})
],
Expand All @@ -56,6 +57,7 @@ void main() {
'useSafariVC': true,
'useWebView': false,
'enableJavaScript': false,
'enableDomStorage': false,
'universalLinksOnly': false,
})
],
Expand All @@ -73,6 +75,7 @@ void main() {
'useSafariVC': false,
'useWebView': false,
'enableJavaScript': false,
'enableDomStorage': false,
'universalLinksOnly': true,
})
],
Expand All @@ -89,6 +92,7 @@ void main() {
'useSafariVC': true,
'useWebView': true,
'enableJavaScript': false,
'enableDomStorage': false,
'universalLinksOnly': false,
})
],
Expand All @@ -106,6 +110,25 @@ void main() {
'useSafariVC': true,
'useWebView': true,
'enableJavaScript': true,
'enableDomStorage': false,
'universalLinksOnly': false,
})
],
);
});

test('launch force WebView enable DOM storage', () async {
await launch('http://example.com/',
forceWebView: true, enableDomStorage: true);
expect(
log,
<Matcher>[
isMethodCall('launch', arguments: <String, Object>{
'url': 'http://example.com/',
'useSafariVC': true,
'useWebView': true,
'enableJavaScript': false,
'enableDomStorage': true,
'universalLinksOnly': false,
})
],
Expand All @@ -122,6 +145,7 @@ void main() {
'useSafariVC': false,
'useWebView': false,
'enableJavaScript': false,
'enableDomStorage': false,
'universalLinksOnly': false,
})
],
Expand Down