-
Notifications
You must be signed in to change notification settings - Fork 29k
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: platform-viewsEmbedding Android/iOS views in Flutter appsEmbedding Android/iOS views in Flutter appsengineflutter/engine repository. See also e: labels.flutter/engine repository. See also e: labels.found in release: 2.10Found to occur in 2.10Found to occur in 2.10found in release: 2.13Found to occur in 2.13Found to occur in 2.13found in release: 3.1Found to occur in 3.1Found to occur in 3.1has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onteam-engineOwned by Engine teamOwned by Engine teamtriaged-engineTriaged by Engine teamTriaged by Engine team
Description
Steps to Reproduce
- Execute
flutter run
on the code sample - Press icon button to take screenshot from camera preview.
Expected results: Screenshot should contain camera preview picture.
Actual results: Screenshot doesn't include camera view.
I tested it on Samsung S9, Samsung S20 using Flutter 2.10.5 and 2.13.0-0.2.pre.
Same issue happen on iOS, tested on iPhone 12 Pro Max, iOS 15.2.1, Flutter 2.10.5.
I'm aware of existing issues like #25306 which all point to resolved #83856 (comment).
However I can't confirm that this feature works.
Code sample
import 'dart:typed_data';
import 'dart:ui';
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
final cameras = await availableCameras();
final firstCamera = cameras.first;
runApp(
MaterialApp(
theme: ThemeData.dark(),
home: TakePictureScreen(
camera: firstCamera,
),
),
);
}
//
class TakePictureScreen extends StatefulWidget {
const TakePictureScreen({
Key? key,
required this.camera,
}) : super(key: key);
final CameraDescription camera;
@override
TakePictureScreenState createState() => TakePictureScreenState();
}
class TakePictureScreenState extends State<TakePictureScreen> {
static GlobalKey boundaryKey = GlobalKey();
late CameraController _controller;
late Future<void> _initializeControllerFuture;
@override
void initState() {
super.initState();
_controller = CameraController(
widget.camera,
ResolutionPreset.veryHigh,
);
_initializeControllerFuture = _controller.initialize();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return RepaintBoundary(
key: boundaryKey,
child: Scaffold(
appBar: AppBar(title: const Text('Take a Screenshot')),
body: FutureBuilder<void>(
future: _initializeControllerFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return CameraPreview(_controller);
} else {
return const Center(child: CircularProgressIndicator());
}
},
),
floatingActionButton: FloatingActionButton(
onPressed: () async {
await _initializeControllerFuture;
RenderRepaintBoundary? boundary =
boundaryKey.currentContext!.findRenderObject() as RenderRepaintBoundary?;
var image = await boundary!.toImage();
var byteData = await image.toByteData(format: ImageByteFormat.png);
var pngBytes = byteData!.buffer.asUint8List();
await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => DisplayPictureScreen(
imageData: pngBytes,
),
),
);
},
child: const Icon(Icons.camera_alt),
),
));
}
}
//
class DisplayPictureScreen extends StatelessWidget {
final Uint8List imageData;
const DisplayPictureScreen({Key? key, required this.imageData}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Display the Picture')),
body: Image.memory(imageData),
);
}
}
pubspec.yaml
name: screenshot_test
description: A new Flutter project.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
camera: ^0.9.4+21
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
flutter:
uses-material-design: true
flutter doctor -v
[√] Flutter (Channel beta, 2.13.0-0.2.pre, on Microsoft Windows [Version 10.0.19042.1288], locale ru-RU)
• Flutter version 2.13.0-0.2.pre at e:\Programs\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 8662e22bac (10 days ago), 2022-04-20 08:21:52 -0700
• Engine revision 24a02fa5ee
• Dart version 2.17.0 (build 2.17.0-266.5.beta)
• DevTools version 2.12.2
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at C:\Users\Alexey\AppData\Local\Android\sdk
• Platform android-31, build-tools 30.0.3
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822)
• 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 (Visual Studio Build Tools 2019 16.5.5)
• Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools
• Visual Studio Build Tools 2019 version 16.5.30104.148
• Windows 10 SDK version 10.0.18362.0
[√] Android Studio (version 2021.1)
• 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.11+9-b60-7590822)
[√] VS Code (version 1.64.2)
• VS Code at C:\Users\Alexey\AppData\Local\Programs\Microsoft VS Code
• Flutter extension can be installed from:
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[√] Connected device (3 available)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19042.1288]
• Chrome (web) • chrome • web-javascript • Google Chrome 100.0.4896.127
• Edge (web) • edge • web-javascript • Microsoft Edge 87.0.664.66
[√] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
D:\Work\Cars\Tests\Flutter\screenshot_test>flutter doctor -v
[√] Flutter (Channel beta, 2.13.0-0.2.pre, on Microsoft Windows [Version 10.0.19042.1288], locale ru-RU)
• Flutter version 2.13.0-0.2.pre at e:\Programs\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 8662e22bac (10 days ago), 2022-04-20 08:21:52 -0700
• Engine revision 24a02fa5ee
• Dart version 2.17.0 (build 2.17.0-266.5.beta)
• DevTools version 2.12.2
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at C:\Users\Alexey\AppData\Local\Android\sdk
• Platform android-31, build-tools 30.0.3
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822)
• 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 (Visual Studio Build Tools 2019 16.5.5)
• Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools
• Visual Studio Build Tools 2019 version 16.5.30104.148
• Windows 10 SDK version 10.0.18362.0
[√] Android Studio (version 2021.1)
• 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.11+9-b60-7590822)
[√] VS Code (version 1.64.2)
• VS Code at C:\Users\Alexey\AppData\Local\Programs\Microsoft VS Code
• Flutter extension can be installed from:
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[√] Connected device (3 available)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19042.1288]
• Chrome (web) • chrome • web-javascript • Google Chrome 100.0.4896.127
• Edge (web) • edge • web-javascript • Microsoft Edge 87.0.664.66
[√] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
zenkog, iapicca, araisann, orestesgaolin, Szugalew and 21 more
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: platform-viewsEmbedding Android/iOS views in Flutter appsEmbedding Android/iOS views in Flutter appsengineflutter/engine repository. See also e: labels.flutter/engine repository. See also e: labels.found in release: 2.10Found to occur in 2.10Found to occur in 2.10found in release: 2.13Found to occur in 2.13Found to occur in 2.13found in release: 3.1Found to occur in 3.1Found to occur in 3.1has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onteam-engineOwned by Engine teamOwned by Engine teamtriaged-engineTriaged by Engine teamTriaged by Engine team