mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 09:45:22 +00:00
271 lines
7.5 KiB
Dart
271 lines
7.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
|
import 'package:syncrow_app/features/devices/model/ac_model.dart';
|
|
import 'package:syncrow_app/features/devices/model/curtain_model.dart';
|
|
import 'package:syncrow_app/features/devices/model/device_category_model.dart';
|
|
import 'package:syncrow_app/features/devices/model/light_model.dart';
|
|
import 'package:syncrow_app/features/devices/model/room_model.dart';
|
|
import 'package:syncrow_app/features/devices/view/widgets/ACs/acs_view.dart';
|
|
import 'package:syncrow_app/features/devices/view/widgets/curtains/curtain_view.dart';
|
|
import 'package:syncrow_app/features/devices/view/widgets/gateway/gateway_view.dart';
|
|
import 'package:syncrow_app/features/devices/view/widgets/lights/lights_view.dart';
|
|
import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_view.dart';
|
|
import 'package:syncrow_app/generated/assets.dart';
|
|
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
|
|
|
part 'spaces_state.dart';
|
|
|
|
class SpacesCubit extends Cubit<SpacesState> {
|
|
SpacesCubit() : super(SpacesInitial());
|
|
|
|
static SpacesCubit get(context) => BlocProvider.of(context);
|
|
|
|
static List<SpaceModel> spaces = [
|
|
SpaceModel(
|
|
id: '0',
|
|
name: 'Home',
|
|
rooms: [
|
|
RoomModel(id: '0', name: 'Living Room', categories: [
|
|
DevicesCategoryModel(
|
|
devices: [
|
|
ACModel(
|
|
name: "Living Room AC",
|
|
id: '0',
|
|
status: false,
|
|
temperature: 20,
|
|
fanSpeed: 0,
|
|
tempMode: 0,
|
|
coolTo: 20,
|
|
type: DeviceType.AC,
|
|
image: '',
|
|
timer: null,
|
|
bounds: Bounds(
|
|
min: 20,
|
|
max: 30,
|
|
),
|
|
),
|
|
],
|
|
icon: Assets.iconsAC,
|
|
name: 'ACs',
|
|
type: DeviceType.AC,
|
|
page: const ACsView(),
|
|
),
|
|
DevicesCategoryModel(
|
|
devices: [
|
|
LightModel(
|
|
name: "Living Room Light",
|
|
id: '0',
|
|
status: false,
|
|
color: 0,
|
|
brightness: 20,
|
|
lightingMode: 1,
|
|
timer: null,
|
|
type: DeviceType.Lights,
|
|
image: '',
|
|
recentColors: [
|
|
0xFF83D9FF,
|
|
0xFFFC3E81,
|
|
0xFFC0FF66,
|
|
0xFFFDC242,
|
|
],
|
|
),
|
|
],
|
|
icon: Assets.iconsLight,
|
|
name: 'Lights',
|
|
type: DeviceType.Lights,
|
|
page: const LightsView(),
|
|
),
|
|
DevicesCategoryModel(
|
|
devices: [],
|
|
icon: Assets.iconsDoorLock,
|
|
name: 'Doors',
|
|
type: DeviceType.Door,
|
|
page: const DoorView(),
|
|
),
|
|
DevicesCategoryModel(
|
|
devices: [
|
|
CurtainModel(
|
|
openPercentage: 10,
|
|
id: "1",
|
|
name: "Living Room Curtain",
|
|
status: false,
|
|
type: DeviceType.Curtain,
|
|
image: '',
|
|
timer: null,
|
|
),
|
|
],
|
|
icon: Assets.iconsCurtain,
|
|
name: 'Curtains',
|
|
type: DeviceType.Curtain,
|
|
page: const CurtainView(),
|
|
),
|
|
DevicesCategoryModel(
|
|
devices: [],
|
|
icon: Assets.iconsGateway,
|
|
name: 'Gateway',
|
|
type: DeviceType.Gateway,
|
|
page: const GateWayView(),
|
|
),
|
|
]),
|
|
RoomModel(id: '1', name: 'Bedroom', categories: [
|
|
DevicesCategoryModel(
|
|
devices: [
|
|
ACModel(
|
|
name: "Living Room AC",
|
|
id: '0',
|
|
status: false,
|
|
temperature: 20,
|
|
fanSpeed: 0,
|
|
tempMode: 0,
|
|
coolTo: 20,
|
|
type: DeviceType.AC,
|
|
image: '',
|
|
timer: null,
|
|
bounds: Bounds(
|
|
min: 20,
|
|
max: 30,
|
|
),
|
|
),
|
|
],
|
|
icon: Assets.iconsAC,
|
|
name: 'ACs',
|
|
type: DeviceType.AC,
|
|
page: const ACsView(),
|
|
),
|
|
DevicesCategoryModel(
|
|
devices: [
|
|
LightModel(
|
|
name: "Living Room Light",
|
|
id: '0',
|
|
status: false,
|
|
color: 0,
|
|
brightness: 20,
|
|
lightingMode: 1,
|
|
timer: null,
|
|
type: DeviceType.Lights,
|
|
image: '',
|
|
recentColors: [
|
|
0xFF83D9FF,
|
|
0xFFFC3E81,
|
|
0xFFC0FF66,
|
|
0xFFFDC242,
|
|
],
|
|
),
|
|
],
|
|
icon: Assets.iconsLight,
|
|
name: 'Lights',
|
|
type: DeviceType.Lights,
|
|
page: const LightsView(),
|
|
),
|
|
DevicesCategoryModel(
|
|
devices: [],
|
|
icon: Assets.iconsDoorLock,
|
|
name: 'Doors',
|
|
type: DeviceType.Door,
|
|
page: const DoorView(),
|
|
),
|
|
DevicesCategoryModel(
|
|
devices: [
|
|
CurtainModel(
|
|
openPercentage: 10,
|
|
id: "1",
|
|
name: "Living Room Curtain",
|
|
status: false,
|
|
type: DeviceType.Curtain,
|
|
image: '',
|
|
timer: null,
|
|
),
|
|
],
|
|
icon: Assets.iconsCurtain,
|
|
name: 'Curtains',
|
|
type: DeviceType.Curtain,
|
|
page: const CurtainView(),
|
|
),
|
|
DevicesCategoryModel(
|
|
devices: [],
|
|
icon: Assets.iconsGateway,
|
|
name: 'Gateway',
|
|
type: DeviceType.Gateway,
|
|
page: const GateWayView(),
|
|
),
|
|
]),
|
|
],
|
|
),
|
|
SpaceModel(
|
|
id: '1',
|
|
name: 'Office',
|
|
rooms: [],
|
|
),
|
|
SpaceModel(
|
|
id: '2',
|
|
name: 'Parent\'s House',
|
|
rooms: [],
|
|
),
|
|
];
|
|
|
|
SpaceModel selectedSpace = spaces.first;
|
|
|
|
RoomModel? selectedRoom;
|
|
|
|
PageController devicesPageController = PageController();
|
|
|
|
PageController roomsPageController = PageController();
|
|
|
|
var duration = const Duration(milliseconds: 300);
|
|
|
|
selectSpace(SpaceModel space) {
|
|
selectedSpace = space;
|
|
emit(SpacesSelected(space));
|
|
}
|
|
|
|
roomSliderPageChanged(int index) {
|
|
devicesPageController.animateToPage(
|
|
index,
|
|
duration: duration,
|
|
curve: Curves.linear,
|
|
);
|
|
|
|
if (index == 0) {
|
|
unselectRoom();
|
|
} else {
|
|
selectedRoom = selectedSpace.rooms[index - 1];
|
|
}
|
|
emit(RoomSelected(selectedRoom!));
|
|
}
|
|
|
|
devicesPageChanged(int index) {
|
|
roomsPageController.animateToPage(
|
|
index,
|
|
duration: const Duration(milliseconds: 300),
|
|
curve: Curves.linear,
|
|
);
|
|
|
|
if (index == 0) {
|
|
unselectRoom();
|
|
} else {
|
|
selectedRoom = selectedSpace.rooms[index - 1];
|
|
}
|
|
emit(RoomSelected(selectedRoom!));
|
|
}
|
|
|
|
unselectRoom() {
|
|
selectedRoom = null;
|
|
devicesPageController.animateToPage(
|
|
0,
|
|
duration: duration,
|
|
curve: Curves.linear,
|
|
);
|
|
|
|
roomsPageController.animateToPage(
|
|
0,
|
|
duration: duration,
|
|
curve: Curves.linear,
|
|
);
|
|
|
|
emit(RoomUnSelected());
|
|
}
|
|
|
|
//TODO implement the methods to fetch the spaces from the API
|
|
}
|