swift
swift copied to clipboard
[CopyPropagation] Replace LexicalDestroyHoisting with OwnedLifetimeCanonicalization.
Replace usages of lexical destroy hoisting with owned value canonicalization now that the latter supports lexical values.
I replicated this behavior using Samsung A2Core (API 28), but not on Samsung S10 (API 30):
- Samsung A2Core (API 28):
- Samsung S10 (API 30):
stable, master flutter doctor -v
C:\Users\Win>flutter doctor -v
Could not load custom device from config index 0: Expected enabled to be a boolean.
[√] Flutter (Channel master, 2.11.0-0.0.pre.542, on Microsoft Windows [Version 10.0.19042.1526], locale en-US)
• Flutter version 2.11.0-0.0.pre.542 at D:\FlutterSDK\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 1958656943 (7 days ago), 2022-02-14 05:15:17 -0500
• Engine revision b63614c306
• Dart version 2.17.0 (build 2.17.0-104.0.dev)
• DevTools version 2.10.0
[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at C:\Users\Win\AppData\Local\Android\sdk
• Platform android-31, build-tools 31.0.0
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.2)
• Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
• Visual Studio Community 2019 version 16.11.31624.102
• Windows 10 SDK version 10.0.19041.0
[√] Android Studio (version 2020.3)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
[√] VS Code (version 1.62.3)
• VS Code at C:\Users\Win\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.28.0
[√] Connected device (6 available)
• SM A260G (mobile) • 5200763ebcfa861f • android-arm • Android 8.1.0 (API 27)
• SM G975F (mobile) • RZ8M802WY0X • android-arm64 • Android 11 (API 30)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19042.1526]
• Windows (UWP) (desktop) • winuwp • windows-uwp-x64 •
• Chrome (web) • chrome • web-javascript • Google Chrome 98.0.4758.102
• Edge (web) • edge • web-javascript • Microsoft Edge 98.0.1108.56
[√] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
[√] Flutter (Channel stable, 2.10.1, on Microsoft Windows [Version 10.0.19042.1526], locale en-US)
• Flutter version 2.10.1 at D:\FlutterSDK\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision db747aa133 (12 days ago), 2022-02-09 13:57:35 -0600
• Engine revision ab46186b24
• Dart version 2.16.1
• DevTools version 2.9.2
[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at C:\Users\Win\AppData\Local\Android\sdk
• Platform android-31, build-tools 31.0.0
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.2)
• Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
• Visual Studio Community 2019 version 16.11.31624.102
• Windows 10 SDK version 10.0.19041.0
[√] Android Studio (version 2020.3)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
[√] VS Code (version 1.62.3)
• VS Code at C:\Users\Win\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.28.0
[√] Connected device (5 available)
• SM A260G (mobile) • 5200763ebcfa861f • android-arm • Android 8.1.0 (API 27)
• SM G975F (mobile) • RZ8M802WY0X • android-arm64 • Android 11 (API 30)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19042.1526]
• Chrome (web) • chrome • web-javascript • Google Chrome 98.0.4758.102
• Edge (web) • edge • web-javascript • Microsoft Edge 98.0.1108.56
[√] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
/cc @LongCatIsLooong
Same issue on Galaxy S8. Seems to be after upgrade to Flutter 2.10.
Any update ?
Because it's very restrictive, we can't edit text in the middle, we need to delete selected text before.
Still present in Flutter version 3.0.0. A workaround? This is very blocking for a word processing application.
Hi @darshankawar, could you check whether you have the bug just tapping on this key (without typing any symbol)?

