MixinNetwork / MixinNetwork/flutter-plugins

pasteboard.image: when system clipboard content changed, then it will crash

Open
#414 0 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.