Untitled

 avatar
unknown
dart
3 years ago
1.8 kB
3
Indexable

    static Future getProfilePictureOfDriver() async {
    bool isConnected = await connectionCheck();
    if (!isConnected) return null;

    Response res = await get(
      Uri.http(
          url, "/driverTablet/getProfilePictureOfDriver/" + Constant.driverInfoModel.sId),
      headers: <String, String>{
        'Authorization': basicAuth
      },
    );

    if (res.body.contains('"Result":false')) {
      print("Profil fotoğrafı mevcut değil.");
      return 0;
    } else {
      print("Profil fotoğrafı bulundu");
      Uint8List _bodybytes = res.bodyBytes;
      var buffer = _bodybytes.buffer;
      ByteData byteData = ByteData.view(buffer);
      var tempdir = await getTemporaryDirectory();
      String tempname = DateTime.now().millisecondsSinceEpoch.toString();
      File file = await File("${tempdir.path}/$tempname").writeAsBytes(
          buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
      return file;
    }
  }
  
  ---------------------------------------------------
  ///////////////////////////////////////////////////
  ---------------------------------------------------
  
    static Future<bool> connectionCheck() async {
    return await Connectivity()
        .checkConnectivity()
        .then((connectivityResult) async {
      if (connectivityResult == ConnectivityResult.mobile ||
          connectivityResult == ConnectivityResult.wifi) {
        return await DataConnectionChecker().hasConnection.then((value) async {
          if (value != null && value) {
            GlobalV.connectionCheck = true;
            return true;
          } else {
            GlobalV.connectionCheck = false;
            return false;
          }
        });
      } else {
        GlobalV.connectionCheck = false;
        return false;
      }
    });
  }
Editor is loading...