Доходы, ребалансировка, налоги, импорт, цели, здоровье данных, правила, транзакции, категории, cashflow, pending: новые виджеты и токены темы, dart format. Тесты подстроены под новые модели.
40 lines
1.4 KiB
Dart
40 lines
1.4 KiB
Dart
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(),
|
|
);
|