Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e41ea0e
add android show title customization functionality
Alex-Usmanov Oct 17, 2023
fb67692
Pass the parameter
Alex-Usmanov Oct 17, 2023
21cd06f
Dependency overrides
Alex-Usmanov Oct 17, 2023
276c08b
Add tests for native side
Alex-Usmanov Oct 17, 2023
1897451
Cover dart side with tests
Alex-Usmanov Oct 17, 2023
5cd1709
Format
Alex-Usmanov Oct 17, 2023
bc943c5
Reduce code repetition
Alex-Usmanov Oct 17, 2023
d6306ba
Revert todo change
Alex-Usmanov Oct 18, 2023
f59475b
Wrap browser customization values in another configuration object
Alex-Usmanov Oct 20, 2023
157343b
Remove deps overrides
Alex-Usmanov Oct 20, 2023
ae20b08
Revert more deps overrides
Alex-Usmanov Oct 20, 2023
214b0a9
Revert web as well
Alex-Usmanov Oct 20, 2023
cd7dfc9
Revert go_router
Alex-Usmanov Oct 20, 2023
d205c7c
Merge branch 'main' into main
Alex-Usmanov Oct 20, 2023
5eef662
Merge remote-tracking branch 'upstream/main'
Alex-Usmanov Oct 27, 2023
c86ff6e
Format files
Alex-Usmanov Oct 27, 2023
92b2197
Fix tests
Alex-Usmanov Oct 27, 2023
425617e
Add browseroptions to launchUrlString & add more tests
Alex-Usmanov Oct 30, 2023
ece2b78
Fix docstrings
Alex-Usmanov Dec 7, 2023
3ddd644
Revert test format change
Alex-Usmanov Dec 7, 2023
cd361d0
Fix tests
Alex-Usmanov Dec 8, 2023
f0017b7
Version bumps and changelogs
Alex-Usmanov Dec 8, 2023
6105671
Merge remote-tracking branch 'upstream/main'
Alex-Usmanov Dec 8, 2023
a50be0f
Return path-based dependencies
Alex-Usmanov Dec 8, 2023
ef9c154
Add licences
Alex-Usmanov Dec 11, 2023
f4b08cb
Merge remote-tracking branch 'upstream/main'
Alex-Usmanov Dec 11, 2023
80d439b
Fix documentation & changelog
Alex-Usmanov Dec 26, 2023
992d38e
Merge remote-tracking branch 'upstream/main'
Alex-Usmanov Dec 26, 2023
193c076
Add backticks to SFSafariViewController in platform interface changelog
Alex-Usmanov Jan 4, 2024
b399c9b
Merge remote-tracking branch 'upstream/main'
Alex-Usmanov Jan 4, 2024
1ad83a2
More merging
Alex-Usmanov Jan 4, 2024
298a705
Merge remote-tracking branch 'upstream/main' into show-title
Alex-Usmanov Feb 12, 2024
70f5eb0
Merge remote-tracking branch 'upstream/main' into show-title
Alex-Usmanov Mar 31, 2024
8f67ab9
Remove dependency overrides
Alex-Usmanov Mar 31, 2024
c203ae0
Revert changelog
Alex-Usmanov Apr 1, 2024
5ae7bc9
Merge branch 'main' into show-title
Alex-Usmanov Apr 7, 2024
e646958
Merge remote-tracking branch 'upstream/main' into show-title
Alex-Usmanov May 10, 2024
7d92695
Merge remote-tracking branch 'upstream/main' into show-title
Alex-Usmanov May 21, 2024
90360b0
Fix missing classname in type_conversion.dart
Alex-Usmanov Jun 3, 2024
647a8ce
Merge remote-tracking branch 'upstream/main' into show-title
Alex-Usmanov Jun 3, 2024
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
Prev Previous commit
Next Next commit
Pass the parameter
  • Loading branch information
Alex-Usmanov committed Oct 17, 2023
commit fb67692dc9301765d3248fd891ce2148b7a34387
17 changes: 17 additions & 0 deletions packages/url_launcher/url_launcher/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ class _MyHomePageState extends State<MyHomePage> {
}
}

Future<void> _launchInAppWithShowTitle(Uri url) async {
if (!await launchUrl(
url,
mode: LaunchMode.inAppWebView,
webViewConfiguration: const WebViewConfiguration(showTitle: true),
)) {
throw Exception('Could not launch $url');
}
}

