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
The code below works perfectly on a physical android device and the iOS simulator, however when running on a physical iPhone, it captures the striped image seen below which is also stretched vertically (screenshot is a rectangle, not a square) instead of the plain square purple container that is rendered on-screen.
Device: iPhone 13 mini
iOS Version: 17.5.1
Screenshot captured
Visible on the iPhone
import'dart:io';
import'dart:typed_data';
import'package:flutter/material.dart';
import'package:path_provider/path_provider.dart';
import'package:screenshot/screenshot.dart';
import'package:share_plus/share_plus.dart';
classPurpleSquarePageextendsStatelessWidget {
PurpleSquarePage({super.key});
finalScreenshotController screenshotController =ScreenshotController();
voidcaptureAndShare(pixelRatio) async {
debugPrint('In captureAndShare');
try {
debugPrint('Starting delay');
awaitFuture.delayed(constDuration(milliseconds:1000));
debugPrint('Ending delay');
debugPrint('pixelRatio: $pixelRatio');
// Capture a screenshot with the given pixel ratio and a delayUint8List? image =await screenshotController.capture(
// pixelRatio: pixelRatio,
delay:constDuration(milliseconds:3000),
);
// Log the captured image's outputdebugPrint(image.toString()); // <--- This is where the strange output is displayed// Check if the captured image is not nullif (image !=null) {
// Get the application's document directoryfinal directory =awaitgetApplicationDocumentsDirectory();
// Create a new file in the directory for storing the imagefinal imagePath =awaitFile('${directory.path}/image.png').create();
// Write the captured image bytes to the fileawait imagePath.writeAsBytes(image);
// Use the Share Plugin to share the image filefinal result =awaitShare.shareXFiles(
[XFile(imagePath.path)]
);
// Log the sharing resultdebugPrint('Share result: ${result.toString()}');
}
} catch (e) {
debugPrint('Error capturing and sharing screenshot: $e');
}
}
@overrideWidgetbuild(BuildContext context) {
finaldouble pixelRatio =MediaQuery.of(context).devicePixelRatio;
returnScaffold(
body:Screenshot(
controller: screenshotController,
child:Container(
width:200.0,
height:200.0,
color:Colors.purple,
),
),
floatingActionButton:FloatingActionButton(
onPressed: () =>captureAndShare(pixelRatio),
child:constIcon(Icons.add)
)
);
}
}
The text was updated successfully, but these errors were encountered:
The code below works perfectly on a physical android device and the iOS simulator, however when running on a physical iPhone, it captures the striped image seen below which is also stretched vertically (screenshot is a rectangle, not a square) instead of the plain square purple container that is rendered on-screen.
Device: iPhone 13 mini
iOS Version: 17.5.1
Screenshot captured
Visible on the iPhone
The text was updated successfully, but these errors were encountered: