ChromeSafariBrowser class

Class that provides a visible standard interface for browsing the web. It presents a self-contained web interface inside your app.

If you need to customize or interact with the web content, use the InAppWebView widget.

This class uses native Chrome Custom Tabs on Android and SFSafariViewController on iOS.

NOTE: If you want to use the ChromeSafariBrowser class on Android 11+ you need to specify your app querying for android.support.customtabs.action.CustomTabsService in your AndroidManifest.xml (you can read more about it here: https://developers.google.com/web/android/custom-tabs/best-practices#applications_targeting_android_11_api_level_30_or_above).

Officially Supported Platforms/Implementations:

  • Android
  • iOS
Implemented types

Constructors

ChromeSafariBrowser()
Constructs a ChromeSafariBrowser.
ChromeSafariBrowser.fromPlatform(PlatformChromeSafariBrowser platform)
Constructs a ChromeSafariBrowser from a specific platform implementation.
ChromeSafariBrowser.fromPlatformCreationParams(PlatformChromeSafariBrowserCreationParams params)
Constructs a ChromeSafariBrowser from creation params for a specific platform.

Properties

hashCode int
The hash code for this object.
no setterinherited
id String
View ID used internally.
no setter
platform PlatformChromeSafariBrowser
Implementation of PlatformChromeSafariBrowser for the current platform.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addMenuItem(ChromeSafariBrowserMenuItem menuItem) → void
Adds a ChromeSafariBrowserMenuItem to the menu.
addMenuItems(List<ChromeSafariBrowserMenuItem> menuItems) → void
Adds a list of ChromeSafariBrowserMenuItem to the menu.
close() Future<void>
Closes the PlatformChromeSafariBrowser instance.
dispose() → void
Disposes the channel and event handler.
isEngagementSignalsApiAvailable() Future<bool>
Returns whether the Engagement Signals API is available. The availability of the Engagement Signals API may change at runtime. If an EngagementSignalsCallback has been set, an PlatformChromeSafariBrowserEvents.onSessionEnded signal will be sent if the API becomes unavailable later.
isOpened() bool
Returns true if the PlatformChromeSafariBrowser instance is opened, otherwise false.
launchUrl({required WebUri url, Map<String, String>? headers, List<WebUri>? otherLikelyURLs, WebUri? referrer}) Future<void>
Tells the browser to launch with url.
mayLaunchUrl({WebUri? url, List<WebUri>? otherLikelyURLs}) Future<bool>
Tells the browser of a likely future navigation to a URL. The most likely URL has to be specified first. Optionally, a list of other likely URLs can be provided. They are treated as less likely than the first one, and have to be sorted in decreasing priority order. These additional URLs may be ignored. All previous calls to this method will be deprioritized.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onClosed() → void
Event fired when the PlatformChromeSafariBrowser is closed.
override
onCompletedInitialLoad(bool? didLoadSuccessfully) → void
Event fired when the initial URL load is complete.
override
onGreatestScrollPercentageIncreased(int scrollPercentage) → void
Called when a user has reached a greater scroll percentage on the page. The greatest scroll percentage is reset if the user navigates to a different page. If the current page's total height changes, this method will be called again only if the scroll progress reaches a higher percentage based on the new and current height of the page.
override
onInitialLoadDidRedirect(WebUri? url) → void
Event fired when the initial URL load is complete.
override
onMessageChannelReady() → void
Called when the PlatformChromeSafariBrowser has requested a postMessage channel through PlatformChromeSafariBrowser.requestPostMessageChannel and the channel is ready for sending and receiving messages on both ends.
override
onNavigationEvent(CustomTabsNavigationEventType? navigationEvent) → void
Event fired when a navigation event happens.
override
onOpened() → void
Event fired when the PlatformChromeSafariBrowser is opened.
override
onPostMessage(String message) → void
Called when a tab controlled by this PlatformChromeSafariBrowser has sent a postMessage. If PlatformChromeSafariBrowser.postMessage is called from a single thread, then the messages will be posted in the same order. When received on the client side, it is the client's responsibility to preserve the ordering further.
override
onRelationshipValidationResult(CustomTabsRelationType? relation, WebUri? requestedOrigin, bool result) → void
Event fired when a relationship validation result is available.
override
onServiceConnected() → void
Event fired when the when connecting from Android Custom Tabs Service.
override
onSessionEnded(bool didUserInteract) → void
Called when a CustomTabsSession is ending or when no further Engagement Signals callbacks are expected to report whether any user action has occurred during the session.
override
onVerticalScrollEvent(bool isDirectionUp) → void
Called when a user scrolls the tab.
override
onWillOpenInBrowser() → void
Event fired when the user opens the current page in the default browser by tapping the toolbar button.
override
open({WebUri? url, Map<String, String>? headers, List<WebUri>? otherLikelyURLs, WebUri? referrer, ChromeSafariBrowserClassOptions? options, ChromeSafariBrowserSettings? settings}) Future<void>
Opens the PlatformChromeSafariBrowser instance with an url.
postMessage(String message) Future<CustomTabsPostMessageResultType>
Sends a postMessage request using the origin communicated via requestPostMessageChannel. Fails when called before PlatformChromeSafariBrowserEvents.onMessageChannelReady event.
requestPostMessageChannel({required WebUri sourceOrigin, WebUri? targetOrigin}) Future<bool>
Sends a request to create a two way postMessage channel between the client and the browser. If you want to specifying the target origin to communicate with, set the targetOrigin.
setActionButton(ChromeSafariBrowserActionButton actionButton) → void
Set a custom action button.
setSecondaryToolbar(ChromeSafariBrowserSecondaryToolbar secondaryToolbar) → void
Sets the remote views displayed in the secondary toolbar in a custom tab.
toString() String
A string representation of this object.
inherited
updateActionButton({required Uint8List icon, required String description}) Future<void>
Updates the ChromeSafariBrowserActionButton.icon and ChromeSafariBrowserActionButton.description.
updateSecondaryToolbar(ChromeSafariBrowserSecondaryToolbar secondaryToolbar) Future<void>
Sets or updates (if already present) the Remote Views of the secondary toolbar in an existing custom tab session.
validateRelationship({required CustomTabsRelationType relation, required WebUri origin}) Future<bool>
Requests to validate a relationship between the application and an origin.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

clearWebsiteData() Future<void>
Clear associated website data accrued from browsing activity within your app. This includes all local storage, cached resources, and cookies.
getMaxToolbarItems() Future<int>
The maximum number of allowed secondary toolbar items.
getPackageName({List<String>? packages, bool ignoreDefault = false}) Future<String?>
Returns the preferred package to use for Custom Tabs. The preferred package name is the default VIEW intent handler as long as it supports Custom Tabs. To modify this preferred behavior, set ignoreDefault to true and give a non empty list of package names in packages. This method queries the PackageManager to determine which packages support the Custom Tabs API. On apps that target Android 11 and above, this requires adding the following package visibility elements to your manifest.
invalidatePrewarmingToken(PrewarmingToken prewarmingToken) Future<void>
Ends all prewarmed connections associated with the token, except for connections that are also kept alive by other tokens.
isAvailable() Future<bool>
On Android, returns true if Chrome Custom Tabs is available. On iOS, returns true if SFSafariViewController is available. Otherwise returns false.
prewarmConnections(List<WebUri> URLs) Future<PrewarmingToken?>
Prewarms a connection to each URL. SFSafariViewController will automatically use a prewarmed connection if possible when loading its initial URL.