# Testing CSV Save Dialog Feature

## What Was Added

A new option in the CSV export dialog that shows a **native system save dialog** (like browser downloads), allowing users to choose exactly where to save their CSV files!

## ✅ FIXED: Bytes Issue Resolved

The previous "Bytes are required" error has been fixed. The save dialog now works properly by providing the CSV content as bytes to the FilePicker.

## How to Test

### 1. Open the App and Navigate to Backup Screen
- Go to the backup/export section of your health tracker app
- Look for the "Export CSV" button

### 2. Click "Export CSV" Button
- This should now open a dialog (instead of immediately exporting)
- The dialog should show:
  - **Export format**: CSV should be pre-selected
  - **Additional options section**: Should contain a toggle switch labeled "Choose Save Location"

### 3. Test the Save Location Option
- **OFF (default)**: CSV files are saved to the app's internal directory
- **ON**: A system save dialog appears, allowing users to choose where to save the file

### 4. Expected Behavior

#### When "Choose Save Location" is OFF:
- Files are saved to: `/data/data/com.example.health_tracker/app_flutter/` (internal)
- Files are accessible through the app's local backups section
- Files are not directly accessible via file manager

#### When "Choose Save Location" is ON:
- A system save dialog appears (like when downloading from a browser)
- Users can navigate to any accessible location (Downloads, Documents, SD card, etc.)
- Users can rename the file if desired
- Files are saved exactly where the user chooses
- Users can cancel the dialog to abort the export

### 5. File Location Verification

#### Android Emulator:
```bash
# Check Downloads folder
adb shell ls -la /storage/emulated/0/Download/

# Look for files like: healthtracker_export_YYYYMMDD_HHMM.csv
```

#### Android Device:
- Open the device's file manager
- Navigate to Downloads folder
- Look for CSV files with names like `healthtracker_export_20250822_1015.csv`

### 6. Permissions
- On first use with Downloads option, the app should request storage permissions
- If permissions are denied, the app should fall back to internal storage

## What to Look For

1. ✅ **Export Dialog Appears**: Clicking "Export CSV" shows a configuration dialog
2. ✅ **Save Location Toggle Visible**: The dialog shows "Choose Save Location" option when CSV format is selected
3. ✅ **Toggle Works**: The switch can be toggled on/off
4. ✅ **System Save Dialog**: When ON, a native save dialog appears (like browser downloads)
5. ✅ **User Can Navigate**: Users can browse to any accessible folder in the save dialog
6. ✅ **User Can Cancel**: Users can cancel the save dialog without error
7. ✅ **Files Save Correctly**: Files are saved to the exact location chosen by the user

## File Naming
CSV files are named with the pattern:
`healthtracker_export_[datatypes]_YYYYMMDD_HHMM.csv`

Examples:
- `healthtracker_export_20250822_1015.csv` (all data)
- `healthtracker_export_weight_20250822_1015.csv` (weight only)

## Testing Different Scenarios

1. **All Data Export**: Leave all data types selected
2. **Specific Data Types**: Select only weight, blood pressure, or mood data
3. **Date Range**: Set a specific date range for export
4. **Permission Denied**: Deny storage permission and verify fallback
5. **No External Storage**: Test on device without SD card access
