import 'dart:io';
import 'package:package_info/package_info.dart';
import 'package:url_launcher/url_launcher.dart';

class DeviceUtil {
  ///发邮件
  static void sendEmail(String email) {
    if (email.isNotEmpty) {
      String url = 'mailto:$email';
      launchUrl(Uri.parse(url));
    }
  }

  ///打电话
  static void callPhone(String phone) {
    if (phone.isNotEmpty) {
      String url = 'tel:$phone';
      if (Platform.isIOS) {
        url = 'tel://$phone';
      }
      if (Platform.isAndroid) {
        url = 'tel:$phone';
      }
      launchUrl(Uri.parse(url));
    }
  }

  /// 获取当前版本
  static Future<String> getAppVersion() async {
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    return packageInfo.version;
  }

  /// 获取平台信息
  static Future<String> getPlatForm() async {
    if (Platform.isAndroid) {
      return 'android';
    } else {
      return 'ios';
    }
  }
}
