Closed
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!
Metadata
Metadata
Assignees
Labels
Important issues not at the top of the work listEmbedding Android/iOS views in Flutter appsflutter/engine repository. See also e: labels.Found to occur in 2.10Found to occur in 2.13Found to occur in 3.1The issue has been confirmed reproducible and is ready to work onOwned by Engine teamTriaged by Engine team
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
maheshj01 commentedon May 2, 2022
Hi @xlyashuk, Thanks for filing the issue. I am able to reproduce the issue on stable and the master channel. On Taking the screenshot error is thrown and a blank image is displayed. The Screenshot can be taken without the CameraPreview (Platformview).
A reproducible code sample can be found in the original post.
flutter doctor -v (mac)
logs
Duplicate of #83856 (closed)
cc: @blasten
[-]RepaintBoundary screenshot for platform-views still doesn't work[/-][+][RepaintBoundary] Screenshot of Platform Views cannot be taken[/+][-][RepaintBoundary] Screenshot of Platform Views cannot be taken[/-][+][RepaintBoundary]Cannot take Screenshot of Platform Views[/+]zenkog commentedon May 5, 2022
I also have the same problem. But in my case, I must take a screenshot of the
PlatformView
widget.So, is there a solution for this yet?
araisann commentedon May 6, 2022
chinmaygarde commentedon May 9, 2022
I don't think Flutter can take a screenshot of platform provided textures today. Especially if those textures are from protected sources. I believe the linked issue was for tests. cc @blasten to confirm.
12 remaining items
TheGlorySaint commentedon Aug 23, 2023
Hey Flutter-Team,
is there any update on this issue?
njovy commentedon Mar 10, 2024
It still hasn't been fixed yet after 2 years.
Trung15010802 commentedon May 6, 2024
Does anyone have solution?
ycv005 commentedon Jun 22, 2024
There is workaround available here - https://pub.dev/packages/ff_native_screenshot
AbhijithKonnayil commentedon Jun 22, 2024
@ycv005 will it take the full screenshot or can we take capture only a the widgets we need
stefanschaller commentedon Jul 22, 2024
Any workaround how I could combine the https://pub.dev/packages/ff_native_screenshot with some flutter widget screenshot from the
RepaintBoundary
?I might also need web support. Any idea?
msxenon commentedon Aug 19, 2024
isn't it doable?
jonahwilliams commentedon Sep 8, 2024
Closing this issue, because this is as-designed in the compositor.
github-actions commentedon Sep 23, 2024
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -v
and a minimal reproduction of the issue.