I am programming an app for iOS and Android in Flutter that must use the camera to automatically capture images every second. I have to create a screen in portarit orientation that shows the preview of what I want to photograph and that preview must fit the width of the screen. However, I am unable to get it to work correctly on iOS as the CameraPreview doesn't display all the visual information that it should. On Android, however, everything looks fine. Below I attach two images that show the problem. On the left is the image that I get in flutter on iOS, while on the right is the one that should appear.
I have done the tests in an iPad mini 4.
Thanks
Steps to Reproduce
Execute flutter run on the code sample on iPad mini
Actual results (left) vs Expected result (right)
Code sample
```dart
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
List cameras = [];
Future main() async {
// Fetch the available cameras before initializing the app.
try {
WidgetsFlutterBinding.ensureInitialized();
cameras = await availableCameras();
} on CameraException catch (e) {
print('Error in fetching the cameras: $e');
}
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
debugShowCheckedModeBanner: false,
home: TakePictureScreenG(
camera: cameras.first,
),
);
}
}
class TakePictureScreenG extends StatefulWidget {
const TakePictureScreenG({Key? key, required this.camera}) : super(key: key);
final CameraDescription camera;
@override
TakePictureScreenGState createState() => TakePictureScreenGState();
}
class TakePictureScreenGState extends State {
late CameraController _controller;
late Future _initializeControllerFuture;
final num resWPreset = 2160;
final num resHPreset = 3840;
final ResolutionPreset resolutionPreset = ResolutionPreset.ultraHigh;
@override
void initState() {
super.initState();
_controller = CameraController(widget.camera, resolutionPreset);
_initializeControllerFuture = _controller.initialize();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(children: [
_buildCamera(),
]),
);
}
Widget _buildCamera() {
return FutureBuilder(
future: _initializeControllerFuture,
builder: (context, snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Spacer(),
Text("LOADING CAMERA"),
CircularProgressIndicator(),
Spacer()
],
),
);
}
var sizeWScreen = MediaQuery.of(context).size.width;
return Container(
width: sizeWScreen,
height: resHPreset * sizeWScreen / resWPreset,
child: CameraPreview(_controller),
);
},
);
}
}
```
[√] Flutter (Channel stable, 3.0.1, on Microsoft Windows [Versi¢n 10.0.19044.1706], locale es-ES)
• Flutter version 3.0.1 at D:\android-sdk-flutter\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision fb57da5f94 (7 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 32.0.0)
• Android SDK at D:\android-sdk-as
• Platform android-32, build-tools 32.0.0
• ANDROID_HOME = D:\android-sdk-as
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
• 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 (the doctor check crashed)
X Due to an error, the doctor check did not complete.
[√] Android Studio (version 2021.2)
• 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.12+7-b1504.28-7817840)
[√] VS Code (version 1.62.1)
• VS Code at C:\Users\angel\AppData\Local\Programs\Microsoft VS Code
• Flutter extension can be installed from:
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
Hello,
I am programming an app for iOS and Android in Flutter that must use the camera to automatically capture images every second. I have to create a screen in portarit orientation that shows the preview of what I want to photograph and that preview must fit the width of the screen. However, I am unable to get it to work correctly on iOS as the CameraPreview doesn't display all the visual information that it should. On Android, however, everything looks fine. Below I attach two images that show the problem. On the left is the image that I get in flutter on iOS, while on the right is the one that should appear.
I have done the tests in an iPad mini 4.
Thanks
Steps to Reproduce
flutter run
on the code sample on iPad miniActual results (left) vs Expected result (right)
Code sample
```dart import 'package:camera/camera.dart'; import 'package:flutter/material.dart'; List