[url_launcher] Add InAppBrowserConfiguration parameter (#5758)

This is #5166 portion of platform interface changes. Adds `InAppBrowserConfiguration` parameter, as well as `InAppBrowserConfiguration.showTitle` parameter that configures whether to show or not to show webpage title
This commit is contained in:
Alex Usmanov
2024-01-04 23:47:06 +05:00
committed by GitHub
parent 31fc7b5dd0
commit 7beab0d305
5 changed files with 65 additions and 1 deletions

View File

@ -1,3 +1,7 @@
## 2.3.0
* Adds `InAppBrowserConfiguration` parameter to `LaunchOptions`, to configure in-app browser views, such as Android Custom Tabs or `SFSafariViewController`.
* Adds `showTitle` parameter to `InAppBrowserConfiguration` in order to control web-page title visibility.
## 2.2.1 ## 2.2.1
* Updates minimum supported SDK version to Flutter 3.10/Dart 3.0. * Updates minimum supported SDK version to Flutter 3.10/Dart 3.0.

View File

@ -50,6 +50,18 @@ class InAppWebViewConfiguration {
final Map<String, String> headers; final Map<String, String> headers;
} }
/// Additional configuration options for [PreferredLaunchMode.inAppBrowserView].
@immutable
class InAppBrowserConfiguration {
/// Creates a new InAppBrowserConfiguration with given settings.
const InAppBrowserConfiguration({this.showTitle = false});
/// Whether or not to show the webpage title.
///
/// May not be supported on all platforms.
final bool showTitle;
}
/// Options for [launchUrl]. /// Options for [launchUrl].
@immutable @immutable
class LaunchOptions { class LaunchOptions {
@ -57,6 +69,7 @@ class LaunchOptions {
const LaunchOptions({ const LaunchOptions({
this.mode = PreferredLaunchMode.platformDefault, this.mode = PreferredLaunchMode.platformDefault,
this.webViewConfiguration = const InAppWebViewConfiguration(), this.webViewConfiguration = const InAppWebViewConfiguration(),
this.browserConfiguration = const InAppBrowserConfiguration(),
this.webOnlyWindowName, this.webOnlyWindowName,
}); });
@ -66,6 +79,9 @@ class LaunchOptions {
/// Configuration for the web view in [PreferredLaunchMode.inAppWebView] mode. /// Configuration for the web view in [PreferredLaunchMode.inAppWebView] mode.
final InAppWebViewConfiguration webViewConfiguration; final InAppWebViewConfiguration webViewConfiguration;
/// Configuration for the browser view in [PreferredLaunchMode.inAppBrowserView] mode.
final InAppBrowserConfiguration browserConfiguration;
/// A web-platform-specific option to set the link target. /// A web-platform-specific option to set the link target.
/// ///
/// Default behaviour when unset should be to open the url in a new tab. /// Default behaviour when unset should be to open the url in a new tab.

View File

@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/url_launcher/
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22 issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a # NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.2.1 version: 2.3.0
environment: environment:
sdk: ">=3.0.0 <4.0.0" sdk: ">=3.0.0 <4.0.0"

View File

@ -0,0 +1,16 @@
// 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.
import 'package:flutter_test/flutter_test.dart';
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
void main() {
test('InAppBrowserConfiguration defaults to showTitle false', () {
expect(const InAppBrowserConfiguration().showTitle, false);
});
test('InAppBrowserConfiguration showTitle can be set to true', () {
expect(const InAppBrowserConfiguration(showTitle: true).showTitle, true);
});
}

View File

@ -0,0 +1,28 @@
// 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.
import 'package:flutter_test/flutter_test.dart';
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
void main() {
test('LaunchOptions have default InAppBrowserConfiguration when not passed',
() {
expect(
const LaunchOptions().browserConfiguration,
const InAppBrowserConfiguration(),
);
});
test('passing non-default InAppBrowserConfiguration to LaunchOptions works',
() {
const InAppBrowserConfiguration browserConfiguration =
InAppBrowserConfiguration(showTitle: true);
const LaunchOptions launchOptions = LaunchOptions(
browserConfiguration: browserConfiguration,
);
expect(launchOptions.browserConfiguration, browserConfiguration);
});
}