MixinNetwork / MixinNetwork/flutter-plugins
pasteboard.image: when system clipboard content changed, then it will crash
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 512
- Forks
- 292
- Avg merge
- 15h 8m
- Merged PRs (30d)
- 7
Description
It is OK to get the image when there is image content in the system clipboard, but when I change the content, like I make another screenshot, then I cannot get the updated image, and it will crash my app.
Please help to check and solve it.
Thanks a lot!
Below is my code which is used together with Flutter_quill
Future _handlePasteImage() async {
try {
Uint8List? imageBytes = await Pasteboard.image;
if (imageBytes == null || imageBytes.isEmpty) {
debugPrint("no valid pic");
return;
}
final decodedImage = await decodeImageFromList(imageBytes);
if (decodedImage.width <= 0 || decodedImage.height <= 0) {
debugPrint("no valid pic");
return;
}
final dir = await getApplicationDocumentsDirectory();
final fileName = 'pasted_${DateTime.now().millisecondsSinceEpoch}.png';
final file = File('${dir.path}/$fileName');
await file.writeAsBytes(imageBytes);
debugPrint("saved: ${file.path}");
final imageUrl = file.path;
final selection = Get.find<NoteViewController>().quill_controller.selection;
final index = selection.baseOffset < 0 ? 0 : selection.baseOffset;
Get.find<NoteViewController>().quill_controller.document.insert(index, BlockEmbed.image(imageUrl));
Get.find<NoteViewController>().quill_controller.updateSelection(
TextSelection.collapsed(offset: index + 1),
ChangeSource.local,
);
} catch (e, stack) {
debugPrint("error: $e");
debugPrint("$stack");
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("error")),
);
}
}
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failure through the Pasteboard.image entry point after replacing the system clipboard image with another screenshot. Inspect the plugin's clipboard image handling and verify that the updated image can be retrieved without crashing the Flutter app.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100