Describe the bug/problem
The CsvPreviewer widget in lib/widgets/previewer_csv.dart attempts to access csvData[0] without checking if the CSV data list is empty. This causes a RangeError crash when the CSV response is empty or malformed.
Steps to Reproduce the bug/problem
- Send an API request that returns an empty CSV response
- Navigate to the Preview tab for CSV viewing
- Result: App crashes with
RangeError: Index out of range
Alternatively:
- Send an API request with malformed CSV data that parses to an empty list
- View the response in Preview mode
- Result: App crashes
Expected behavior
The CSV previewer should gracefully handle empty CSV data by displaying an error widget instead of crashing. Empty CSV responses should not cause the application to fail.
Root Cause
File: lib/widgets/previewer_csv.dart, line 23
Current code:
final List<List<dynamic>> csvData = csv.decode(body);
return SingleChildScrollView(
scrollDirection: Axis.vertical,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: DataTable(
columns: csvData[0] // ← Crashes if csvData is empty
.map((item) => DataColumn(label: Text(item.toString())))
.toList(),
Problem: The code directly accesses csvData[0] without verifying that the list contains at least one row.
Proposed Solution
Add a validation check before building the DataTable:
final List<List<dynamic>> csvData = csv.decode(body);
if (csvData.isEmpty) {
return errorWidget;
}
return SingleChildScrollView(
// ... rest of the code
Device Info
- OS: All platforms (cross-platform issue)
- Version: Not platform-specific
- Environment: Production & Development
Impact
Severity: Medium - Causes application crash
Frequency: Occurs when API returns empty or malformed CSV data
User Impact: Prevents users from viewing other response formats after CSV crash, requires app restart
Describe the bug/problem
The
CsvPreviewerwidget inlib/widgets/previewer_csv.dartattempts to accesscsvData[0]without checking if the CSV data list is empty. This causes aRangeErrorcrash when the CSV response is empty or malformed.Steps to Reproduce the bug/problem
RangeError: Index out of rangeAlternatively:
Expected behavior
The CSV previewer should gracefully handle empty CSV data by displaying an error widget instead of crashing. Empty CSV responses should not cause the application to fail.
Root Cause
File:
lib/widgets/previewer_csv.dart, line 23Current code:
Problem: The code directly accesses
csvData[0]without verifying that the list contains at least one row.Proposed Solution
Add a validation check before building the DataTable:
Device Info
Impact
Severity: Medium - Causes application crash
Frequency: Occurs when API returns empty or malformed CSV data
User Impact: Prevents users from viewing other response formats after CSV crash, requires app restart