Even after the second view controller was presentViewController'ed, the FlutterViewController still passes events to Flutter.
I have fixed with similar problems in the past. When displaying iOS native ViewController, taps on the edge were passed to the back Flutter.
I did not run the example, so if it is another problem, please ignore this comment.
[✓] Flutter (Channel master, 1.21.0-6.0.pre.117, on Mac OS X 10.15.6 19G73, locale en-GB)
• Flutter version 1.21.0-6.0.pre.117 at /Users/nevercode/dev/flutter
• Framework revision 7ec2d360bc (2 hours ago), 2020-07-29 23:25:38 -0700
• Engine revision a9910e409c
• Dart version 2.10.0 (build 2.10.0-1.0.dev 24c7666def)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at /Users/nevercode/Library/Android/sdk
• Platform android-29, build-tools 29.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.6)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.6, Build version 11E708
• CocoaPods version 1.9.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 4.0)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 47.1.2
• Dart plugin version 193.7361
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
[✓] VS Code (version 1.47.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.12.2
[✓] Connected device (6 available)
• Redmi Note 7 (mobile) • 6345c469 • android-arm64 • Android 9 (API 28)
• Nevercode’s iPhone (mobile) • b668e524315069f3db3661ac11ff1f66afafebdb • ios • iOS 13.6
• iPhone 11 Pro Max (mobile) • 55C8466B-5367-492B-8EFE-EC45D980571F • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-6 (simulator)
• macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.6 19G73
• Web Server (web) • web-server • web-javascript • Flutter Tools
• Chrome (web) • chrome • web-javascript • Google Chrome 84.0.4147.105
• No issues found!
#62310 - another example project
#35784 (comment) - workaround
[image_picker] On iOS, camera overlay is clickable through, user can interact with widgets behind the overlay
#28335
I did some investigation for #28335 by creating a native app that shows the camera. When the camera viewcontroller is shown, the iOS buttons are not clickable anymore, but touchesBegan
is actually being called: https://github.com/renefloor/ios_camera_overlay_test/blob/main/cameratest/ViewController.m#L57-L63.
Why this is and how to possibly work around it is very well explained in this (closed) issue: #35784 (comment).
My proposal (with help from @Kavantix) would be to only use the touches when there is no presentedViewController, but I'm not sure if that would break anything existing.
https://github.com/flutter/engine/blob/master/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm#L934-L953
For example:
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
if(self.presentedViewController == nil){
[self dispatchTouches:touches pointerDataChangeOverride:nullptr];
}else{
[super touchesBegan:touches withEvent:event];
@renefloor's suggestion looks similar in concept to flutter/engine#18544 (though I think isPresentingViewController
instead of self.presentedViewController
check? Would have to play with animations). @gaaclarke Can you think of any issues off the top of your head that would arise from not processing touches if isPresentingViewController
is false?
@jmagman I'd have to play around with it but I'd check what happens when a UIView is placed on top of the FlutterView without a UIViewController, that might still be an issue. You'd have to make sure to do this logic for all of the touches methods obviously.
An alternative would be to use something like an UIAdaptivePresentationControllerDelegate
that sets UIView.userInteractionEnabled
. I think something like UIView.userInteractionEnabled
is more robust than fiddling with the touches methods. It's also something users can do without modifying the code of the engine.
I guess Apple didn't disable touch events for presenting view controllers because under certain circumstances they can still be partially visible? It might be better if users set UIView.userInteractionEnabled
on their own.
@gaaclarke if a UIView is placed on top the next responder shouldn’t be the FlutterViewController right?
But setting userInteractionEnabled to false could work, perhaps we could set that in viewDidDisappear
?
In my case the click throughs are happening in the lower right corner on top of a CupertinoTabBar... which causes the underlying Flutter app's navigation state to change.
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.1, on macOS 12.4 21F79 darwin-x64, locale en-CA)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] VS Code (version 1.68.1)
[✓] Connected device (3 available)
[✓] HTTP Host Availability
[Image_Picker] Exception after taping in blank space between Cancel and Shutter button on iOS
#110325
darkTheme: ThemeData.dark(),
themeMode: ThemeMode.system,
home: const MyHomePage(title: 'Image Picker Sample'),
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
class _MyHomePageState extends State<MyHomePage> {
File? _image;
final picker = ImagePicker();
Future getImage() async {
final pickedFile = await picker.pickImage(source: ImageSource.camera);
setState(() {
if (pickedFile != null) {
_image = File(pickedFile.path);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Image Picker Sample'),
body: Center(
child: _image == null
? const Text('No image selected.')
: Image.file(_image!),
floatingActionButton: FloatingActionButton(
onPressed: getImage,
child: const Icon(Icons.add_a_photo),
flutter doctor -v
[✓] Flutter (Channel stable, 3.7.5, on macOS 13.2.1 22D68 darwin-arm64, locale en-GB)
• Flutter version 3.7.5 on channel stable at /Users/nexus/dev/sdks/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision c07f788888 (6 days ago), 2023-02-22 17:52:33 -0600
• Engine revision 0f359063c4
• Dart version 2.19.2
• DevTools version 2.20.1
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at /Users/nexus/Library/Android/sdk
• Platform android-33, build-tools 33.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14C18
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[!] Android Studio (version 2022.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
✗ Unable to find bundled Java version.
• Try updating or re-installing Android Studio.
[!] Android Studio (version 2022.1)
• Android Studio at /Users/nexus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/221.6008.13.2211.9477386/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
✗ Unable to find bundled Java version.
• Try updating or re-installing Android Studio.
[✓] IntelliJ IDEA Community Edition (version 2022.3.2)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• 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
[✓] VS Code (version 1.75.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.58.0
[✓] Connected device (3 available)
• Nexus (mobile) • 00008020-001875E83A38002E • ios • iOS 16.3.1 20D67
• macOS (desktop) • macos • darwin-arm64 • macOS 13.2.1 22D68 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 110.0.5481.177
[✓] HTTP Host Availability
• All required HTTP hosts are available
! Doctor found issues in 2 categories.
[!] Flutter (Channel master, 3.8.0-17.0.pre.38, on macOS 13.2.1 22D68 darwin-arm64, locale en-GB)
• Flutter version 3.8.0-17.0.pre.38 on channel master at /Users/nexus/dev/sdks/flutters
! Warning: `flutter` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
! Warning: `dart` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 1d17caed66 (9 hours ago), 2023-02-27 23:11:38 -0500
• Engine revision 002b3d7a24
• Dart version 3.0.0 (build 3.0.0-277.0.dev)
• DevTools version 2.22.1
• If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at /Users/nexus/Library/Android/sdk
• Platform android-33, build-tools 33.0.0
• Java binary at: /Users/nexus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/221.6008.13.2211.9477386/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14C18
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2022.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.15+0-b2043.56-8887301)
[✓] Android Studio (version 2022.1)
• Android Studio at /Users/nexus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/221.6008.13.2211.9477386/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.15+0-b2043.56-8887301)
[✓] IntelliJ IDEA Community Edition (version 2022.3.2)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• 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
[✓] VS Code (version 1.75.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.58.0
[✓] Connected device (3 available)
• Nexus (mobile) • 00008020-001875E83A38002E • ios • iOS 16.3.1 20D67
• macOS (desktop) • macos • darwin-arm64 • macOS 13.2.1 22D68 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 110.0.5481.177
[✓] Network resources
• All expected network resources are available.
! Doctor found issues in 1 category.
Hi all, I am facing the same problem, however, it is complicated by the fact that my application presents a native View Controller that allows you to select a file. When closing a file, if the click was in the place where Flutter is listening to the Gesture Detector, the application crashes with an error
io.flutter.1.raster (10): "Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread."
flutter doctor -v
[✓] Flutter (Channel beta, 3.13.0-0.4.pre, on macOS 13.4.1 22F770820d darwin-arm64, locale ru-GE)
• Flutter version 3.13.0-0.4.pre on channel beta at /Users/jwo1f/development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 7e07cd4 (10 дней назад), 2023-08-08 21:20:03 -0700
• Engine revision 73d89ca7c5
• Dart version 3.1.0 (build 3.1.0-262.3.beta)
• DevTools version 2.25.0
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/jwo1f/Library/Android/sdk
✗ cmdline-tools component is missing
Run path/to/sdkmanager --install "cmdline-tools;latest"
See https://developer.android.com/studio/command-line for more details.
✗ Android license status unknown.
Run flutter doctor --android-licenses
to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14E300c
• CocoaPods version 1.12.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[!] Android Studio (version unknown)
• Android Studio at /Users/jwo1f/Applications/Android Studio Hedgehog 2023.1.1 Canary 15.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
✗ Unable to determine Android Studio version.
• Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
[✓] Android Studio (version 2022.3)
• Android Studio at /Users/jwo1f/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 17.0.6+0-17.0.6b829.9-10027231)
[✓] VS Code (version 1.81.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension can be installed from:
🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
@GabrielAraujo
When using thrid-party-libs like image_picker you can use this workaround. The overlay created just before the camera ui controller is opened swallows all touch events during the process. After that the overlay is removed.
void _onTakeCameraPhoto(BuildContext context) async {
//create a whole overlay to absorb touches when the camera ui is open
final entry = OverlayEntry(
builder: (context) => const AbsorbPointer(
child: SizedBox.expand(),
Overlay.of(context).insert(entry);
try {
final picker = ImagePicker();
final XFile? file = await picker.pickImage(source: ImageSource.camera);
if (context.mounted) {
//do something with the file
} catch (e, s) {
//error handling
} finally {
//always remove the entry
entry.remove();
Also facing this issue when using the camera from image_picker
plugin
i made a plugin to fix this case
https://pub.dev/packages/simple_picker
hope you're fun !!
[image_picker] throw PlatformException(already_active, Image picker is already active, null, null) when pick photo from gallery
#156385