Skip to content

Commit 7c5ca19

Browse files
Fix file saving failure for names exceeding 200 characters
Before: - ​If a user inputs a file name longer than 200 characters, the OS rejects it and the file does not get saved. After: - Leading and trailing whitespaces are removed from the filename. - ​The filename is automatically truncated to a maximum of 200 characters before saving, preventing the crash.
1 parent 83c3315 commit 7c5ca19

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

lib/others/csv_service.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ class CsvService {
4646
final directory = await getInstrumentDirectory(instrumentName);
4747

4848
String finalFileName;
49+
fileName = fileName.trim();
4950
if (fileName.isEmpty) {
5051
finalFileName =
5152
'${DateFormat('yyyy-MM-dd_HH-mm-ss').format(DateTime.now())}.csv';
5253
} else {
54+
if (fileName.length > 200) {
55+
fileName = fileName.substring(0, 200);
56+
}
5357
finalFileName = fileName.endsWith('.csv') ? fileName : '$fileName.csv';
5458
}
5559

0 commit comments

Comments
 (0)