diff --git a/lib/src/utils/platform.dart b/lib/src/utils/platform.dart index 1ee63392..b2ab2882 100644 --- a/lib/src/utils/platform.dart +++ b/lib/src/utils/platform.dart @@ -1,3 +1,6 @@ +import 'dart:io'; + +import 'package:device_info_plus/device_info_plus.dart'; import 'package:flutter/foundation.dart'; bool isMobile([TargetPlatform? targetPlatform]) { @@ -23,3 +26,12 @@ bool isAppleOS([TargetPlatform? targetPlatform]) { TargetPlatform.iOS, }.contains(targetPlatform); } + +Future isIosSimulator() async { + if (Platform.isIOS) { + final deviceInfo = DeviceInfoPlugin(); + final iosInfo = await deviceInfo.iosInfo; + return !iosInfo.isPhysicalDevice; + } + return false; +} diff --git a/lib/src/widgets/raw_editor.dart b/lib/src/widgets/raw_editor.dart index 473eea10..d3ff570c 100644 --- a/lib/src/widgets/raw_editor.dart +++ b/lib/src/widgets/raw_editor.dart @@ -557,13 +557,20 @@ class RawEditorState extends EditorState if (isKeyboardOS()) { _keyboardVisible = true; } else { - _keyboardVisibilityController = KeyboardVisibilityController(); - _keyboardVisible = _keyboardVisibilityController!.isVisible; - _keyboardVisibilitySubscription = - _keyboardVisibilityController?.onChange.listen((visible) { - _keyboardVisible = visible; - if (visible) { - _onChangeTextEditingValue(!_hasFocus); + // treat iOS Simulator like a keyboard OS + isIosSimulator().then((isIosSimulator) { + if (isIosSimulator) { + _keyboardVisible = true; + } else { + _keyboardVisibilityController = KeyboardVisibilityController(); + _keyboardVisible = _keyboardVisibilityController!.isVisible; + _keyboardVisibilitySubscription = + _keyboardVisibilityController?.onChange.listen((visible) { + _keyboardVisible = visible; + if (visible) { + _onChangeTextEditingValue(!_hasFocus); + } + }); } }); } diff --git a/pubspec.yaml b/pubspec.yaml index 6823b7f7..1d22d9b9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -28,6 +28,7 @@ dependencies: diff_match_patch: ^0.4.1 i18n_extension: ^4.2.0 gallery_saver: ^2.3.2 + device_info_plus: ^3.2.1 dev_dependencies: flutter_test: