# App Version Management

This system allows you to manage app version and download links from the backend.

## Database Setup

Run the SQL file `app_version_setup.sql` to create the `app_settings` table and insert default values.

## How to Update App Version

### Method 1: Direct Database Update

Update the `app_settings` table directly:

```sql
-- Update app version
UPDATE app_settings SET setting_value = '2' WHERE setting_key = 'app_version';

-- Update download links
UPDATE app_settings SET setting_value = 'https://your-new-apk-url.apk' WHERE setting_key = 'download_link_apk';
UPDATE app_settings SET setting_value = 'https://play.google.com/...' WHERE setting_key = 'download_link_googlePlay';
UPDATE app_settings SET setting_value = 'https://appgallery.huawei.com/...' WHERE setting_key = 'download_link_huawei';
UPDATE app_settings SET setting_value = 'https://store.oppo.com/...' WHERE setting_key = 'download_link_oppo';
```

### Method 2: API Endpoint (POST)

Send a POST request to `/api/app-version/update`:

```json
{
  "version": 2,
  "downloadLinks": {
    "apk": "https://your-server.com/apps/betting_tips_v2.apk",
    "googlePlay": "https://play.google.com/store/apps/details?id=com.sports.bettips",
    "huawei": "https://appgallery.huawei.com/app/your-app-id",
    "oppo": "https://store.oppo.com/app/your-app-id"
  }
}
```

**Note:** Add authentication/authorization to the `update()` method in `AppVersion.php` before using in production.

## API Endpoint

### GET /api/app-version

Returns the current app version and download links:

```json
{
  "version": 1,
  "downloadLinks": {
    "apk": "https://your-server.com/apps/betting_tips.apk",
    "googlePlay": "https://play.google.com/store/apps/details?id=com.sports.bettips",
    "huawei": "https://appgallery.huawei.com/app/your-app-id",
    "oppo": "https://store.oppo.com/app/your-app-id"
  }
}
```

## How It Works

1. The Flutter app checks `/api/app-version` on startup
2. Compares the backend `version` with the local `appVersion` constant in `constants.dart`
3. If backend version > local version, shows a non-skippable update dialog
4. **Platform-specific filtering:**
   - **iOS devices**: Only shows App Store download option
   - **Android devices**: Shows APK, Google Play, Huawei, OPPO (hides App Store)
5. User can choose from available download sources for their platform

## Adding New Download Sources

To add a new download source (e.g., Xiaomi App Store):

1. Add a new setting in the database:
```sql
INSERT INTO app_settings (setting_key, setting_value) 
VALUES ('download_link_xiaomi', 'https://app.mi.com/...')
ON DUPLICATE KEY UPDATE setting_value = 'https://app.mi.com/...';
```

2. The Flutter app will automatically display it in the update dialog with a formatted name.

**Note:** 
- iOS-specific sources (containing "appstore", "ios", or "apple" in the key) will only show on iOS devices
- Android-specific sources will only show on Android devices
- The App Store link is automatically hidden on Android devices