@inevitabile Yes. See below:
https://user-images.githubusercontent.com/67046386/171638703-71854971-a6ae-4dd0-a20e-9d6e9825c3c2.MOV
You may close your issue in favor of this. It can be tracked in this issue. Will update the issue title accordingly.
I was able to reproduce this on a Pixel emulator, Pressing up/down arrow key on a physical keyboard reproduces the issue
https://user-images.githubusercontent.com/31410839/172311939-c891b11c-d020-4320-9557-839ab08d8cf1.mov
code sample
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextField(minLines: 4, maxLines: 4),
],
),
),
);
}
}
flutter doctor -v (mac)
[✓] Flutter (Channel stable, 3.0.1, on macOS 12.3 21E230 darwin-arm, locale en-IN)
• Flutter version 3.0.1 at /Users/mahesh/Documents/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision fb57da5f94 (3 days ago), 2022-05-19 15:50:29 -0700
• Engine revision caaafc5604
• Dart version 2.17.1
• DevTools version 2.12.2
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at /Users/mahesh/Library/Android/sdk
• Platform android-32, build-tools 31.0.0
• ANDROID_HOME = /Users/mahesh/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
• All Android licenses accepted.
[!] Xcode - develop for iOS and macOS (Xcode 13.2.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
! CocoaPods 1.10.2 out of date (1.11.0 is recommended).
CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin
usage on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To upgrade see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
[✓] IntelliJ IDEA Community Edition (version 2021.2.1)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin version 61.2.4
• Dart plugin version 212.5080.8
[✓] VS Code (version 1.66.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.40.0
[✓] Connected device (4 available)
• Redmi K20 Pro (mobile) • 192.168.1.2:5555 • android-arm64 • Android 11 (API 30)
• iPhone 12 Pro (mobile) • 19FD0231-BFF0-441D-B584-AD94C4084525 • ios •
com.apple.CoreSimulator.SimRuntime.iOS-15-2 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 12.3 21E230 darwin-arm
• Chrome (web) • chrome • web-javascript • Google Chrome 101.0.4951.64
[✓] HTTP Host Availability
• All required HTTP hosts are available
! Doctor found issues in 1 category.
[✓] Flutter (Channel master, 3.1.0-0.0.pre.1138, on macOS 12.3 21E230 darwin-arm, locale en-IN)
• Flutter version 3.1.0-0.0.pre.1138 at /Users/mahesh/Documents/flutter_master
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision d9be807192 (2 hours ago), 2022-06-06 21:16:49 -0700
• Engine revision 48864fc837
• Dart version 2.18.0 (build 2.18.0-170.0.dev)
• DevTools version 2.14.0
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4)
• Android SDK at /Users/mahesh/Library/Android/sdk
• Platform android-32, build-tools 33.0.0-rc4
• ANDROID_HOME = /Users/mahesh/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• CocoaPods version 1.11.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
[✓] IntelliJ IDEA Community Edition (version 2021.2.1)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin version 61.2.4
• Dart plugin version 212.5080.8
[✓] VS Code (version 1.67.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.42.0
[✓] Connected device (3 available)
• sdk gphone arm64 (mobile) • emulator-5554 • android-arm64 • Android 11 (API 30) (emulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 12.3 21E230 darwin-arm
• Chrome (web) • chrome • web-javascript • Google Chrome 102.0.5005.61
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
Removing the Samsung label since this tends to occur on nonsamsung devices too.
Any fix ?
@maheshmnj I couldn't reproduce this on emulator. Could you share the repro steps?
@LongCatIsLooong I was able to reproduce this by pressing up/down arrow keys on a physical keyboard please see https://github.com/flutter/flutter/issues/98720#issuecomment-1148260659
@dkwingsmt here's the key events emitted when I press Shift ! !#1 in order on the samsung keyboard:
I/flutter (28918): KeyEvent: KeyDownEvent#a56e2(physicalKey: PhysicalKeyboardKey#0003b(usbHidUsage: "0x30000003b", debugName: "Key with ID 0x30000003b"), logicalKey: LogicalKeyboardKey#00102 (keyId: "0x200000102", keyLabel: "Shift Left", debugName: "Shift Left"), character: null, timeStamp: 0:21:02.527909)
I/flutter (28918): KeyEvent: KeyUpEvent#0b26d(physicalKey: PhysicalKeyboardKey#0003b(usbHidUsage: "0x30000003b", debugName: "Key with ID 0x30000003b"), logicalKey: LogicalKeyboardKey#00102(k eyId: "0x200000102", keyLabel: "Shift Left", debugName: "Shift Left"), character: null, timeStamp: 0:21:02.527978)
I/flutter (28918): KeyEvent: KeyDownEvent#70748(physicalKey: PhysicalKeyboardKey#700e1(usbHidUsage: "0x000700e1", debugName: "Shift Left"), logicalKey: LogicalKeyboardKey#00102(keyId: "0x200000102", keyLabel: "Shift Left", debugName: "Shift Left"), character: null, timeStamp: 0:21:02.543613, synthesized)
The first 2 events are from the Shift press (even if I hold the shift key on the virtual keyboard it still sends both events). The last one is sent when I press !#1 (the key on the Samsung keyboard that allows you to switch from the regular keyboard to the symbol keyboard), and the key event seems to be synthesized. Is there a reason we are synthesizing a KeyDown event here?
Hi,
I can reproduce this issue on my Samsung S8, with a simple application with only basic TextField :
https://user-images.githubusercontent.com/1569578/177317632-dd759643-d98b-4f88-b68c-05cfe11ce06f.mp4
Please provide a fix or a workaround, it's very restrictive for me, many of my customers are impacted.
Thank you.
I had this same issue on TextField in bottom sheets. Got it resolved by making them TextFormFields, no idea why but it might have to do with the Restoration system.
I also have this problem on Android devices. Not only Samsung keyboard but also GBoard. I reproduced this issue by following steps.
Settings -> General management -> Samsung Keyboard settings (or other keyboard settings) -> Swipe, touch, and feedback -> Keyboard swip controls -> Turn on Cursor control
When i turned off Cursor control, the issue went away.
@whitesoil Didn't solve it for me, and seems I was mistaken about replacing it with a TextField, must have gotten lucky :/
This issue totally prevents effective usage of Textfields and needs to be investigated.
@TheCarpetMerchant I agree with you, this issue needs to be investigated.
In my case, it happens on all characters and multiline.
Video information:
- Flutter 3.3.7
- Galaxy S20, API 31 (Android 12)
https://user-images.githubusercontent.com/34286430/200761418-a3d6bd8b-adda-40d4-b5b7-cde69a0f5bf6.mp4
Any predictions on when the issue will be resolved? I'm depending on this regularization to launch 2 apps on the Playstore.
Any updates on this issue, facing the same problems on my Samsung Galaxy S9 android 10.
Edit: Using the stable flutter channel 3.3.9.
@LongCatIsLooong If you cannot reproduce on an emulator, can you hand this to someone with access to physical devices for investigation ? This is preventing usage of text selection, which I think is quite a core feature for any UI framework. This thread contains multiple example of device/API level able to produce the issue. I myself am on a Samsung A7 2018 Android 10 (API level 29) and still getting this issue (Flutter 3.3.9, 2.18.5).
I'm a bit at a loss about what to do about this. This makes TextFields basically unusable !
Any updates on this issue? Same problem on my samsung galaxy note 8 android 9. flutter 3.7.10 stable Edit: android 8,9,10 : got issue (Samsung Keyboard version < 5.x ) android 11,12,13: work fine. (Samsung Keyboard version >= 5.x )
@LongCatIsLooong If you cannot reproduce on an emulator, can you hand this to someone with access to physical devices for investigation ? This is preventing usage of text selection, which I think is quite a core feature for any UI framework. This thread contains multiple example of device/API level able to produce the issue. I myself am on a Samsung A7 2018 Android 10 (API level 29) and still getting this issue (Flutter 3.3.9, 2.18.5).
i see this issue on Pixel 7
as far as I can tell, this is much bigger issue than being able to tap/cursor inside a word. My android browser version of a flutter web app moves the cursor one or two lines away nowhere near the point of the tap. This is with a Pixel 7 with latest Flutter version
This is crazy!!
Can anyone recommend a workaround of any kind please!!
I have a workaround. I don't know if it's a good Idea, but it's save my app because i think this is a very important issue for users.
Simply listen for the key event on Android, anf when the shift Key are pressed, automatically simulate the key UP event for shift :
bool Function(KeyMessage)? _previousEvent;
@override
void initState() {
super.initState();
_previousEvent = ServicesBinding.instance.keyEventManager.keyMessageHandler;
ServicesBinding.instance.keyEventManager.keyMessageHandler = (event) {
if (!kIsWeb &&
Platform.isAndroid &&
event.events.any((element) =>
element.physicalKey == PhysicalKeyboardKey.shiftLeft)) {
HardwareKeyboard.instance.handleKeyEvent(KeyUpEvent(
physicalKey: PhysicalKeyboardKey.shiftLeft,
logicalKey: LogicalKeyboardKey.shiftLeft,
timeStamp:
Duration(milliseconds: DateTime.now().millisecondsSinceEpoch)));
return true;
} else if (_previousEvent != null) {
return _previousEvent!(event);
}
return false;
};
}
@override
void dispose() { ServicesBinding.instance.keyEventManager.keyMessageHandler = _previousEvent;
super.dispose();
}
I use this on my app and it's ok for Samsung devices. Hope for a better fix...
I have a workaround. I don't know if it's a good Idea, but it's save my app because i think this is a very important issue for users.
Simply listen for the key event on Android, anf when the shift Key are pressed, automatically simulate the key UP event for shift :
bool Function(KeyMessage)? _previousEvent; @override void initState() { super.initState(); _previousEvent = ServicesBinding.instance.keyEventManager.keyMessageHandler; ServicesBinding.instance.keyEventManager.keyMessageHandler = (event) { if (!kIsWeb && Platform.isAndroid && event.events.any((element) => element.physicalKey == PhysicalKeyboardKey.shiftLeft)) { HardwareKeyboard.instance.handleKeyEvent(KeyUpEvent( physicalKey: PhysicalKeyboardKey.shiftLeft, logicalKey: LogicalKeyboardKey.shiftLeft, timeStamp: Duration(milliseconds: DateTime.now().millisecondsSinceEpoch))); return true; } else if (_previousEvent != null) { return _previousEvent!(event); } return false; }; } @override void dispose() { ServicesBinding.instance.keyEventManager.keyMessageHandler = _previousEvent; super.dispose(); }I use this on my app and it's ok for Samsung devices. Hope for a better fix...
Thank you SO much for your reply. I am dealing with (and I think this thread is about) tapping on a location on a cell phone , and having the cursor end up somewhere else. Does a tap induce a key event? Else I'm not sure how a key handler would help.
Or perhaps you are focusing on the text selection aspect of the thread which would of course have relevance to key events?
Regards, Henry
@maheshmnj I couldn't reproduce this on emulator. Could you share the repro steps?
pls see this issue for a simple example to reproduce directly using the flutter dev cookbook: https://github.com/flutter/flutter/issues/124483
I have a workaround. I don't know if it's a good Idea, but it's save my app because i think this is a very important issue for users.
Simply listen for the key event on Android, anf when the shift Key are pressed, automatically simulate the key UP event for shift :
bool Function(KeyMessage)? _previousEvent; @override void initState() { super.initState(); _previousEvent = ServicesBinding.instance.keyEventManager.keyMessageHandler; ServicesBinding.instance.keyEventManager.keyMessageHandler = (event) { if (!kIsWeb && Platform.isAndroid && event.events.any((element) => element.physicalKey == PhysicalKeyboardKey.shiftLeft)) { HardwareKeyboard.instance.handleKeyEvent(KeyUpEvent( physicalKey: PhysicalKeyboardKey.shiftLeft, logicalKey: LogicalKeyboardKey.shiftLeft, timeStamp: Duration(milliseconds: DateTime.now().millisecondsSinceEpoch))); return true; } else if (_previousEvent != null) { return _previousEvent!(event); } return false; }; } @override void dispose() { ServicesBinding.instance.keyEventManager.keyMessageHandler = _previousEvent; super.dispose(); }I use this on my app and it's ok for Samsung devices. Hope for a better fix...
It worked for me. Thank you very much! =)
I have an incomplete solution. Because you should edit flutter library.
This issue is caused by TextSelectionGestureDetectorBuilder Class and TextSelectionGestureDetector Widget, used by TextField Widget.
In TextSelectionGestureDetectorBuilder, buildGestureDetector method return TextSelectionGestureDetector instance with gesture event methods.
onSingleTapUp method is Important.
You can see at flutter/packages/flutter/lib/src/widgets/text_selection.dart (or trace TextField -> _selectionGestureDetectorBuilder.buildGestureDetector -> onSingleTapUp)
Delete below if(isShiftPressedValid){...} on TargetPlatform.android case and restart or rebuild app.
@protected
void onSingleTapUp(TapUpDetails details) {
if (delegate.selectionEnabled) {
// Handle shift + click selection if needed.
final bool isShiftPressedValid =
_isShiftPressed && renderEditable.selection?.baseOffset != null;
switch (defaultTargetPlatform) {
case TargetPlatform.linux:
case TargetPlatform.macOS:
case TargetPlatform.windows:
editableText.hideToolbar();
// On desktop platforms the selection is set on tap down.
if (_isShiftTapping) {
_isShiftTapping = false;
}
break;
case TargetPlatform.android:
case TargetPlatform.fuchsia:
editableText.hideToolbar();
// * This if condition causes the issue.
if (isShiftPressedValid) {
_isShiftTapping = true;
_extendSelection(details.globalPosition, SelectionChangedCause.tap);
return;
}
renderEditable.selectPosition(cause: SelectionChangedCause.tap);
break;
case TargetPlatform.iOS:
if (isShiftPressedValid) {
In my case, it works fine.
Can someone on the team please take this issue seriously ? @LongCatIsLooong identified the issue almost 10 months ago ! What can we do to make the team understand that this renders text input almost unusable ??