Skip to content

Commit d7667a4

Browse files
committed
pass controller in focus callback
1 parent da8faf3 commit d7667a4

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

packages/flutter/lib/src/widgets/platform_view.dart

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -569,12 +569,13 @@ class _UiKitViewState extends State<UiKitView> {
569569

570570
@override
571571
Widget build(BuildContext context) {
572-
if (_controller == null) {
572+
final UiKitViewController? controller = _controller;
573+
if (controller == null) {
573574
return const SizedBox.expand();
574575
}
575576
return Focus(
576577
focusNode: _focusNode,
577-
onFocusChange: _onFocusChange,
578+
onFocusChange: (bool isFocused) => _onFocusChange(isFocused, controller),
578579
child: _UiKitPlatformView(
579580
controller: _controller!,
580581
hitTestBehavior: widget.hitTestBehavior,
@@ -659,12 +660,7 @@ class _UiKitViewState extends State<UiKitView> {
659660
});
660661
}
661662

662-
void _onFocusChange(bool isFocused) {
663-
assert(_controller != null, 'warning: attempt to focus a UIKitView when it is not ready. ');
664-
if (_controller == null) {
665-
return;
666-
}
667-
663+
void _onFocusChange(bool isFocused, UiKitViewController controller) {
668664
if (!isFocused) {
669665
// Unlike Android, we do not need to send "clearFocus" channel message
670666
// to the engine, because focusing on another view will automatically
@@ -673,7 +669,7 @@ class _UiKitViewState extends State<UiKitView> {
673669
}
674670
SystemChannels.textInput.invokeMethod<void>(
675671
'TextInput.setPlatformViewClient',
676-
<String, dynamic>{'platformViewId': _controller!.id},
672+
<String, dynamic>{'platformViewId': controller.id},
677673
);
678674
}
679675
}

0 commit comments

Comments
 (0)