feat(app): экраны импорта отчётов, целей, доходов, ребалансировки, налогов и бенчмарков
Импорт (/imports, /instruments/pending) и фаза 4 (/goals, /income, /rebalance, /tax, аналитика-хаб с benchmarks_card) — по docs/ai/import-contract.md и docs/ai/phase4-contract.md. file_picker для загрузки отчёта.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'imports_api.dart';
|
||||
|
||||
/// Picking a report is the one part of the import screen that touches the platform, so it
|
||||
/// sits behind this one-method interface: widget tests (and a future drag-and-drop variant)
|
||||
/// override [reportPickerProvider] instead of mocking a plugin.
|
||||
abstract class ReportPicker {
|
||||
Future<PickedReport?> pick();
|
||||
}
|
||||
|
||||
/// The extensions the report parsers accept.
|
||||
const reportExtensions = ['html', 'htm', 'xlsx', 'csv'];
|
||||
|
||||
class FilePickerReportPicker implements ReportPicker {
|
||||
const FilePickerReportPicker();
|
||||
|
||||
@override
|
||||
Future<PickedReport?> pick() async {
|
||||
// file_picker 11 exposes `pickFiles` as a static on [FilePicker]; the old
|
||||
// `FilePicker.platform` singleton is gone.
|
||||
final result = await FilePicker.pickFiles(
|
||||
type: FileType.custom,
|
||||
allowedExtensions: reportExtensions,
|
||||
// On web there is no path at all, only bytes; asking for bytes everywhere would read
|
||||
// a 16 MB report into memory for nothing on desktop.
|
||||
withData: kIsWeb,
|
||||
);
|
||||
if (result == null || result.files.isEmpty) return null;
|
||||
final file = result.files.first;
|
||||
return PickedReport(name: file.name, bytes: file.bytes, path: file.path);
|
||||
}
|
||||
}
|
||||
|
||||
final reportPickerProvider = Provider<ReportPicker>((ref) => const FilePickerReportPicker());
|
||||
Reference in New Issue
Block a user