我不确定该屏幕来自哪里。但您可以尝试使用 file_picker_writable 插件。 (无耻的插头)。
Future<void> _openFilePickerForCreate() async {
final rand = Random().nextInt(10000000);
final fileInfo = await FilePickerWritable().openFileForCreate(
fileName: 'newfile.$rand.codeux',
writer: (file) async {
final content = 'File created at ${DateTime.now()}\n\n';
await file.writeAsString(content);
},
);
if (fileInfo == null) {
_logger.info('User canceled.');
return;
}
final data = await _appDataBloc.store.load();
await _appDataBloc.store
.save(data.copyWith(files: data.files + [fileInfo]));
}
}
这将为用户打开一个文件夹选择器对话框和默认文件名(由
fileName
给出)。
此代码示例将打开以下对话框:
我不确定您是否已解决此问题,但我遇到了类似的问题,我的解决方案如下
class PdfPreviewPageProd extends StatelessWidget {
final ProdutoData produto;
final List<ItensProdutoData> itens;
const PdfPreviewPageProd(
{Key? key, required this.produto, required this.itens})
: super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Ficha Técnica de produto'),
),
body: PdfPreview(
pdfFileName: produto.prodNome,//<- this is the sugested file name
build: (context) => pdfFichaTecnicaProd(produto, itens),
),
);
}
}