mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-14 17:25:47 +00:00
fetch groups
This commit is contained in:
48
.vscode/launch.json
vendored
Normal file
48
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "Iphone 15 Pro Max",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "dart",
|
||||||
|
"deviceId": "0147FC23-3D6C-406A-BE2C-9E67BAF3DA9B"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Iphone SE",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "dart",
|
||||||
|
"deviceId": "DB3BAF09-EF89-4A31-8DD8-A81DC346CB43",
|
||||||
|
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "syncrow-app",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "dart"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "syncrow-app (profile mode)",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "dart",
|
||||||
|
"flutterMode": "profile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "syncrow-app (release mode)",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "dart",
|
||||||
|
"flutterMode": "release"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"compounds": [
|
||||||
|
{
|
||||||
|
"name": "All Device",
|
||||||
|
"configurations": [
|
||||||
|
"Iphone 15 Pro Max",
|
||||||
|
"Iphone SE"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -21,7 +21,7 @@ class SpacesCubit extends Cubit<SpacesState> {
|
|||||||
|
|
||||||
static List<SpaceModel> spaces = [];
|
static List<SpaceModel> spaces = [];
|
||||||
|
|
||||||
SpaceModel? selectedSpace = spaces.isNotEmpty ? spaces.first : null;
|
static SpaceModel? selectedSpace = spaces.isNotEmpty ? spaces.first : null;
|
||||||
|
|
||||||
RoomModel? selectedRoom;
|
RoomModel? selectedRoom;
|
||||||
|
|
||||||
@ -47,8 +47,8 @@ class SpacesCubit extends Cubit<SpacesState> {
|
|||||||
unselectRoom();
|
unselectRoom();
|
||||||
} else {
|
} else {
|
||||||
selectedRoom = selectedSpace!.rooms![index - 1];
|
selectedRoom = selectedSpace!.rooms![index - 1];
|
||||||
|
emit(RoomSelected(selectedRoom!));
|
||||||
}
|
}
|
||||||
emit(RoomSelected(selectedRoom!));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
devicesPageChanged(int index) {
|
devicesPageChanged(int index) {
|
||||||
@ -58,12 +58,12 @@ class SpacesCubit extends Cubit<SpacesState> {
|
|||||||
curve: Curves.linear,
|
curve: Curves.linear,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (index == 0) {
|
if (index <= 0) {
|
||||||
unselectRoom();
|
unselectRoom();
|
||||||
} else {
|
} else {
|
||||||
selectedRoom = selectedSpace!.rooms![index - 1];
|
selectedRoom = selectedSpace!.rooms![index - 1];
|
||||||
|
emit(RoomSelected(selectedRoom!));
|
||||||
}
|
}
|
||||||
emit(RoomSelected(selectedRoom!));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unselectRoom() {
|
unselectRoom() {
|
||||||
|
@ -26,4 +26,8 @@ class SpaceModel {
|
|||||||
rooms: [],
|
rooms: [],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static List<SpaceModel> fromJsonList(List<dynamic> jsonList) {
|
||||||
|
return jsonList.map((item) => SpaceModel.fromJson(item)).toList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ class AppBarHomeDropdown extends StatelessWidget {
|
|||||||
underline: const SizedBox.shrink(),
|
underline: const SizedBox.shrink(),
|
||||||
padding: const EdgeInsets.all(0),
|
padding: const EdgeInsets.all(0),
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
value: SpacesCubit.get(context).selectedSpace!.id,
|
value: SpacesCubit.selectedSpace!.id,
|
||||||
items: SpacesCubit.spaces.map((space) {
|
items: SpacesCubit.spaces.map((space) {
|
||||||
return DropdownMenuItem(
|
return DropdownMenuItem(
|
||||||
value: space.id,
|
value: space.id,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/app_layout/bloc/spaces_cubit.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_category_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_category_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||||
@ -18,7 +19,9 @@ import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
|||||||
part 'devices_state.dart';
|
part 'devices_state.dart';
|
||||||
|
|
||||||
class DevicesCubit extends Cubit<DevicesState> {
|
class DevicesCubit extends Cubit<DevicesState> {
|
||||||
DevicesCubit() : super(DevicesInitial());
|
DevicesCubit() : super(DevicesInitial()) {
|
||||||
|
fetchGroups(SpacesCubit.selectedSpace!);
|
||||||
|
}
|
||||||
|
|
||||||
static DevicesCubit get(context) => BlocProvider.of(context);
|
static DevicesCubit get(context) => BlocProvider.of(context);
|
||||||
|
|
||||||
@ -435,23 +438,10 @@ class DevicesCubit extends Cubit<DevicesState> {
|
|||||||
emit(DevicesCategoryChanged());
|
emit(DevicesCategoryChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
//fetchRooms(SpaceModel space) async {
|
|
||||||
// emit(SpaceRoomsLoading());
|
|
||||||
// try {
|
|
||||||
// space.rooms = await SpacesAPI.getRooms(space.id!);
|
|
||||||
// if (space.rooms != null) {
|
|
||||||
// emit(SpaceRoomsLoaded(space.rooms!));
|
|
||||||
// } else {
|
|
||||||
// emit(SpaceRoomsError("No rooms found"));
|
|
||||||
// }
|
|
||||||
// } on DioException catch (e) {
|
|
||||||
// emit(SpacesError(ServerFailure.fromDioError(e).errMessage));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
deviceControl(DeviceControlModel control) async {
|
deviceControl(DeviceControlModel control) async {
|
||||||
emit(DeviceControlLoading());
|
emit(DeviceControlLoading());
|
||||||
try {
|
try {
|
||||||
var response = await DevicesAPI.controlDevice(control);
|
await DevicesAPI.controlDevice(control);
|
||||||
emit(DeviceControlSuccess());
|
emit(DeviceControlSuccess());
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
emit(DeviceControlError(ServerFailure.fromDioError(e).errMessage));
|
emit(DeviceControlError(ServerFailure.fromDioError(e).errMessage));
|
||||||
@ -461,12 +451,18 @@ class DevicesCubit extends Cubit<DevicesState> {
|
|||||||
fetchGroups(
|
fetchGroups(
|
||||||
SpaceModel space,
|
SpaceModel space,
|
||||||
) async {
|
) async {
|
||||||
emit(DevicesCategoriesLoading());
|
|
||||||
try {
|
try {
|
||||||
allCategories = await DevicesAPI.fetchGroups(space.id!);
|
if (state is! DevicesCategoriesLoading) {
|
||||||
|
emit(DevicesCategoriesLoading());
|
||||||
|
allCategories = await DevicesAPI.fetchGroups(space.id!);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
emit(DevicesCategoriesSuccess());
|
emit(DevicesCategoriesSuccess());
|
||||||
} on DioException catch (e) {
|
} on DioException catch (error) {
|
||||||
emit(DevicesCategoriesError(ServerFailure.fromDioError(e).errMessage));
|
emit(
|
||||||
|
DevicesCategoriesError(ServerFailure.fromDioError(error).errMessage),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ class DevicesFailure extends DevicesState {}
|
|||||||
|
|
||||||
class ChangeIndex extends DevicesState {}
|
class ChangeIndex extends DevicesState {}
|
||||||
|
|
||||||
|
// Devices
|
||||||
class DevicesCategoryChanged extends DevicesState {}
|
class DevicesCategoryChanged extends DevicesState {}
|
||||||
|
|
||||||
class CategorySwitchChanged extends DevicesState {}
|
class CategorySwitchChanged extends DevicesState {}
|
||||||
@ -21,6 +22,7 @@ class DeviceSwitchChanged extends DevicesState {}
|
|||||||
|
|
||||||
class DeviceSelected extends DevicesState {}
|
class DeviceSelected extends DevicesState {}
|
||||||
|
|
||||||
|
// Device Control
|
||||||
class DeviceControlLoading extends DevicesState {}
|
class DeviceControlLoading extends DevicesState {}
|
||||||
|
|
||||||
class DeviceControlSuccess extends DevicesState {}
|
class DeviceControlSuccess extends DevicesState {}
|
||||||
@ -31,6 +33,7 @@ class DeviceControlError extends DevicesState {
|
|||||||
DeviceControlError(this.errorMsg);
|
DeviceControlError(this.errorMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Categories
|
||||||
class DevicesCategoriesLoading extends DevicesState {}
|
class DevicesCategoriesLoading extends DevicesState {}
|
||||||
|
|
||||||
class DevicesCategoriesSuccess extends DevicesState {}
|
class DevicesCategoriesSuccess extends DevicesState {}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// ignore_for_file: constant_identifier_names
|
// ignore_for_file: constant_identifier_names
|
||||||
|
|
||||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_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 DevicesCategoryModel {
|
class DevicesCategoryModel {
|
||||||
@ -40,10 +41,16 @@ class DevicesCategoryModel {
|
|||||||
DevicesCategoryModel.fromJson(Map<String, dynamic> json)
|
DevicesCategoryModel.fromJson(Map<String, dynamic> json)
|
||||||
: name = json['groupName'],
|
: name = json['groupName'],
|
||||||
id = json['groupId'],
|
id = json['groupId'],
|
||||||
icon = json['icon'],
|
|
||||||
type = deviceTypeMap[json['groupName']] ?? DeviceType.Other,
|
type = deviceTypeMap[json['groupName']] ?? DeviceType.Other,
|
||||||
|
icon = deviceTypeIconMap[
|
||||||
|
deviceTypeMap[json['groupName']] ?? DeviceType.Other] ??
|
||||||
|
'',
|
||||||
devices = [],
|
devices = [],
|
||||||
isSelected = false;
|
isSelected = false;
|
||||||
|
|
||||||
|
static List<DevicesCategoryModel> fromJsonList(List<dynamic> jsonList) {
|
||||||
|
return jsonList.map((item) => DevicesCategoryModel.fromJson(item)).toList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, DeviceType> deviceTypeMap = {
|
Map<String, DeviceType> deviceTypeMap = {
|
||||||
@ -52,4 +59,16 @@ Map<String, DeviceType> deviceTypeMap = {
|
|||||||
'Door Locks': DeviceType.DoorLock,
|
'Door Locks': DeviceType.DoorLock,
|
||||||
'Gateways': DeviceType.Gateway,
|
'Gateways': DeviceType.Gateway,
|
||||||
'ACs': DeviceType.AC,
|
'ACs': DeviceType.AC,
|
||||||
|
'3Gang': DeviceType.Gang,
|
||||||
|
};
|
||||||
|
|
||||||
|
Map<DeviceType, String> deviceTypeIconMap = {
|
||||||
|
DeviceType.AC: Assets.iconsAC,
|
||||||
|
DeviceType.Lights: Assets.iconsLight,
|
||||||
|
DeviceType.DoorLock: Assets.iconsDoorLock,
|
||||||
|
DeviceType.Curtain: Assets.iconsCurtain,
|
||||||
|
DeviceType.Gateway: Assets.iconsGateway,
|
||||||
|
DeviceType.Sensors: Assets.iconsSensors,
|
||||||
|
DeviceType.Gang: Assets.iconsGang,
|
||||||
|
DeviceType.Other: Assets.iconsAC,
|
||||||
};
|
};
|
||||||
|
@ -23,8 +23,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) {
|
||||||
print(
|
|
||||||
"length : ${SpacesCubit.get(context).selectedSpace!.rooms!.length}");
|
|
||||||
//TODO : move to NavigationCubit
|
//TODO : move to NavigationCubit
|
||||||
if (state is DevicesLoading) {
|
if (state is DevicesLoading) {
|
||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: CircularProgressIndicator());
|
||||||
@ -51,15 +49,9 @@ class DevicesViewBody extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
const WizardPage(),
|
const WizardPage(),
|
||||||
if (SpacesCubit.get(context).selectedSpace != null)
|
if (SpacesCubit.selectedSpace != null)
|
||||||
if (SpacesCubit.get(context)
|
if (SpacesCubit.selectedSpace!.rooms != null)
|
||||||
.selectedSpace!
|
...SpacesCubit.selectedSpace!.rooms!.map(
|
||||||
.rooms !=
|
|
||||||
null)
|
|
||||||
...SpacesCubit.get(context)
|
|
||||||
.selectedSpace!
|
|
||||||
.rooms!
|
|
||||||
.map(
|
|
||||||
(room) {
|
(room) {
|
||||||
return RoomPage(
|
return RoomPage(
|
||||||
room: room,
|
room: room,
|
||||||
@ -76,11 +68,7 @@ class DevicesViewBody extends StatelessWidget {
|
|||||||
child: SmoothPageIndicator(
|
child: SmoothPageIndicator(
|
||||||
controller:
|
controller:
|
||||||
SpacesCubit.get(context).devicesPageController,
|
SpacesCubit.get(context).devicesPageController,
|
||||||
count: SpacesCubit.get(context)
|
count: SpacesCubit.selectedSpace!.rooms!.length + 1,
|
||||||
.selectedSpace!
|
|
||||||
.rooms!
|
|
||||||
.length +
|
|
||||||
1,
|
|
||||||
effect: const WormEffect(
|
effect: const WormEffect(
|
||||||
paintStyle: PaintingStyle.stroke,
|
paintStyle: PaintingStyle.stroke,
|
||||||
dotHeight: 8,
|
dotHeight: 8,
|
||||||
|
@ -26,6 +26,7 @@ class LightSwitch extends StatelessWidget {
|
|||||||
DevicesCubit.get(context)
|
DevicesCubit.get(context)
|
||||||
.deviceControl(control)
|
.deviceControl(control)
|
||||||
.then((value) {
|
.then((value) {
|
||||||
|
print('Device control response: $value');
|
||||||
if (control.value ?? true) {
|
if (control.value ?? true) {
|
||||||
control.value = false;
|
control.value = false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -25,26 +25,65 @@ class LightSwitchesBody extends StatelessWidget {
|
|||||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
LightSwitch(
|
Column(
|
||||||
control: DeviceControlModel(
|
children: [
|
||||||
deviceId: 'bfe10693d4fd263206ocq9',
|
LightSwitch(
|
||||||
code: 'switch_1',
|
control: DeviceControlModel(
|
||||||
value: true,
|
deviceId: 'bfe10693d4fd263206ocq9',
|
||||||
),
|
code: 'switch_1',
|
||||||
|
value: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
const SizedBox(
|
||||||
|
width: 70,
|
||||||
|
child: BodySmall(
|
||||||
|
text: "Bedside Light",
|
||||||
|
fontColor: ColorsManager.textPrimaryColor,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
LightSwitch(
|
Column(
|
||||||
control: DeviceControlModel(
|
children: [
|
||||||
deviceId: 'bfe10693d4fd263206ocq9',
|
LightSwitch(
|
||||||
code: 'switch_2',
|
control: DeviceControlModel(
|
||||||
value: true,
|
deviceId: 'bfe10693d4fd263206ocq9',
|
||||||
),
|
code: 'switch_2',
|
||||||
|
value: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
const SizedBox(
|
||||||
|
width: 70,
|
||||||
|
child: BodySmall(
|
||||||
|
text: "Ceiling Light",
|
||||||
|
fontColor: ColorsManager.textPrimaryColor,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
LightSwitch(
|
Column(
|
||||||
control: DeviceControlModel(
|
children: [
|
||||||
deviceId: 'bfe10693d4fd263206ocq9',
|
LightSwitch(
|
||||||
code: 'switch_3',
|
control: DeviceControlModel(
|
||||||
value: true,
|
deviceId: 'bfe10693d4fd263206ocq9',
|
||||||
),
|
code: 'switch_3',
|
||||||
|
value: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
const SizedBox(
|
||||||
|
width: 70,
|
||||||
|
child: BodySmall(
|
||||||
|
text: "Spotlight",
|
||||||
|
fontColor: ColorsManager.textPrimaryColor,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -40,33 +40,29 @@ class RoomsSlider extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (SpacesCubit.get(context).selectedSpace != null)
|
if (SpacesCubit.selectedSpace != null)
|
||||||
if (SpacesCubit.get(context).selectedSpace!.rooms != null)
|
if (SpacesCubit.selectedSpace!.rooms != null)
|
||||||
...SpacesCubit.get(context).selectedSpace!.rooms!.map(
|
...SpacesCubit.selectedSpace!.rooms!.map(
|
||||||
(room) => Padding(
|
(room) => Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 15),
|
padding: const EdgeInsets.symmetric(horizontal: 15),
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
SpacesCubit.get(context).roomSliderPageChanged(
|
SpacesCubit.get(context).roomSliderPageChanged(
|
||||||
SpacesCubit.get(context)
|
SpacesCubit.selectedSpace!.rooms!.indexOf(room));
|
||||||
.selectedSpace!
|
},
|
||||||
.rooms!
|
child: TitleMedium(
|
||||||
.indexOf(room));
|
text: room.name!,
|
||||||
},
|
style: context.titleMedium.copyWith(
|
||||||
child: TitleMedium(
|
fontSize: 25,
|
||||||
text: room.name!,
|
color: SpacesCubit.get(context).selectedRoom == room
|
||||||
style: context.titleMedium.copyWith(
|
? ColorsManager.textPrimaryColor
|
||||||
fontSize: 25,
|
: ColorsManager.textPrimaryColor
|
||||||
color: SpacesCubit.get(context).selectedRoom ==
|
.withOpacity(.2),
|
||||||
room
|
|
||||||
? ColorsManager.textPrimaryColor
|
|
||||||
: ColorsManager.textPrimaryColor
|
|
||||||
.withOpacity(.2),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -18,68 +18,72 @@ class WizartSwitches extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return GridView.builder(
|
return state is DevicesLoading
|
||||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
? const Center(child: CircularProgressIndicator())
|
||||||
crossAxisCount: 2,
|
: GridView.builder(
|
||||||
crossAxisSpacing: 10,
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
mainAxisSpacing: 10,
|
crossAxisCount: 2,
|
||||||
childAspectRatio: 1.5,
|
crossAxisSpacing: 10,
|
||||||
),
|
mainAxisSpacing: 10,
|
||||||
padding: const EdgeInsets.only(top: 10),
|
childAspectRatio: 1.5,
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
),
|
||||||
shrinkWrap: true,
|
padding: const EdgeInsets.only(top: 10),
|
||||||
itemCount: DevicesCubit.allCategories.length,
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
itemBuilder: (_, index) {
|
shrinkWrap: true,
|
||||||
return InkWell(
|
itemCount: DevicesCubit.allCategories.length,
|
||||||
onTap: () {
|
itemBuilder: (_, index) {
|
||||||
DevicesCubit.get(context).selectCategory(index);
|
return InkWell(
|
||||||
//Navigate to the chosen category view without animation
|
onTap: () {
|
||||||
|
DevicesCubit.get(context).selectCategory(index);
|
||||||
|
//Navigate to the chosen category view without animation
|
||||||
|
|
||||||
Navigator.push(context, CustomPageRoute(builder: (context) {
|
Navigator.push(context,
|
||||||
return DevicesCubit.get(context).chosenCategoryView!;
|
CustomPageRoute(builder: (context) {
|
||||||
}));
|
return DevicesCubit.get(context).chosenCategoryView!;
|
||||||
},
|
}));
|
||||||
child: DefaultContainer(
|
},
|
||||||
child: Padding(
|
child: DefaultContainer(
|
||||||
padding: const EdgeInsets.only(top: 10, right: 10, left: 10),
|
child: Padding(
|
||||||
child: Column(
|
padding:
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
const EdgeInsets.only(top: 10, right: 10, left: 10),
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
child: Column(
|
||||||
children: [
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
Row(
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
children: [
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
Row(
|
||||||
children: [
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
SvgPicture.asset(
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
DevicesCubit.allCategories[index].icon!,
|
children: [
|
||||||
fit: BoxFit.contain,
|
SvgPicture.asset(
|
||||||
),
|
DevicesCubit.allCategories[index].icon!,
|
||||||
CustomSwitch(
|
fit: BoxFit.contain,
|
||||||
category: DevicesCubit.allCategories[index],
|
),
|
||||||
),
|
CustomSwitch(
|
||||||
],
|
category: DevicesCubit.allCategories[index],
|
||||||
),
|
),
|
||||||
Expanded(
|
],
|
||||||
child: FittedBox(
|
|
||||||
fit: BoxFit.scaleDown,
|
|
||||||
child: BodyLarge(
|
|
||||||
text: DevicesCubit.allCategories[index].name!,
|
|
||||||
style: context.bodyLarge.copyWith(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
height: 0,
|
|
||||||
fontSize: 24,
|
|
||||||
color: Colors.grey,
|
|
||||||
),
|
),
|
||||||
),
|
Expanded(
|
||||||
|
child: FittedBox(
|
||||||
|
fit: BoxFit.scaleDown,
|
||||||
|
child: BodyLarge(
|
||||||
|
text: DevicesCubit.allCategories[index].name!,
|
||||||
|
style: context.bodyLarge.copyWith(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
height: 0,
|
||||||
|
fontSize: 24,
|
||||||
|
color: Colors.grey,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
);
|
||||||
),
|
},
|
||||||
),
|
);
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ class BodySmall extends StatelessWidget {
|
|||||||
this.fontColor,
|
this.fontColor,
|
||||||
this.fontSize,
|
this.fontSize,
|
||||||
this.fontWeight,
|
this.fontWeight,
|
||||||
|
this.textAlign,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String text;
|
final String text;
|
||||||
@ -20,6 +21,8 @@ class BodySmall extends StatelessWidget {
|
|||||||
final double? fontSize;
|
final double? fontSize;
|
||||||
final FontWeight? fontWeight;
|
final FontWeight? fontWeight;
|
||||||
|
|
||||||
|
final TextAlign? textAlign;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => CustomText(
|
Widget build(BuildContext context) => CustomText(
|
||||||
text,
|
text,
|
||||||
@ -27,5 +30,6 @@ class BodySmall extends StatelessWidget {
|
|||||||
fontColor: fontColor,
|
fontColor: fontColor,
|
||||||
fontSize: fontSize,
|
fontSize: fontSize,
|
||||||
fontWeight: fontWeight,
|
fontWeight: fontWeight,
|
||||||
|
textAlign: textAlign,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ class Assets {
|
|||||||
static const String iconsFan3 = 'assets/icons/fan-3.svg';
|
static const String iconsFan3 = 'assets/icons/fan-3.svg';
|
||||||
static const String iconsFilter = 'assets/icons/filter.png';
|
static const String iconsFilter = 'assets/icons/filter.png';
|
||||||
static const String iconsFrequency = 'assets/icons/frequency.svg';
|
static const String iconsFrequency = 'assets/icons/frequency.svg';
|
||||||
|
static const String iconsGang = 'assets/icons/gang.svg';
|
||||||
static const String iconsGateway = 'assets/icons/Gateway.svg';
|
static const String iconsGateway = 'assets/icons/Gateway.svg';
|
||||||
static const String iconsGoogle = 'assets/icons/Google.svg';
|
static const String iconsGoogle = 'assets/icons/Google.svg';
|
||||||
static const String iconsHome = 'assets/icons/home.svg';
|
static const String iconsHome = 'assets/icons/home.svg';
|
||||||
@ -50,6 +51,7 @@ class Assets {
|
|||||||
static const String iconsRoutinesFill = 'assets/icons/Routines-fill.svg';
|
static const String iconsRoutinesFill = 'assets/icons/Routines-fill.svg';
|
||||||
static const String iconsScan = 'assets/icons/Scan.svg';
|
static const String iconsScan = 'assets/icons/Scan.svg';
|
||||||
static const String iconsScreen = 'assets/icons/Screen.svg';
|
static const String iconsScreen = 'assets/icons/Screen.svg';
|
||||||
|
static const String iconsSensors = 'assets/icons/sensors.svg';
|
||||||
static const String iconsSettings = 'assets/icons/settings.png';
|
static const String iconsSettings = 'assets/icons/settings.png';
|
||||||
static const String iconsSummer = 'assets/icons/Summer.svg';
|
static const String iconsSummer = 'assets/icons/Summer.svg';
|
||||||
static const String iconsSummerMode = 'assets/icons/summer_mode.svg';
|
static const String iconsSummerMode = 'assets/icons/summer_mode.svg';
|
||||||
|
@ -16,4 +16,7 @@ abstract class ApiEndpoints {
|
|||||||
|
|
||||||
// Devices
|
// Devices
|
||||||
static const String control = '$baseUrl/device/control';
|
static const String control = '$baseUrl/device/control';
|
||||||
|
|
||||||
|
//groups
|
||||||
|
static const String groups = '$baseUrl/group';
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,11 @@ import 'package:syncrow_app/services/api/api_links_endpoints.dart';
|
|||||||
import 'package:syncrow_app/services/api/http_service.dart';
|
import 'package:syncrow_app/services/api/http_service.dart';
|
||||||
|
|
||||||
class DevicesAPI {
|
class DevicesAPI {
|
||||||
|
static final HTTPService _httpService = HTTPService();
|
||||||
|
|
||||||
static Future<Map<String, dynamic>> controlDevice(
|
static Future<Map<String, dynamic>> controlDevice(
|
||||||
DeviceControlModel controlModel) async {
|
DeviceControlModel controlModel) async {
|
||||||
final response = await HTTPService().post(
|
final response = await _httpService.post(
|
||||||
path: ApiEndpoints.control,
|
path: ApiEndpoints.control,
|
||||||
body: controlModel.toJson(),
|
body: controlModel.toJson(),
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
@ -18,18 +20,20 @@ class DevicesAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Future<List<DevicesCategoryModel>> fetchGroups(int spaceId) async {
|
static Future<List<DevicesCategoryModel>> fetchGroups(int spaceId) async {
|
||||||
final response = await HTTPService().get(
|
Map<String, dynamic> params = {
|
||||||
path: ApiEndpoints.control,
|
"homeId": spaceId,
|
||||||
queryParameters: {'homeId': spaceId, 'pageSize': 100, 'page': 1},
|
"pageSize": 100,
|
||||||
|
"page": 1
|
||||||
|
};
|
||||||
|
final response = await _httpService.get(
|
||||||
|
path:
|
||||||
|
"https://syncrow.azurewebsites.net/group?homeId=$spaceId&pageSize=100&pageNo=1",
|
||||||
|
// path: ApiEndpoints.groups,
|
||||||
|
// queryParameters: params,
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) =>
|
||||||
List<DevicesCategoryModel> categories = [];
|
DevicesCategoryModel.fromJsonList(json['groups']),
|
||||||
for (var category in json['groups']) {
|
|
||||||
categories.add(DevicesCategoryModel.fromJson(category));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
print('fetchGroups response: $response');
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,10 +12,10 @@ class HTTPInterceptor extends InterceptorsWrapper {
|
|||||||
@override
|
@override
|
||||||
void onRequest(
|
void onRequest(
|
||||||
RequestOptions options, RequestInterceptorHandler handler) async {
|
RequestOptions options, RequestInterceptorHandler handler) async {
|
||||||
var storage = FlutterSecureStorage();
|
var storage = const FlutterSecureStorage();
|
||||||
var token = await storage.read(key: Token.loginAccessTokenKey);
|
var token = await storage.read(key: Token.loginAccessTokenKey);
|
||||||
options.headers['Authorization'] = 'Bearer $token';
|
|
||||||
|
|
||||||
|
options.headers['Authorization'] = 'Bearer $token';
|
||||||
super.onRequest(options, handler);
|
super.onRequest(options, handler);
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
@ -44,6 +44,7 @@ class HTTPService {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
debugPrint("******* Error");
|
debugPrint("******* Error");
|
||||||
debugPrint(error.toString());
|
debugPrint(error.toString());
|
||||||
|
debugPrint("******* Error End");
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,29 +6,25 @@ import 'package:syncrow_app/services/api/api_links_endpoints.dart';
|
|||||||
import 'package:syncrow_app/services/api/http_service.dart';
|
import 'package:syncrow_app/services/api/http_service.dart';
|
||||||
|
|
||||||
class SpacesAPI {
|
class SpacesAPI {
|
||||||
|
static final HTTPService _httpService = HTTPService();
|
||||||
|
|
||||||
static Future<List<SpaceModel>> getSpaces() async {
|
static Future<List<SpaceModel>> getSpaces() async {
|
||||||
var uuid =
|
var uuid =
|
||||||
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
||||||
final response = await HTTPService().get(
|
final response = await _httpService.get(
|
||||||
path: ApiEndpoints.spaces,
|
path: ApiEndpoints.spaces,
|
||||||
queryParameters: {
|
queryParameters: {
|
||||||
"userUuid": uuid,
|
"userUuid": uuid,
|
||||||
},
|
},
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) => SpaceModel.fromJsonList(json),
|
||||||
List<SpaceModel> spaces = [];
|
|
||||||
for (var space in json) {
|
|
||||||
spaces.add(SpaceModel.fromJson(space));
|
|
||||||
}
|
|
||||||
return spaces;
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
//get rooms by space id
|
//get rooms by space id
|
||||||
static Future<List<RoomModel>> getRooms(int spaceId) async {
|
static Future<List<RoomModel>> getRooms(int spaceId) async {
|
||||||
final response = await HTTPService().get(
|
final response = await _httpService.get(
|
||||||
path: ApiEndpoints.rooms,
|
path: ApiEndpoints.rooms,
|
||||||
queryParameters: {"homeId": spaceId},
|
queryParameters: {"homeId": spaceId},
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
|
@ -22,5 +22,6 @@ enum DeviceType {
|
|||||||
ThreeGang,
|
ThreeGang,
|
||||||
Gateway,
|
Gateway,
|
||||||
Sensors,
|
Sensors,
|
||||||
|
Gang,
|
||||||
Other,
|
Other,
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user