requestFocus method
- @SupportedPlatforms.new(platforms: [AndroidPlatform(apiName: 'WebView.requestFocus', apiUrl: 'https://developer.android.com/reference/android/webkit/WebView#requestFocus(int,%20android.graphics.Rect)'), IOSPlatform(apiName: 'UIResponder.becomeFirstResponder', apiUrl: 'https://developer.apple.com/documentation/uikit/uiresponder/1621113-becomefirstresponder'), MacOSPlatform(apiName: 'NSWindow.makeFirstResponder', apiUrl: 'https://developer.apple.com/documentation/appkit/nswindow/1419366-makefirstresponder'), LinuxPlatform(apiName: 'wpe_view_backend_add_activity_state', apiUrl: 'https://wpewebkit.org/reference/stable/wpe-platform-2.0/func.view_backend_add_activity_state.html', note: 'Adds focused state to WPE backend')])
- @SupportedPlatforms.new(platforms: [AndroidPlatform()]) FocusDirection? direction,
- @SupportedPlatforms.new(platforms: [AndroidPlatform()]) InAppWebViewRect? previouslyFocusedRect,
Call this method when you want to try the WebView to be the first responder.
On Android, call this to try to give focus to the WebView and
give it hints about the direction and a specific previouslyFocusedRect that the focus is coming from.
The previouslyFocusedRect can help give larger views a finer grained hint about where focus is coming from,
and therefore, where to show selection, or forward focus change internally.
Returns true whether this WebView actually took focus; otherwise, false.
Officially Supported Platforms/Implementations:
- Android WebView (Official API - WebView.requestFocus)
- iOS WKWebView (Official API - UIResponder.becomeFirstResponder)
- macOS WKWebView (Official API - NSWindow.makeFirstResponder)
- Linux WPE WebKit (Official API - wpe_view_backend_add_activity_state):
- Adds focused state to WPE backend
Parameters - Officially Supported Platforms/Implementations:
direction:- Android WebView
previouslyFocusedRect:- Android WebView
Use the PlatformInAppWebViewController.isMethodSupported method to check if this method is supported at runtime.
Implementation
@SupportedPlatforms(
platforms: [
AndroidPlatform(
apiName: 'WebView.requestFocus',
apiUrl:
'https://developer.android.com/reference/android/webkit/WebView#requestFocus(int,%20android.graphics.Rect)',
),
IOSPlatform(
apiName: 'UIResponder.becomeFirstResponder',
apiUrl:
'https://developer.apple.com/documentation/uikit/uiresponder/1621113-becomefirstresponder',
),
MacOSPlatform(
apiName: 'NSWindow.makeFirstResponder',
apiUrl:
'https://developer.apple.com/documentation/appkit/nswindow/1419366-makefirstresponder',
),
LinuxPlatform(
apiName: 'wpe_view_backend_add_activity_state',
apiUrl:
'https://wpewebkit.org/reference/stable/wpe-platform-2.0/func.view_backend_add_activity_state.html',
note: 'Adds focused state to WPE backend',
),
],
)
Future<bool?> requestFocus({
@SupportedPlatforms(platforms: [AndroidPlatform()])
FocusDirection? direction,
@SupportedPlatforms(platforms: [AndroidPlatform()])
InAppWebViewRect? previouslyFocusedRect,
}) {
throw UnimplementedError(
'${PlatformInAppWebViewControllerMethod.requestFocus.name} is not implemented on the current platform',
);
}