fromCsv static method
Imports from a CSV file
Implementation
static Future<ImportResult> fromCsv(
String filePath, {
String? schemaName,
String delimiter = ',',
bool hasHeader = true,
}) async {
try {
final file = File(filePath);
if (!await file.exists()) {
return ImportResult(
schema: _createEmptySchema(schemaName ?? 'ImportedData'),
data: [],
rowCount: 0,
error: 'File not found: $filePath',
);
}
final content = await file.readAsString();
return fromCsvString(
content,
schemaName: schemaName ?? _extractFileName(filePath),
delimiter: delimiter,
hasHeader: hasHeader,
);
} catch (e) {
return ImportResult(
schema: _createEmptySchema(schemaName ?? 'ImportedData'),
data: [],
rowCount: 0,
error: 'Error reading the file: $e',
);
}
}