fix: correct super_clipboard getFile API call signature
getFile requires two positional args: format and callback. Wrapped in Completer for async/await usage. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
5f28605e13
commit
cfc0a97da7
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
|
|
@ -209,20 +210,27 @@ class _ChatPageState extends ConsumerState<ChatPage> {
|
|||
// Try PNG first, then JPEG
|
||||
for (final format in [Formats.png, Formats.jpeg]) {
|
||||
if (item.canProvide(format)) {
|
||||
final completer = item.getFile(format);
|
||||
if (completer != null) {
|
||||
final file = await completer;
|
||||
final bytes = await file.readAll();
|
||||
final mediaType = format == Formats.png ? 'image/png' : 'image/jpeg';
|
||||
setState(() {
|
||||
_pendingAttachments.add(ChatAttachment(
|
||||
base64Data: base64Encode(bytes),
|
||||
mediaType: mediaType,
|
||||
fileName: 'clipboard.${format == Formats.png ? "png" : "jpg"}',
|
||||
));
|
||||
});
|
||||
return;
|
||||
}
|
||||
final completer = Completer<List<int>>();
|
||||
item.getFile(format, (file) async {
|
||||
try {
|
||||
final bytes = await file.readAll();
|
||||
completer.complete(bytes);
|
||||
} catch (e) {
|
||||
completer.completeError(e);
|
||||
}
|
||||
}, onError: (e) {
|
||||
if (!completer.isCompleted) completer.completeError(e);
|
||||
});
|
||||
final bytes = await completer.future;
|
||||
final mediaType = format == Formats.png ? 'image/png' : 'image/jpeg';
|
||||
setState(() {
|
||||
_pendingAttachments.add(ChatAttachment(
|
||||
base64Data: base64Encode(bytes),
|
||||
mediaType: mediaType,
|
||||
fileName: 'clipboard.${format == Formats.png ? "png" : "jpg"}',
|
||||
));
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue