Description
What package does this bug report belong to?
camera
What target platforms are you seeing this bug on?
Android
Have you already upgraded your packages?
Yes
Dependency versions
Latest version of camera_android_camerax: 0.6.10
, however, the bug was first observed in 0.6.8+2
Steps to reproduce
- Run example on an Android device (in my case, Samsung Galaxy A25 5G)
- Use the front camera
- See camera preview being incorrect
Expected results
The camera preview should be mirrored like it is with default cameras apps.
Actual results
The camera preview is shown like it is recorded (from the perspective of the user, it is mirrored).
Code sample
Code sample
import 'package:camera/camera.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main() async {
runApp(const MainApp());
}
class MainApp extends StatefulWidget {
const MainApp({super.key});
@override
State<MainApp> createState() => _MainAppState();
}
class _MainAppState extends State<MainApp> {
final _runner = _Runner();
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: ValueListenableBuilder(
valueListenable: _runner,
builder: _build,
),
),
);
}
Widget _build(BuildContext context, _State value, Widget? child) {
switch (value) {
case _Loaded():
return Center(
child: CameraPreview(value.controller),
);
case _Simple.initializing:
return const Center(
child: CircularProgressIndicator(),
);
case _Simple.error:
return const Center(
child: Icon(Icons.error),
);
}
}
}
class _Runner with ChangeNotifier implements ValueListenable<_State> {
_Runner() {
_init();
}
void _init() async {
final available = await availableCameras();
if (available.isEmpty) {
_emit(_Simple.error);
} else {
final controller = CameraController(
available.firstWhere((candidate) {
return candidate.lensDirection == CameraLensDirection.front;
}, orElse: () {
return available.first;
}),
ResolutionPreset.veryHigh);
try {
await controller.initialize();
_emit(_Loaded(
controller: controller,
available: available,
));
} catch (e) {
_emit(_Simple.error);
}
}
}
_State _value = _Simple.initializing;
@override
_State get value => _value;
void _emit(_State state) {
_value = state;
notifyListeners();
}
}
sealed class _State {}
enum _Simple implements _State {
initializing,
error,
}
class _Loaded implements _State {
final CameraController controller;
final List<CameraDescription> available;
const _Loaded({
required this.controller,
required this.available,
});
}
Screenshots or Videos
No response
Logs
No response
Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.24.3, on macOS 15.0.1 24A348 darwin-arm64, locale en)
• Flutter version 3.24.3 on channel stable at /Users/User/Development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 2663184aa7 (5 weeks ago), 2024-09-11 16:27:48 -0500
• Engine revision 36335019a8
• Dart version 3.5.3
• DevTools version 2.37.3
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/User/Library/Android/sdk
• Platform android-35, build-tools 34.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 16.0)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 16A242d
• CocoaPods version 1.15.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2024.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 17.0.10+0-17.0.10b1087.21-11609105)
[✓] VS Code (version 1.95.0-insider)
• VS Code at /Applications/Visual Studio Code - Insiders.app/Contents
• Flutter extension version 3.98.0
[✓] Connected device (5 available)
• Pixel (mobile) • FA76R0301797 • android-arm64 • Android 10 (API 29)
• SM A256B (mobile) • R5CX806EZNE • android-arm64 • Android 14 (API 34)
• macOS (desktop) • macos • darwin-arm64 • macOS 15.0.1 24A348 darwin-arm64
• Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 15.0.1 24A348 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 129.0.6668.101
[✓] Network resources
• All expected network resources are available.
• No issues found!
Metadata
Metadata
Labels
High-priority issues at the top of the work listIt was better in the past than it is nowFound to occur in 3.24Found to occur in 3.27For the attention of Ecosystem teamThe issue has been confirmed reproducible and is ready to work onThe camera pluginflutter/packages repository. See also p: labels.Android applications specificallyOwned by Android platform teamTriaged by Android platform team