mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 10:06:16 +00:00
AC devices page implemented
AC Cubit Add New Devices Cubit Arch will be used Devices Cubit (for devices categories, and devices page) { AC cubit, Lights cubit. ... } Replaced AssetsManager with Assets Class (auto generated)
This commit is contained in:
@ -1,31 +0,0 @@
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class CacheHelper {
|
||||
static late SharedPreferences sharedPreferences;
|
||||
|
||||
static init() async {
|
||||
sharedPreferences = await SharedPreferences.getInstance();
|
||||
}
|
||||
|
||||
static Object? getData({
|
||||
required String key,
|
||||
}) async {
|
||||
return sharedPreferences.get(key);
|
||||
}
|
||||
|
||||
static Future setData({
|
||||
required String key,
|
||||
required value,
|
||||
}) async {
|
||||
if (value is String) return await sharedPreferences.setString(key, value);
|
||||
if (value is int) return await sharedPreferences.setInt(key, value);
|
||||
if (value is bool) return await sharedPreferences.setBool(key, value);
|
||||
return await sharedPreferences.setDouble(key, value);
|
||||
}
|
||||
|
||||
static dynamic removeData({
|
||||
required String key,
|
||||
}) async {
|
||||
return sharedPreferences.remove(key);
|
||||
}
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
// import 'dart:io';
|
||||
// import 'dart:math';
|
||||
// import 'package:dio/dio.dart';
|
||||
// import 'package:file_picker/file_picker.dart';
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:flutter/services.dart';
|
||||
//
|
||||
// import 'package:path_provider/path_provider.dart';
|
||||
//
|
||||
// class FileHelper {
|
||||
// static Future<Map<String, Uint8List>> takePicture() async {
|
||||
// try {
|
||||
// XFile? pickedImage = await ImagePicker().pickImage(source: ImageSource.camera);
|
||||
// if (pickedImage != null) {
|
||||
// final fileTemp = File(pickedImage.path);
|
||||
// final bytes = fileTemp.readAsBytesSync();
|
||||
// return {pickedImage.path: bytes};
|
||||
// } else {
|
||||
// return {};
|
||||
// }
|
||||
// } on PlatformException catch (_) {
|
||||
// return {};
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// static Future<Map<String, Uint8List>> pickFile({bool gallery = false}) async {
|
||||
// try {
|
||||
// FilePickerResult? pickedFile;
|
||||
// XFile? pickedFromGallery;
|
||||
// if (gallery) {
|
||||
// final picker = ImagePicker();
|
||||
// pickedFromGallery =
|
||||
// await picker.pickImage(source: ImageSource.gallery, requestFullMetadata: false);
|
||||
// } else {
|
||||
// pickedFile = await FilePicker.platform.pickFiles(
|
||||
// allowedExtensions: ['png', 'jpg', 'jpeg', 'pdf'],
|
||||
// type: FileType.custom,
|
||||
// withReadStream: true,
|
||||
// );
|
||||
// }
|
||||
// if (pickedFile != null) {
|
||||
// String path = pickedFile.files.single.path ?? '';
|
||||
// final fileTemp = File(path);
|
||||
// final bytes = fileTemp.readAsBytesSync();
|
||||
// if (path.isEmpty) {
|
||||
// return {};
|
||||
// }
|
||||
// return {path: bytes};
|
||||
// } else if (pickedFromGallery != null) {
|
||||
// String path = pickedFromGallery.path;
|
||||
// final fileTemp = File(path);
|
||||
// final bytes = fileTemp.readAsBytesSync();
|
||||
// if (path.isEmpty) {
|
||||
// return {};
|
||||
// }
|
||||
// return {path: bytes};
|
||||
// } else {
|
||||
// return {};
|
||||
// }
|
||||
// } on PlatformException catch (_) {
|
||||
// return {};
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Future<String> downloadFile(String url) async {
|
||||
// String filePath;
|
||||
// try {
|
||||
// filePath = await _prepareSaveDir(url);
|
||||
// await HTTPService()
|
||||
// .downloadRequest(path: url, savePath: filePath, expectedResponseModel: (json) {});
|
||||
// } catch (err) {
|
||||
// CustomSnackBar.displaySnackBar('Something went wrong please try again!');
|
||||
// return '';
|
||||
// }
|
||||
// return filePath;
|
||||
// }
|
||||
//
|
||||
// String getRandomString(int length) {
|
||||
// const chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
|
||||
// Random rnd = Random();
|
||||
//
|
||||
// return String.fromCharCodes(
|
||||
// Iterable.generate(length, (_) => chars.codeUnitAt(rnd.nextInt(chars.length))));
|
||||
// }
|
||||
//
|
||||
// Future<String> _prepareSaveDir(String url) async {
|
||||
// try {
|
||||
// final localPath = (await _findLocalPath(url))!;
|
||||
//
|
||||
// final savedDir = Directory(localPath);
|
||||
// bool hasExisted = await savedDir.exists();
|
||||
// if (!hasExisted) {
|
||||
// await File(savedDir.path).create();
|
||||
// }
|
||||
// return savedDir.path;
|
||||
// } catch (err) {
|
||||
// return '';
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Future<String?> _findLocalPath(String url) async {
|
||||
// String fileName = getRandomString(10);
|
||||
// String fileNameWithExtension = url.contains('pdf') ? '$fileName.pdf' : '$fileName.jpeg';
|
||||
//
|
||||
// if (Platform.isAndroid) {
|
||||
// return "/sdcard/download/$fileNameWithExtension";
|
||||
// } else {
|
||||
// var directory = await getApplicationDocumentsDirectory();
|
||||
// return '${directory.path}${Platform.pathSeparator}$fileNameWithExtension';
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// static Future<Uint8List?> fetchPdfContent(final String url) async {
|
||||
// try {
|
||||
// final Response<List<int>> response = await Dio().get<List<int>>(
|
||||
// url,
|
||||
// options: Options(responseType: ResponseType.bytes),
|
||||
// );
|
||||
// return Uint8List.fromList(response.data ?? []);
|
||||
// } catch (e) {
|
||||
// debugPrint(e.toString());
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
// }
|
@ -1,90 +0,0 @@
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class SharedPreferencesHelper {
|
||||
// isRegistered flag to know if the user has entered his fullname and email or not (is he registered or not)
|
||||
static bool? isRegistered;
|
||||
|
||||
// flags to detect the mode {regular, onboarding, demo}
|
||||
static bool? isDemo;
|
||||
static bool? isOnBoarding;
|
||||
|
||||
// isDemoAndUseToken flag to use the user token in the header of the request in the demo experience, instead of "Demo" header in situations (1. openning the profile request 2. updating th user data -registeration- request)
|
||||
static bool? isDemoAndUseToken;
|
||||
|
||||
// addedFirstProperty flag to detect if the user has added his first property or not
|
||||
static bool? addedFirstProperty;
|
||||
|
||||
// stores the user id value
|
||||
static String? userIdValue;
|
||||
|
||||
// stores the phone number value
|
||||
static String? phoneNumber;
|
||||
|
||||
//stores the country code of the user phone
|
||||
static String? countryCode;
|
||||
|
||||
// static Future<bool?> getIsDemoValue() async {
|
||||
// isDemo = await readBoolFromSP(KeyConstants.isDemoFlag) ?? false;
|
||||
// return isDemo;
|
||||
// }
|
||||
//
|
||||
// static Future<bool?> getIsOnboardingValue() async {
|
||||
// isOnBoarding = await readBoolFromSP(KeyConstants.isOnboardingFlag);
|
||||
// return isOnBoarding;
|
||||
// }
|
||||
|
||||
static saveStringToSP(String key, String value) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString(key, value);
|
||||
}
|
||||
|
||||
static saveBoolToSP(String key, bool value) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setBool(key, value);
|
||||
}
|
||||
|
||||
static saveIntToSP(String key, int value) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setInt(key, value);
|
||||
}
|
||||
|
||||
static saveDoubleToSP(String key, double value) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setDouble(key, value);
|
||||
}
|
||||
|
||||
static saveStringListToSP(String key, List<String> value) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setStringList(key, value);
|
||||
}
|
||||
|
||||
static Future<String> readStringFromSP(String key) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
String value = prefs.getString(key) ?? '';
|
||||
return value;
|
||||
}
|
||||
|
||||
static Future<bool?> readBoolFromSP(String key) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
bool? value = prefs.getBool(key);
|
||||
return value;
|
||||
}
|
||||
|
||||
static Future<int> readIntFromSP(String key) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
int value = prefs.getInt(key) ?? 0;
|
||||
return value;
|
||||
}
|
||||
|
||||
static Future<List<String>> readStringListFromSP(String key) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
List<String>? value = prefs.getStringList(key) ?? [];
|
||||
return value;
|
||||
}
|
||||
|
||||
static Future<bool> removeValueFromSP(String key) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.remove(key);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class URLLauncher {
|
||||
static Future<void> sendWhatsapp(
|
||||
{String phoneNumber = '971581497062',
|
||||
String text = 'Hi%2C%20I%20would%20like%20to',
|
||||
String from = ''}) async {
|
||||
Uri launchUri;
|
||||
launchUri = Uri.parse("whatsapp://send?phone=%2B$phoneNumber&text=$text");
|
||||
// Launch the App
|
||||
try {
|
||||
// SegmentEvents.sendTrackEvent(SegmentEventModel(
|
||||
// eventName: 'Whatsapp opened', properties: {'From': from}));
|
||||
//
|
||||
// if (await canLaunchUrl(launchUri) == false) {
|
||||
// CustomSnackBar.displaySnackBar('Could not open whatsapp');
|
||||
// return;
|
||||
// }
|
||||
if (Platform.isAndroid) {
|
||||
await launch(
|
||||
launchUri.toString(),
|
||||
);
|
||||
} else {
|
||||
await launchUrl(
|
||||
launchUri,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
// CustomSnackBar.displaySnackBar('Could not open whatsapp');
|
||||
throw 'Could not launch $phoneNumber';
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> sendEmail(
|
||||
{required String email, String subject = '', body = ''}) async {
|
||||
String? encodeQueryParameters(Map<String, String> params) {
|
||||
return params.entries
|
||||
.map((MapEntry<String, String> e) =>
|
||||
'${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}')
|
||||
.join('&');
|
||||
}
|
||||
|
||||
final emailLaunchUri = Uri(
|
||||
scheme: 'mailto',
|
||||
path: email,
|
||||
query: encodeQueryParameters(<String, String>{
|
||||
subject: body,
|
||||
}),
|
||||
);
|
||||
try {
|
||||
bool canLaunch = await canLaunchUrl(emailLaunchUri);
|
||||
if (canLaunch) {
|
||||
await launchUrl(emailLaunchUri);
|
||||
}
|
||||
} catch (err) {
|
||||
throw 'Could not launch $emailLaunchUri';
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> launch(String url) async {
|
||||
Uri parsedUrl = Uri.parse(url);
|
||||
try {
|
||||
bool canLaunch = await canLaunchUrl(parsedUrl);
|
||||
if (canLaunch) {
|
||||
await launchUrl(
|
||||
parsedUrl,
|
||||
// mode: LaunchMode.externalApplication,
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
throw 'Url launcher error: ${err.toString()}';
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user