import 'dart:io';

import 'package:dio/dio.dart';
import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';

class ApkUpdater {
  static const _channel = MethodChannel('apk_installer');

  static Future<void> downloadAndInstall() async {
    final dio = Dio();
    final apkUrl = "https://yourdomain.com/app.apk";

    final dir = await getExternalStorageDirectory();
    final path = "${dir!.path}/update.apk";
    final file = File(path);

    await dio.download(apkUrl, path);

    await _channel.invokeMethod("installApk", {"path": path});
  }
}
