Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 9bb5b5d

Browse files
committed
add dispatchKeyEvent back to deprecated FlutterView
1 parent 131a230 commit 9bb5b5d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

shell/platform/android/io/flutter/view/FlutterView.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.util.AttributeSet;
2222
import android.util.SparseArray;
2323
import android.view.DisplayCutout;
24+
import android.view.KeyEvent;
2425
import android.view.MotionEvent;
2526
import android.view.PointerIcon;
2627
import android.view.Surface;
@@ -267,6 +268,23 @@ public DartExecutor getDartExecutor() {
267268
return dartExecutor;
268269
}
269270

271+
@Override
272+
public boolean dispatchKeyEvent(KeyEvent event) {
273+
Log.e(TAG, "dispatchKeyEvent: " + event.toString());
274+
if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
275+
// Tell Android to start tracking this event.
276+
getKeyDispatcherState().startTracking(event, this);
277+
} else if (event.getAction() == KeyEvent.ACTION_UP) {
278+
// Stop tracking the event.
279+
getKeyDispatcherState().handleUpEvent(event);
280+
}
281+
// If the key processor doesn't handle it, then send it on to the
282+
// superclass. The key processor will typically handle all events except
283+
// those where it has re-dispatched the event after receiving a reply from
284+
// the framework that the framework did not handle it.
285+
return (isAttached() && androidKeyProcessor.onKeyEvent(event)) || super.dispatchKeyEvent(event);
286+
}
287+
270288
public FlutterNativeView getFlutterNativeView() {
271289
return mNativeView;
272290
}

0 commit comments

Comments
 (0)