mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-10 21:27:14 +01:00
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1.3 KiB
1.3 KiB
data_transfer_flutter
Shared "export to a JSON file / import from a JSON file" plumbing for kuhy's Flutter apps. Apps keep their own export CONTENT; this owns the file plumbing and the envelope.
Install
dependencies:
data_transfer_flutter:
git:
url: https://github.com/kuhyx/utils
ref: data_transfer_flutter-v0.2.1
path: data_transfer_flutter
Use
final saved = await exportJson(fileName: 'x.json', json: envelope);
final map = await pickJson(); // null when cancelled
exportJson/exportJsonTextsave to device storage: Android and iOS use the system "Save as" document picker (file_pickersaveFile, i.e. ACTION_CREATE_DOCUMENT), desktop a save dialog (file_selector), web a browser download. Returns false when cancelled.exportTextFiledoes the same for any text (text/csv,text/calendar).shareJsonis an optional second action (share sheet). It is never the only way out: a stock phone's share sheet has no local save target.pickJson/pickJsonTextuse the system open-document picker.buildEnvelope/validateEnvelope/parseEnvelopewrite and check{format, version, exported_at, ...}; mismatches throw a typedEnvelopeException(always aFormatException).
Tests fake DataTransfer.platform (a DataTransferPlatform); restore it in
tearDown.