mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 18:16:21 +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/features/devices/model/function_model.dart';
|
||||||
|
import 'package:syncrow_app/generated/assets.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||||
|
|
||||||
class DeviceModel {
|
class DeviceModel {
|
||||||
@ -56,13 +57,37 @@ class DeviceModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
factory DeviceModel.fromJson(Map<String, dynamic> json) {
|
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(
|
return DeviceModel(
|
||||||
activeTime: json['activeTime'],
|
activeTime: json['activeTime'],
|
||||||
category: json['category'],
|
category: json['category'],
|
||||||
categoryName: json['categoryName'],
|
categoryName: json['categoryName'],
|
||||||
createTime: json['createTime'],
|
createTime: json['createTime'],
|
||||||
gatewayId: json['gatewayId'],
|
gatewayId: json['gatewayId'],
|
||||||
icon: json['icon'],
|
icon: icon,
|
||||||
id: json['id'],
|
id: json['id'],
|
||||||
ip: json['ip'],
|
ip: json['ip'],
|
||||||
lat: double.tryParse(json['lat']),
|
lat: double.tryParse(json['lat']),
|
||||||
|
@ -22,7 +22,6 @@ class DevicesViewBody extends StatelessWidget {
|
|||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
//TODO : move to NavigationCubit
|
|
||||||
if (state is DevicesLoading) {
|
if (state is DevicesLoading) {
|
||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: CircularProgressIndicator());
|
||||||
} else {
|
} else {
|
||||||
|
@ -21,18 +21,6 @@ class RoomPageSwitch extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () {
|
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) {
|
if (device.productType == DeviceType.AC) {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
|
@ -61,10 +61,7 @@ class WizartSwitches extends StatelessWidget {
|
|||||||
DevicesCubit.allCategories![index].icon!,
|
DevicesCubit.allCategories![index].icon!,
|
||||||
fit: BoxFit.contain,
|
fit: BoxFit.contain,
|
||||||
),
|
),
|
||||||
CustomSwitch(
|
// CustomSwitch(
|
||||||
category:
|
|
||||||
DevicesCubit.allCategories![index],
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:html/parser.dart' as parser;
|
||||||
|
|
||||||
abstract class Failure {
|
abstract class Failure {
|
||||||
final String errMessage;
|
final String errMessage;
|
||||||
@ -28,8 +29,12 @@ class ServerFailure extends Failure {
|
|||||||
return ServerFailure("Bad certificate!");
|
return ServerFailure("Bad certificate!");
|
||||||
|
|
||||||
case DioExceptionType.badResponse:
|
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:
|
case DioExceptionType.cancel:
|
||||||
return ServerFailure("The request to ApiServer was canceled");
|
return ServerFailure("The request to ApiServer was canceled");
|
||||||
|
|
||||||
|
@ -29,17 +29,32 @@ enum DeviceType {
|
|||||||
Other,
|
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 = {
|
Map<String, DeviceType> devicesTypesMap = {
|
||||||
"AC": DeviceType.AC,
|
"wzdcrqh0": DeviceType.AC,
|
||||||
"LB": DeviceType.LightBulb,
|
"wp8ticoo2bhumwgb": DeviceType.Gateway,
|
||||||
"DL": DeviceType.DoorLock,
|
"d3ci7gcn": DeviceType.CeilingSensor,
|
||||||
"WC": DeviceType.Curtain,
|
"awu7anehyu5q1iu8": DeviceType.DoorLock,
|
||||||
"WB": DeviceType.Blind,
|
"awarhusb": DeviceType.WallSensor,
|
||||||
"3G": DeviceType.ThreeGang,
|
"1a6vgvyi": DeviceType.ThreeGang,
|
||||||
"GW": DeviceType.Gateway,
|
|
||||||
"CPS": DeviceType.CeilingSensor,
|
|
||||||
"WPS": DeviceType.WallSensor,
|
|
||||||
"Other": DeviceType.Other,
|
|
||||||
};
|
};
|
||||||
Map<DeviceType, List<FunctionModel>> devicesFunctionsMap = {
|
Map<DeviceType, List<FunctionModel>> devicesFunctionsMap = {
|
||||||
DeviceType.AC: [
|
DeviceType.AC: [
|
||||||
|
16
pubspec.lock
16
pubspec.lock
@ -97,6 +97,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.0.3"
|
version: "3.0.3"
|
||||||
|
csslib:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: csslib
|
||||||
|
sha256: "706b5707578e0c1b4b7550f64078f0a0f19dec3f50a178ffae7006b0a9ca58fb"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.0"
|
||||||
cupertino_icons:
|
cupertino_icons:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -357,6 +365,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "7.6.7"
|
version: "7.6.7"
|
||||||
|
html:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: html
|
||||||
|
sha256: "3a7812d5bcd2894edf53dfaf8cd640876cf6cef50a8f238745c8b8120ea74d3a"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.15.4"
|
||||||
http:
|
http:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -36,6 +36,7 @@ dependencies:
|
|||||||
firebase_analytics: ^10.8.7
|
firebase_analytics: ^10.8.7
|
||||||
firebase_crashlytics: ^3.4.16
|
firebase_crashlytics: ^3.4.16
|
||||||
smooth_page_indicator: ^1.1.0
|
smooth_page_indicator: ^1.1.0
|
||||||
|
html: ^0.15.4
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
Reference in New Issue
Block a user