Future<void> _launchAsInAppWebViewWithCustomHeaders(Uri url) async {
if (!await launchUrl(
url,
Expand Down Expand Up @@ -214,6 +224,13 @@ class _MyHomePageState extends State<MyHomePage> {
child: const Text('Launch in app + close after 5 seconds'),
),
const Padding(padding: EdgeInsets.all(16.0)),
ElevatedButton(
onPressed: () => setState(() {
_launched = _launchInAppWithShowTitle(toLaunch);
}),
child: const Text('Launch in app with showTitle'),
),
const Padding(padding: EdgeInsets.all(16.0)),
Link(
uri: Uri.parse(
'https://pub.dev/documentation/url_launcher/latest/link/link-library.html'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ InAppWebViewConfiguration convertConfiguration(WebViewConfiguration config) {
enableJavaScript: config.enableJavaScript,
enableDomStorage: config.enableDomStorage,
headers: config.headers,
showTitle: config.showTitle,
);
}

Expand Down
6 changes: 6 additions & 0 deletions packages/url_launcher/url_launcher/lib/src/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class WebViewConfiguration {
this.enableJavaScript = true,
this.enableDomStorage = true,
this.headers = const <String, String>{},
this.showTitle = false,
});

/// Whether or not JavaScript is enabled for the web content.
Expand All @@ -51,4 +52,9 @@ class WebViewConfiguration {
/// [Browser.EXTRA_HEADERS](https://developer.android.com/reference/android/provider/Browser#EXTRA_HEADERS)
/// Not all browsers support this, so it is not guaranteed to be honored.
final Map<String, String> headers;

/// Whether or not to show the webpage title when using Chrome Custom Tabs.
///
/// Only works on Android.
final bool showTitle;
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ void main() {
enableDomStorage: false,
universalLinksOnly: false,
headers: <String, String>{},
showTitle: false,
),
true);
await launcher.closeWebView();
Expand Down
26 changes: 15 additions & 11 deletions packages/url_launcher/url_launcher_android/lib/src/messages.g.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v10.0.0), do not edit directly.
// Autogenerated from Pigeon (v10.1.6), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import

Expand All @@ -17,6 +17,7 @@ class WebViewOptions {
required this.enableJavaScript,
required this.enableDomStorage,
required this.headers,
required this.showTitle,
});

bool enableJavaScript;
Expand All @@ -25,11 +26,14 @@ class WebViewOptions {

Map<String?, String?> headers;

bool showTitle;

Object encode() {
return <Object?>[
enableJavaScript,
enableDomStorage,
headers,
showTitle,
];
}

Expand All @@ -39,6 +43,7 @@ class WebViewOptions {
enableJavaScript: result[0]! as bool,
enableDomStorage: result[1]! as bool,
headers: (result[2] as Map<Object?, Object?>?)!.cast<String?, String?>(),
showTitle: result[3]! as bool,
);
}
}
Expand All @@ -58,7 +63,7 @@ class _UrlLauncherApiCodec extends StandardMessageCodec {
@override
Object? readValueOfType(int type, ReadBuffer buffer) {
switch (type) {
case 128:
case 128:
return WebViewOptions.decode(readValue(buffer)!);
default:
return super.readValueOfType(type, buffer);
Expand All @@ -79,7 +84,7 @@ class UrlLauncherApi {
/// Returns true if the URL can definitely be launched.
Future<bool> canLaunchUrl(String arg_url) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.UrlLauncherApi.canLaunchUrl', codec,
'dev.flutter.pigeon.url_launcher_android.UrlLauncherApi.canLaunchUrl', codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(<Object?>[arg_url]) as List<Object?>?;
Expand All @@ -105,10 +110,9 @@ class UrlLauncherApi {
}

/// Opens the URL externally, returning true if successful.
Future<bool> launchUrl(
String arg_url, Map<String?, String?> arg_headers) async {
Future<bool> launchUrl(String arg_url, Map<String?, String?> arg_headers) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.UrlLauncherApi.launchUrl', codec,
'dev.flutter.pigeon.url_launcher_android.UrlLauncherApi.launchUrl', codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(<Object?>[arg_url, arg_headers]) as List<Object?>?;
Expand All @@ -135,10 +139,9 @@ class UrlLauncherApi {

/// Opens the URL in an in-app WebView, returning true if it opens
/// successfully.
Future<bool> openUrlInWebView(
String arg_url, WebViewOptions arg_options) async {
Future<bool> openUrlInWebView(String arg_url, WebViewOptions arg_options) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.UrlLauncherApi.openUrlInWebView', codec,
'dev.flutter.pigeon.url_launcher_android.UrlLauncherApi.openUrlInWebView', codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(<Object?>[arg_url, arg_options]) as List<Object?>?;
Expand Down Expand Up @@ -166,9 +169,10 @@ class UrlLauncherApi {
/// Closes the view opened by [openUrlInSafariViewController].
Future<void> closeWebView() async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.UrlLauncherApi.closeWebView', codec,
'dev.flutter.pigeon.url_launcher_android.UrlLauncherApi.closeWebView', codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList = await channel.send(null) as List<Object?>?;
final List<Object?>? replyList =
await channel.send(null) as List<Object?>?;
if (replyList == null) {
throw PlatformException(
code: 'channel-error',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,42 @@ class UrlLauncherAndroid extends UrlLauncherPlatform {
required Map<String, String> headers,
String? webOnlyWindowName,
}) async {
final bool succeeded;
return launchUrl(
url,
LaunchOptions(
webViewConfiguration: InAppWebViewConfiguration(
enableJavaScript: enableJavaScript,
enableDomStorage: enableDomStorage,
headers: headers,
),
webOnlyWindowName: webOnlyWindowName,
),
);
}

@override
Future<bool> launchUrl(String url, LaunchOptions options) async {
final bool isWebURL = url.startsWith('http:') || url.startsWith('https:');
final bool useWebView = options.mode == PreferredLaunchMode.inAppWebView ||
(isWebURL && options.mode == PreferredLaunchMode.platformDefault);

bool succeeded;

if (useWebView) {
succeeded = await _hostApi.openUrlInWebView(
url,
WebViewOptions(
enableJavaScript: enableJavaScript,
enableDomStorage: enableDomStorage,
headers: headers));
url,
WebViewOptions(
enableJavaScript: options.webViewConfiguration.enableJavaScript,
enableDomStorage: options.webViewConfiguration.enableDomStorage,
headers: options.webViewConfiguration.headers,
showTitle: options.webViewConfiguration.showTitle,
),
);
} else {
succeeded = await _hostApi.launchUrl(url, headers);
succeeded =
await _hostApi.launchUrl(url, options.webViewConfiguration.headers);
}

// TODO(stuartmorgan): Remove this special handling as part of a
// breaking change to rework failure handling across all platform. The
// current behavior is backwards compatible with the previous Java error.
Expand All @@ -81,6 +106,7 @@ class UrlLauncherAndroid extends UrlLauncherPlatform {
code: 'ACTIVITY_NOT_FOUND',
message: 'No Activity found to handle intent { $url }');
}

return succeeded;
}

Expand Down
12 changes: 8 additions & 4 deletions packages/url_launcher/url_launcher_android/pigeons/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@ import 'package:pigeon/pigeon.dart';

/// Configuration options for an in-app WebView.
class WebViewOptions {
const WebViewOptions(
{required this.enableJavaScript,
required this.enableDomStorage,
this.headers = const <String, String>{}});
const WebViewOptions({
required this.enableJavaScript,
required this.enableDomStorage,
this.headers = const <String, String>{},
required this.showTitle,
});

final bool enableJavaScript;
final bool enableDomStorage;
// TODO(stuartmorgan): Declare these as non-nullable generics once
// https://github.com/flutter/flutter/issues/97848 is fixed. In practice,
// the values will never be null, and the native implementation assumes that.
final Map<String?, String?> headers;
final bool showTitle;
}

@HostApi()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,11 @@ class _FakeUrlLauncherApi implements UrlLauncherApi {
@override
Future<bool> launchUrl(String url, Map<String?, String?> headers) async {
passedWebViewOptions = WebViewOptions(
enableJavaScript: false, enableDomStorage: false, headers: headers);
enableJavaScript: false,
enableDomStorage: false,
headers: headers,
showTitle: false,
);
usedWebView = false;
return _launch(url);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class InAppWebViewConfiguration {
this.enableJavaScript = true,
this.enableDomStorage = true,
this.headers = const <String, String>{},
this.showTitle = false,
});

/// Whether or not JavaScript is enabled for the web content.
Expand All @@ -44,6 +45,11 @@ class InAppWebViewConfiguration {

/// Additional headers to pass in the load request.
final Map<String, String> headers;

/// Whether or not to show the webpage title when using Chrome Custom Tabs.
///
/// Only works on Android.
final bool showTitle;
}

/// Options for [launchUrl].
Expand Down