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:
Mohammad Salameh
2024-02-26 15:55:22 +03:00
parent c95a9c7817
commit abe7072f2d
72 changed files with 1535 additions and 634 deletions
+5 -1
View File
@@ -1,6 +1,7 @@
// ignore_for_file: avoid_print
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
class MyBlocObserver extends BlocObserver {
@override
@@ -24,6 +25,9 @@ class MyBlocObserver extends BlocObserver {
@override
void onClose(BlocBase bloc) {
super.onClose(bloc);
if (bloc is DevicesCubit) {
DevicesCubit.clearCategoriesSelection();
}
print('onClose -- ${bloc.runtimeType}');
}
}
}
-31
View File
@@ -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);
}
}
-125
View File
@@ -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;
}
}
-76
View File
@@ -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()}';
}
}
}
@@ -1,47 +0,0 @@
abstract class ImageManager {
static const String base = 'assets/images';
static const String whiteLogo = '$base/white-logo.png';
static const String blackLogo = '$base/black-logo.png';
static const String boxEmpty = '$base/box-empty.jpg';
static const String automation = '$base/automation.jpg';
static const String background = '$base/Background.png';
static const String testDash = '$base/test_dash.png';
static const String testDash2 = '$base/test_dash2.png';
}
abstract class IconsManager {
static const String base = 'assets/icons';
static const String home = '$base/home-2.svg';
static const String dashboardFill = '$base/dashboard-fill.svg';
static const String dashboard = '$base/dashboard.svg';
static const String devices = '$base/Devices.svg';
static const String devicesFill = '$base/Devices-fill.svg';
static const String routine = '$base/Routines.svg';
static const String routineFill = '$base/Routine-fill.svg';
static const String menu = '$base/Menu.svg';
static const String menuFill = '$base/Menu-fill.svg';
static const String layout = '$base/Layout.svg';
static const String layoutFill = '$base/Layout-fill.svg';
static const String frequency = '$base/frequency.svg';
static const String winter = '$base/Winter.svg';
static const String active = '$base/active.svg';
static const String voltMeter = '$base/volt-meter.svg';
static const String summer = '$base/Summer.svg';
static const String CO2 = '$base/CO2.svg';
static const String sustainability = '$base/sustainability.svg';
static const String ac = '$base/AC.svg';
static const String curtain = '$base/Curtain.svg';
static const String doorLock = '$base/Door Lock.svg';
static const String gateway = '$base/Gateway.svg';
static const String light = '$base/Light.svg';
static const String summerMode = '$base/Hot 1.jpg';
static const String winterMode = '$base/Winter 1.jpg';
static const String screen = '$base/Screen.svg';
}