Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
pass controller in focus callback
  • Loading branch information
hellohuanlin committed Jun 22, 2022
commit d7667a44c100080e000d186e1da419779fd1f363
14 changes: 5 additions & 9 deletions packages/flutter/lib/src/widgets/platform_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -569,12 +569,13 @@ class _UiKitViewState extends State<UiKitView> {

@override
Widget build(BuildContext context) {
if (_controller == null) {
final UiKitViewController? controller = _controller;
if (controller == null) {
return const SizedBox.expand();
}
return Focus(
focusNode: _focusNode,
onFocusChange: _onFocusChange,
onFocusChange: (bool isFocused) => _onFocusChange(isFocused, controller),
child: _UiKitPlatformView(
controller: _controller!,
hitTestBehavior: widget.hitTestBehavior,
Expand Down Expand Up @@ -659,12 +660,7 @@ class _UiKitViewState extends State<UiKitView> {
});
}

void _onFocusChange(bool isFocused) {
assert(_controller != null, 'warning: attempt to focus a UIKitView when it is not ready. ');
if (_controller == null) {
return;
}

void _onFocusChange(bool isFocused, UiKitViewController controller) {
if (!isFocused) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits:
Maybe this would be more readable if we check if (isFocused) first?

if (isFocused) {
  SystemChannels.textInput.invokeMethod<void>(
        'TextInput.setPlatformViewClient',
        <String, dynamic>{'platformViewId': _controller!.id},

}

Or we can escape early instead of if-else

if (!isfocused) {
  return;
}
 SystemChannels.textInput.invokeMethod<void>(
        'TextInput.setPlatformViewClient',
        <String, dynamic>{'platformViewId': _controller!.id},

// Unlike Android, we do not need to send "clearFocus" channel message
// to the engine, because focusing on another view will automatically
Expand All @@ -673,7 +669,7 @@ class _UiKitViewState extends State<UiKitView> {
}
SystemChannels.textInput.invokeMethod<void>(
'TextInput.setPlatformViewClient',
<String, dynamic>{'platformViewId': _controller!.id},
<String, dynamic>{'platformViewId': controller.id},
);
}
}
Expand Down