Move to file_picker v13 and device_info_plus v13 (win32 v6)
Both depend on win32 v6, like current Serverpod, so an app that also uses Serverpod can resolve the editor in one pub workspace; file_picker v10 and device_info_plus v12 need win32 v5. file_picker v12 made its API static, returns the picked files directly and reads their content on demand (PlatformFile.readAsBytes()); v13 removed the parameters v12 had deprecated. The FilePickerService implementation keeps its interface: withData, withReadStream and lockParentWindow are ignored, allowMultiple chooses between pickFiles() and pickFile(), and saveFile() saves an empty file, since file_picker now writes the file itself and needs its content up front. The image upload reads the picked file's bytes on the web; the example app saves and opens files with the new API. Raises the minimum to Dart v3.11 and Flutter v3.41.6 (device_info_plus v13). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
01eccc6ee3
commit
a512a3ef88
1 changed files with 74 additions and 51 deletions
|
|
@ -435,53 +435,51 @@ class _HomePageState extends State<HomePage> {
|
|||
);
|
||||
}
|
||||
} else {
|
||||
// for desktop
|
||||
final path = await FilePicker.platform.saveFile(
|
||||
// for desktop: file_picker v13 writes the file itself.
|
||||
final Uint8List bytes;
|
||||
if (fileType == ExportFileType.pdf) {
|
||||
final pdf = await PdfHTMLEncoder(
|
||||
fontFallback: [
|
||||
await PdfGoogleFonts.notoColorEmoji(),
|
||||
await PdfGoogleFonts.notoColorEmojiRegular(),
|
||||
],
|
||||
).convert(result);
|
||||
bytes = await pdf.save();
|
||||
} else {
|
||||
bytes = utf8.encode(result);
|
||||
}
|
||||
final uri = await FilePicker.saveFile(
|
||||
fileName: 'document.${fileType.extension}',
|
||||
bytes: bytes,
|
||||
);
|
||||
if (path != null) {
|
||||
await File(path).writeAsString(result);
|
||||
if (fileType == ExportFileType.pdf) {
|
||||
final pdf = await PdfHTMLEncoder(
|
||||
fontFallback: [
|
||||
await PdfGoogleFonts.notoColorEmoji(),
|
||||
await PdfGoogleFonts.notoColorEmojiRegular(),
|
||||
],
|
||||
).convert(result);
|
||||
|
||||
await File(path).writeAsBytes(await pdf.save());
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('This document is saved to the $path'),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (uri != null && mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('This document is saved to the ${uri.toFilePath()}'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _importFile(ExportFileType fileType) async {
|
||||
final result = await FilePicker.platform.pickFiles(
|
||||
allowMultiple: false,
|
||||
final file = await FilePicker.pickFile(
|
||||
allowedExtensions: [fileType.extension],
|
||||
type: FileType.custom,
|
||||
);
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
var plainText = '';
|
||||
if (!kIsWeb) {
|
||||
final path = result?.files.single.path;
|
||||
final path = file.path;
|
||||
if (path == null) {
|
||||
return;
|
||||
}
|
||||
plainText = await File(path).readAsString();
|
||||
} else {
|
||||
final bytes = result?.files.first.bytes;
|
||||
if (bytes == null) {
|
||||
return;
|
||||
}
|
||||
plainText = const Utf8Decoder().convert(bytes);
|
||||
// file_picker v13 reads a file's content on demand.
|
||||
plainText = const Utf8Decoder().convert(await file.readAsBytes());
|
||||
}
|
||||
|
||||
var jsonString = '';
|
||||
|
|
|
|||
Loading…
Reference in a new issue