mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 07:37:56 +00:00
Add device icons based on device type and update network exception handling
- Add logic to set device icons based on device type in DeviceModel.fromJson method - Update network exception handling to parse HTML response in ServerFailure class - Add html package as a dependency for parsing HTML responses -Added Devices Icons by updateing device types mapping
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:syncrow_app/features/devices/model/function_model.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
class DeviceModel {
|
||||
@@ -56,13 +57,37 @@ class DeviceModel {
|
||||
}
|
||||
|
||||
factory DeviceModel.fromJson(Map<String, dynamic> json) {
|
||||
print(
|
||||
'type : ${json['productId']} => ${devicesTypesMap[json['productId']]}');
|
||||
|
||||
String icon = '';
|
||||
DeviceType type = devicesTypesMap[json['productId']] ?? DeviceType.Other;
|
||||
|
||||
if (type == DeviceType.LightBulb) {
|
||||
icon = Assets.iconsLight;
|
||||
} else if (type == DeviceType.CeilingSensor ||
|
||||
type == DeviceType.WallSensor) {
|
||||
icon = Assets.iconsSensors;
|
||||
} else if (type == DeviceType.AC) {
|
||||
icon = Assets.iconsAC;
|
||||
} else if (type == DeviceType.DoorLock) {
|
||||
icon = Assets.iconsDoorLock;
|
||||
} else if (type == DeviceType.Curtain) {
|
||||
icon = Assets.iconsCurtain;
|
||||
} else if (type == DeviceType.ThreeGang) {
|
||||
icon = Assets.iconsLight;
|
||||
} else if (type == DeviceType.Gateway) {
|
||||
icon = Assets.iconsGateway;
|
||||
} else {
|
||||
icon = Assets.iconsLogo;
|
||||
}
|
||||
return DeviceModel(
|
||||
activeTime: json['activeTime'],
|
||||
category: json['category'],
|
||||
categoryName: json['categoryName'],
|
||||
createTime: json['createTime'],
|
||||
gatewayId: json['gatewayId'],
|
||||
icon: json['icon'],
|
||||
icon: icon,
|
||||
id: json['id'],
|
||||
ip: json['ip'],
|
||||
lat: double.tryParse(json['lat']),
|
||||
|
||||
@@ -22,7 +22,6 @@ class DevicesViewBody extends StatelessWidget {
|
||||
builder: (context, state) {
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
//TODO : move to NavigationCubit
|
||||
if (state is DevicesLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else {
|
||||
|
||||
@@ -21,18 +21,6 @@ class RoomPageSwitch extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
//Navigate to the chosen category view without animation
|
||||
|
||||
// Navigator.push(
|
||||
// context,
|
||||
// CustomPageRoute(
|
||||
// builder: (context) {
|
||||
// return DevicesCubit.get(context)
|
||||
// .chosenCategoryView!;
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
|
||||
if (device.productType == DeviceType.AC) {
|
||||
Navigator.push(
|
||||
context,
|
||||
|
||||
@@ -61,10 +61,7 @@ class WizartSwitches extends StatelessWidget {
|
||||
DevicesCubit.allCategories![index].icon!,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
CustomSwitch(
|
||||
category:
|
||||
DevicesCubit.allCategories![index],
|
||||
),
|
||||
// CustomSwitch(
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:html/parser.dart' as parser;
|
||||
|
||||
abstract class Failure {
|
||||
final String errMessage;
|
||||
@@ -28,8 +29,12 @@ class ServerFailure extends Failure {
|
||||
return ServerFailure("Bad certificate!");
|
||||
|
||||
case DioExceptionType.badResponse:
|
||||
return ServerFailure.fromResponse(dioError.response!.statusCode!,
|
||||
dioError.response!.data!["message"]);
|
||||
{
|
||||
var document = parser.parse(dioError.response!.data.toString());
|
||||
var message = document.body!.text;
|
||||
return ServerFailure.fromResponse(
|
||||
dioError.response!.statusCode!, message);
|
||||
}
|
||||
case DioExceptionType.cancel:
|
||||
return ServerFailure("The request to ApiServer was canceled");
|
||||
|
||||
|
||||
@@ -29,17 +29,32 @@ enum DeviceType {
|
||||
Other,
|
||||
}
|
||||
|
||||
// Map<String, DeviceType> devicesTypesMap = {
|
||||
// "AC": DeviceType.AC,
|
||||
// "LB": DeviceType.LightBulb,
|
||||
// "DL": DeviceType.DoorLock,
|
||||
// "WC": DeviceType.Curtain,
|
||||
// "WB": DeviceType.Blind,
|
||||
// "3G": DeviceType.ThreeGang,
|
||||
// "GW": DeviceType.Gateway,
|
||||
// "CPS": DeviceType.CeilingSensor,
|
||||
// "WPS": DeviceType.WallSensor,
|
||||
// "Other": DeviceType.Other,
|
||||
// };
|
||||
//AC wzdcrqh0
|
||||
// GW wp8ticoo2bhumwgb
|
||||
// CPS d3ci7gcn
|
||||
// DL awu7anehyu5q1iu8
|
||||
// WPS awarhusb
|
||||
// 3G 1a6vgvyi
|
||||
|
||||
Map<String, DeviceType> devicesTypesMap = {
|
||||
"AC": DeviceType.AC,
|
||||
"LB": DeviceType.LightBulb,
|
||||
"DL": DeviceType.DoorLock,
|
||||
"WC": DeviceType.Curtain,
|
||||
"WB": DeviceType.Blind,
|
||||
"3G": DeviceType.ThreeGang,
|
||||
"GW": DeviceType.Gateway,
|
||||
"CPS": DeviceType.CeilingSensor,
|
||||
"WPS": DeviceType.WallSensor,
|
||||
"Other": DeviceType.Other,
|
||||
"wzdcrqh0": DeviceType.AC,
|
||||
"wp8ticoo2bhumwgb": DeviceType.Gateway,
|
||||
"d3ci7gcn": DeviceType.CeilingSensor,
|
||||
"awu7anehyu5q1iu8": DeviceType.DoorLock,
|
||||
"awarhusb": DeviceType.WallSensor,
|
||||
"1a6vgvyi": DeviceType.ThreeGang,
|
||||
};
|
||||
Map<DeviceType, List<FunctionModel>> devicesFunctionsMap = {
|
||||
DeviceType.AC: [
|
||||
|
||||
Reference in New Issue
Block a user