Merge branch 'main' into product

This commit is contained in:
Raj
2024-05-08 18:49:42 +05:30
committed by GitHub
15 changed files with 438 additions and 133 deletions

View File

@@ -131,12 +131,12 @@ Widget text12W500_B4B4B4(String text) {
);
}
Widget text14W600_1B1B1B(String text) {
Widget text14W600_1B1B1B(String text, {Color? clr}) {
return Text(
text,
style: TextStyle(
fontSize: 14.sp,
color: Color(0Xff1B1B1B),
color: clr ?? const Color(0Xff1B1B1B),
fontWeight: FontWeight.w600,
fontFamily: 'hiragino'),
);

View File

@@ -1,8 +1,13 @@
import 'dart:developer';
import 'dart:io';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart' as getx;
import 'package:permission_handler/permission_handler.dart';
class Utils {
static Future<MultipartFile> networkImageToMultipartFile(
@@ -61,4 +66,112 @@ class Utils {
barrierDismissible: false,
);
}
static Future<void> getStoragePermission() async {
DeviceInfoPlugin plugin = DeviceInfoPlugin();
AndroidDeviceInfo android = await plugin.androidInfo;
if (android.version.sdkInt < 33) {
if (await Permission.storage.request().isGranted) {
// setState(() {
// permissionGranted = true;
// });
} else if (await Permission.storage.request().isPermanentlyDenied) {
await openAppSettings();
await showToast("Permission denied.");
}
// else if (await Permission.audio.request().isDenied) {
// // setState(() {
// // permissionGranted = false;
// // });
// }
} else {
if (await Permission.photos.request().isGranted) {
// await utils.showToast("Permission granted.");
// setState(() {
// permissionGranted = true;
// });
} else if (await Permission.photos.request().isPermanentlyDenied) {
await openAppSettings();
await showToast("Permission denied.");
} else if (await Permission.photos.request().isDenied) {
await openAppSettings();
await showToast("Permission denied.");
// setState(() {
// permissionGranted = false;
// });
}
}
}
static Future openFile({
required String url,
String? fileName,
}) async {
var status;
// Permission.manageExternalStorage.request();
final deviceInfo = await DeviceInfoPlugin().androidInfo;
if (deviceInfo.version.sdkInt > 32) {
status = await Permission.photos.request().isGranted;
await Permission.manageExternalStorage.request();
} else {
status = await Permission.storage.request().isGranted;
await Permission.manageExternalStorage.request();
}
if (status) {
await downloadFile(url, fileName!);
// if (file == null) {
// log("Error 3333333333333");
// } else {
// await OpenFile.open(file.path).then((value) {
// print("RUNNING THIS");
// if (value.type == ResultType.noAppToOpen) {
// ScaffoldMessenger.of(context).showSnackBar(Helper.displaySnackBar(
// "type",
// "error",
// "You do not have any application to open this file"));
// //Navigator.pop(context);
// } else {
// log(value.message);
// }
// });
// // if (message.toString() != "done") {
// // displaySnackBar("login", "error", message.message.toString());
// // }
// }
} else {
openAppSettings();
}
}
static Future<File?> downloadFile(String url, String name) async {
final appStorage = Directory("/storage/emulated/0/Download");
final file = File('${appStorage.path}/$name');
try {
showToast("Downloading...");
final response = await Dio().get(
url,
options: Options(
// headers: requestHeaders,
responseType: ResponseType.bytes,
followRedirects: false,
// receiveTimeout: 0,
),
);
final raf = file.openSync(mode: FileMode.write);
raf.writeFromSync(response.data);
await raf.close();
showToast("Download Completed !");
return file;
} catch (e) {
log(e.toString());
showToast("Download Error! Please try again");
return null;
}
}
}