Closed
Description
On Desktop and Web, Flutter maintains keyboard state based on key events received when the window has focus.
If a keyboard event happens when the window has lost focus, Flutter keyboard state is not updated.
This leads to visible bugs, especially ones related to modifier keys. See #112488
Steps to Reproduce
- Launch the below code sample.
- Enter some test in the text field.
- Click somewhere on the text.
- Hold shift key pressed.
- While holding the shift key, click somewhere else on the text, the text between both click positions is selected.
- While holding the shift key, click on another window (Flutter window loses focus).
- Release the shift key.
- Click inside the text field.
Expected results: At step 8, the click should just move the cursor and no text should be selected
Actual results: At step 8, the click updates the selection (as the shift key was still pressed).
Code sample
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Container(
alignment: Alignment.center,
padding: const EdgeInsets.all(16),
child: const TextField(),
),
),
);
}
}
As per this discussion, the modifier keys states should be also updated based on pointer events (which contain a modifier state property).
This should be implemented on the engine side for:
- Web : fixed by [Web] Synthesize key events for modifier keys on pointer events. engine#36724
- Linux : fixed by [Linux] Synthesize modifier keys events on pointer events engine#37491
- MacOS : [macos] Synthesize modifier keys events on pointer events engine#37870
- Windows : fixed by [Windows] Synthesize modifier keys events on pointer events engine#38138
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done (PR merged)