You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[camera_android_camerax] takePicture sets an unchanged flash mode on every capture #195468
P1High-priority issues at the top of the work listc: performanceRelates to speed or footprint issues (see "perf:" labels)p: cameraThe camera pluginpackageflutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyteam-androidOwned by Android platform teamtriaged-androidTriaged by Android platform team
Once an app calls setFlashMode, every takePicture() sets the same flash mode on ImageCapture again, which adds roughly 250-300 ms to each capture. This happens
even when the mode is FlashMode.off and never changes.
Steps to reproduce
Create a camera with ResolutionPreset.high.
Call setFlashMode(FlashMode.off).
Call takePicture() repeatedly and measure the latency.
Results
ZSL off
ZSL on
setFlashMode never called
517 ms
360 ms
setFlashMode(FlashMode.off) called once
794 ms
656 ms
Galaxy S21 (SM-G991N), camera_android_camerax 0.7.6, CameraX 1.6.2. Each value is
the median of 12 shots, after 2 warm-up shots, 600 ms apart. "ZSL on" means setZeroShutterLagEnabled(true).
Why
takePicture calls ImageCapture.setFlashMode before every capture whenever a
flash mode has been set (since flutter/packages#3800). CameraX keeps the flash mode
on the ImageCapture instance for subsequent captures, so the repeated call does not
change anything. In CameraX 1.6.2, ImageCapture.setFlashMode has no check for an
unchanged mode, so each call still goes through CameraControl.setFlashMode. (The
androidx-main source has since added that check.)
Proposed fix
Only call ImageCapture.setFlashMode in takePicture when the mode differs from the
one last applied to the current ImageCapture instance. The torch behavior from flutter/packages#4903 (clearing a previous flash mode when torch is enabled) stays
the same.
A new app (flutter create) with camera: ^0.12.2 added and this lib/main.dart. It needs the camera permission. Tap the button; it prints the median takePicture() latency with ResolutionPreset.high, without and with a setFlashMode(FlashMode.off) call.
import'package:camera/camera.dart';
import'package:flutter/material.dart';
voidmain() =>runApp(constMaterialApp(home:FlashModePage()));
/// Median `takePicture()` latency in ms over [shots] captures, after 2 warm-up/// captures.Future<int> measure(CameraController controller, {int shots =12}) async {
final ms =<int>[];
for (var i =0; i < shots +2; i++) {
final sw =Stopwatch()..start();
await controller.takePicture();
sw.stop();
if (i >=2) {
ms.add(sw.elapsedMilliseconds);
}
awaitFuture<void>.delayed(constDuration(milliseconds:600));
}
ms.sort();
return ms[ms.length ~/2];
}
Future<String> runComparison() async {
finalCameraDescription back = (awaitavailableCameras()).firstWhere(
(CameraDescription c) => c.lensDirection ==CameraLensDirection.back,
);
final lines =<String>[];
for (final setFlashOff in<bool>[false, true]) {
final controller =CameraController(back, ResolutionPreset.high, enableAudio:false);
await controller.initialize();
if (setFlashOff) {
await controller.setFlashMode(FlashMode.off);
}
awaitFuture<void>.delayed(constDuration(seconds:2));
finalint median =awaitmeasure(controller);
await controller.dispose();
lines.add('setFlashMode(off) called: $setFlashOff -> $median ms');
}
return lines.join('\n');
}
classFlashModePageextendsStatefulWidget {
constFlashModePage({super.key});
@overrideState<FlashModePage> createState() =>_FlashModePageState();
}
class_FlashModePageStateextendsState<FlashModePage> {
String _result ='Tap the button to run.';
bool _running =false;
Future<void> _run() async {
setState(() => _running =true);
finalString result =awaitrunComparison();
debugPrint(result);
setState(() {
_result = result;
_running =false;
});
}
@overrideWidgetbuild(BuildContext context) {
returnScaffold(
appBar:AppBar(title:constText('setFlashMode and takePicture latency')),
body:Padding(padding:constEdgeInsets.all(16), child:Text(_result)),
floatingActionButton:FloatingActionButton(
onPressed: _running ?null: _run,
child: _running ?constCircularProgressIndicator() :constIcon(Icons.play_arrow),
),
);
}
}
Output on the Galaxy S21:
setFlashMode(off) called: false -> 522 ms
setFlashMode(off) called: true -> 811 ms
Calling setFlashMode(FlashMode.off) once adds about 290 ms to every capture, even though the mode never changes.
flutter doctor -v
[✓] Flutter (Channel stable, 3.44.1, on macOS 26.6.2 25G83 darwin-arm64, locale ko-KR) [1,000ms]
• Flutter version 3.44.1 on channel stable at /Users/paul/projects/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 924134a44c (5달 전), 2026-05-29 12:13:22 -0400
• Engine revision c416acfeb8
• Dart version 3.12.1
• DevTools version 2.57.0
• Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration
[!] Android toolchain - develop for Android devices (Android SDK version 37.0.0) [3.7s]
• Android SDK at /Users/paul/Library/Android/sdk
• Emulator version 37.1.11.0 (build_id 15917651) (CL:N/A)
• Platform android-37.0, build-tools 37.0.0
• ANDROID_HOME = /Users/paul/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
This is the JDK bundled with the latest Android Studio installation on this machine.
To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
• Java version OpenJDK Runtime Environment (build 21.0.7+-13880790-b1038.58)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 26.2) [2.4s]
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 17C52
• CocoaPods version 1.16.2
[✓] Chrome - develop for the web [11ms]
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Connected device (4 available) [14.3s]
• SM G991N (mobile) • <redacted> • android-arm64 • Android 15 (API 35)
• iPhone (mobile) • <redacted> • ios • iOS 27.0.1 24A446
• macOS (desktop) • macos • darwin-arm64 • macOS 26.6.2 25G83 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 156.0.8078.48
[✓] Network resources [532ms]
• All expected network resources are available.
! Doctor found issues in 1 category.
P1High-priority issues at the top of the work listc: performanceRelates to speed or footprint issues (see "perf:" labels)p: cameraThe camera pluginpackageflutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyteam-androidOwned by Android platform teamtriaged-androidTriaged by Android platform team
Activity
toyaji commentedon Oct 28, 2026
Fix: flutter/packages#13468
saurabh-mirajkar commentedon Oct 28, 2026
@toyaji Thanks for the report. Could you please provide :
main.dartfileflutter doctor -vtoyaji commentedon Oct 28, 2026
@saurabh-mirajkar Thanks for looking at this. Here is the requested information.
Device: Galaxy S21 (SM-G991N), Android 15 (API 35).
Packages: camera 0.12.2, camera_android_camerax 0.7.6.
Minimal reproducible example
A new app (
flutter create) withcamera: ^0.12.2added and thislib/main.dart. It needs the camera permission. Tap the button; it prints the mediantakePicture()latency withResolutionPreset.high, without and with asetFlashMode(FlashMode.off)call.Output on the Galaxy S21:
Calling
setFlashMode(FlashMode.off)once adds about 290 ms to every capture, even though the mode never changes.flutter doctor -vmbcorona commentedon Oct 28, 2026
Hi @toyaji, thanks for sharing the clean code sample that reproduces the issue.
Confirmed in source: takePicture re-applies _currentFlashMode on every shot with no check for whether it changed.
https://github.com/flutter/packages/blob/10a178cb16d4a05c18b594ab13a99c87e9081b54/packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart#L1022-L1031
Routing to team-android. Fix is up in 13468
[camera_android_camerax] Only set the ImageCapture flash mode when it…