mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 17:47:28 +00:00
Refactor device control logic and add temperature and fan speed enums
- Refactor device control logic in the app to improve readability and maintainability. - Add temperature modes (hot, cold, wind) and fan speeds (auto, low, middle, high) enums. - Update icon mappings and utility functions for temperature modes and fan speeds.
This commit is contained in:
@ -18,8 +18,6 @@ import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
|||||||
part 'home_state.dart';
|
part 'home_state.dart';
|
||||||
|
|
||||||
class HomeCubit extends Cubit<HomeState> {
|
class HomeCubit extends Cubit<HomeState> {
|
||||||
// Create a private static instance variable
|
|
||||||
|
|
||||||
HomeCubit._() : super(HomeInitial()) {
|
HomeCubit._() : super(HomeInitial()) {
|
||||||
if (selectedSpace == null) {
|
if (selectedSpace == null) {
|
||||||
fetchSpaces().then((value) {
|
fetchSpaces().then((value) {
|
||||||
@ -37,6 +35,13 @@ class HomeCubit extends Cubit<HomeState> {
|
|||||||
return _instance!;
|
return _instance!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void emitSafe(HomeState newState) {
|
||||||
|
final cubit = this;
|
||||||
|
if (!cubit.isClosed) {
|
||||||
|
cubit.emit(newState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static HomeCubit get(context) => BlocProvider.of(context);
|
static HomeCubit get(context) => BlocProvider.of(context);
|
||||||
|
|
||||||
List<SpaceModel>? spaces;
|
List<SpaceModel>? spaces;
|
||||||
@ -58,7 +63,7 @@ class HomeCubit extends Cubit<HomeState> {
|
|||||||
|
|
||||||
changeSelectedSpace(SpaceModel space) {
|
changeSelectedSpace(SpaceModel space) {
|
||||||
selectedSpace = space;
|
selectedSpace = space;
|
||||||
emit(SpaceSelected(space));
|
emitSafe(SpaceSelected(space));
|
||||||
}
|
}
|
||||||
|
|
||||||
roomSliderPageChanged(int index) {
|
roomSliderPageChanged(int index) {
|
||||||
@ -72,7 +77,7 @@ class HomeCubit extends Cubit<HomeState> {
|
|||||||
unselectRoom();
|
unselectRoom();
|
||||||
} else {
|
} else {
|
||||||
selectedRoom = selectedSpace!.rooms![index - 1];
|
selectedRoom = selectedSpace!.rooms![index - 1];
|
||||||
emit(RoomSelected(selectedRoom!));
|
emitSafe(RoomSelected(selectedRoom!));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +92,7 @@ class HomeCubit extends Cubit<HomeState> {
|
|||||||
unselectRoom();
|
unselectRoom();
|
||||||
} else {
|
} else {
|
||||||
selectedRoom = selectedSpace!.rooms![index - 1];
|
selectedRoom = selectedSpace!.rooms![index - 1];
|
||||||
emit(RoomSelected(selectedRoom!));
|
emitSafe(RoomSelected(selectedRoom!));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,11 +110,11 @@ class HomeCubit extends Cubit<HomeState> {
|
|||||||
curve: Curves.linear,
|
curve: Curves.linear,
|
||||||
);
|
);
|
||||||
|
|
||||||
emit(RoomUnSelected());
|
emitSafe(RoomUnSelected());
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchSpaces() async {
|
fetchSpaces() async {
|
||||||
emit(GetSpacesLoading());
|
emitSafe(GetSpacesLoading());
|
||||||
try {
|
try {
|
||||||
spaces = await SpacesAPI.getSpaces();
|
spaces = await SpacesAPI.getSpaces();
|
||||||
selectedSpace = spaces!.isNotEmpty
|
selectedSpace = spaces!.isNotEmpty
|
||||||
@ -117,23 +122,23 @@ class HomeCubit extends Cubit<HomeState> {
|
|||||||
// selectSpace(spaces!.first)
|
// selectSpace(spaces!.first)
|
||||||
selectedSpace = spaces!.first
|
selectedSpace = spaces!.first
|
||||||
: null;
|
: null;
|
||||||
emit(GetSpacesLoaded(spaces!));
|
emitSafe(GetSpacesLoaded(spaces!));
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
emit(GetSpacesError(ServerFailure.fromDioError(e).errMessage));
|
emitSafe(GetSpacesError(ServerFailure.fromDioError(e).errMessage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchRooms(SpaceModel space) async {
|
fetchRooms(SpaceModel space) async {
|
||||||
emit(GetSpaceRoomsLoading());
|
emitSafe(GetSpaceRoomsLoading());
|
||||||
try {
|
try {
|
||||||
space.rooms = await SpacesAPI.getRoomsBySpaceId(space.id!);
|
space.rooms = await SpacesAPI.getRoomsBySpaceId(space.id!);
|
||||||
if (space.rooms != null) {
|
if (space.rooms != null) {
|
||||||
emit(GetSpaceRoomsLoaded(space.rooms!));
|
emitSafe(GetSpaceRoomsLoaded(space.rooms!));
|
||||||
} else {
|
} else {
|
||||||
emit(GetSpaceRoomsError("No rooms found"));
|
emitSafe(GetSpaceRoomsError("No rooms found"));
|
||||||
}
|
}
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
emit(GetSpacesError(ServerFailure.fromDioError(e).errMessage));
|
emitSafe(GetSpacesError(ServerFailure.fromDioError(e).errMessage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +267,7 @@ class HomeCubit extends Cubit<HomeState> {
|
|||||||
const DashboardView(),
|
const DashboardView(),
|
||||||
// const LayoutPage(),
|
// const LayoutPage(),
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (context) => DevicesCubit(),
|
create: (context) => DevicesCubit.getInstance(),
|
||||||
child: const DevicesViewBody(),
|
child: const DevicesViewBody(),
|
||||||
),
|
),
|
||||||
const SceneView(),
|
const SceneView(),
|
||||||
@ -272,7 +277,7 @@ class HomeCubit extends Cubit<HomeState> {
|
|||||||
void updatePageIndex(int index) {
|
void updatePageIndex(int index) {
|
||||||
pageIndex = index;
|
pageIndex = index;
|
||||||
|
|
||||||
emit(NavChangePage());
|
emitSafe(NavChangePage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ class DefaultNavBar extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => DevicesCubit(),
|
create: (context) => DevicesCubit.getInstance(),
|
||||||
child: BlocBuilder<DevicesCubit, DevicesState>(
|
child: BlocBuilder<DevicesCubit, DevicesState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return BlocBuilder<HomeCubit, HomeState>(
|
return BlocBuilder<HomeCubit, HomeState>(
|
||||||
@ -26,8 +26,8 @@ class DefaultNavBar extends StatelessWidget {
|
|||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
onTap: (int index) {
|
onTap: (int index) {
|
||||||
cubit.updatePageIndex(index);
|
cubit.updatePageIndex(index);
|
||||||
if (DevicesCubit.get(context).chosenCategoryView != null) {
|
if (DevicesCubit.getInstance().chosenCategoryView != null) {
|
||||||
DevicesCubit.get(context)
|
DevicesCubit.getInstance()
|
||||||
.clearCategoriesSelection(context);
|
.clearCategoriesSelection(context);
|
||||||
}
|
}
|
||||||
if (HomeCubit.getInstance().selectedRoom != null) {
|
if (HomeCubit.getInstance().selectedRoom != null) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
|
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_mode_control_unit.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_mode_control_unit.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||||
@ -16,9 +18,11 @@ class AcInterfaceControls extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||||
|
builder: (context, state) {
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
ACModeControlUnit(model: deviceModel),
|
ACModeControlUnit(acDevice: deviceModel),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
@ -49,5 +53,7 @@ class AcInterfaceControls extends StatelessWidget {
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
|||||||
if (valueAsString.endsWith(".0") ||
|
if (valueAsString.endsWith(".0") ||
|
||||||
valueAsString.endsWith(".5")) {
|
valueAsString.endsWith(".5")) {
|
||||||
value = double.parse(valueAsString);
|
value = double.parse(valueAsString);
|
||||||
// DevicesCubit.get(context)
|
// DevicesCubit.getInstance()
|
||||||
// .setACTemp(DeviceModel, value);
|
// .setACTemp(DeviceModel, value);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -98,7 +98,7 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
|||||||
dimension: 24,
|
dimension: 24,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// DevicesCubit.get(context)
|
// DevicesCubit.getInstance()
|
||||||
// .setACTemp(DeviceModel, DeviceModel.coolTo);
|
// .setACTemp(DeviceModel, DeviceModel.coolTo);
|
||||||
// DeviceModel.coolTo -= .5;
|
// DeviceModel.coolTo -= .5;
|
||||||
},
|
},
|
||||||
@ -130,7 +130,7 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
|||||||
dimension: 24,
|
dimension: 24,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// DevicesCubit.get(context)
|
// DevicesCubit.getInstance()
|
||||||
// .setACTemp(DeviceModel, DeviceModel.coolTo);
|
// .setACTemp(DeviceModel, DeviceModel.coolTo);
|
||||||
// DeviceModel.coolTo += .5;
|
// DeviceModel.coolTo += .5;
|
||||||
},
|
},
|
||||||
|
@ -31,7 +31,7 @@ class ACTempWidget extends StatelessWidget {
|
|||||||
dimension: 24,
|
dimension: 24,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// DevicesCubit.get(context)
|
// DevicesCubit.getInstance()
|
||||||
// .setACTemp(DeviceModel, DeviceModel.temperature - 0.5);
|
// .setACTemp(DeviceModel, DeviceModel.temperature - 0.5);
|
||||||
},
|
},
|
||||||
child: SvgPicture.asset(
|
child: SvgPicture.asset(
|
||||||
@ -51,7 +51,7 @@ class ACTempWidget extends StatelessWidget {
|
|||||||
dimension: 24,
|
dimension: 24,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// DevicesCubit.get(context)
|
// DevicesCubit.getInstance()
|
||||||
// .setACTemp(DeviceModel, DeviceModel.temperature + 0.5);
|
// .setACTemp(DeviceModel, DeviceModel.temperature + 0.5);
|
||||||
},
|
},
|
||||||
child: SvgPicture.asset(
|
child: SvgPicture.asset(
|
||||||
|
@ -27,7 +27,7 @@ class ACsList extends StatelessWidget {
|
|||||||
const BodySmall(text: "All ACs"),
|
const BodySmall(text: "All ACs"),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 5),
|
||||||
UniversalSwitch(
|
UniversalSwitch(
|
||||||
category: DevicesCubit.get(context).chosenCategory!,
|
category: DevicesCubit.getInstance().chosenCategory!,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
const UniversalACTemp(),
|
const UniversalACTemp(),
|
||||||
@ -39,10 +39,11 @@ class ACsList extends StatelessWidget {
|
|||||||
physics: const NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
padding: const EdgeInsets.all(0),
|
padding: const EdgeInsets.all(0),
|
||||||
itemCount:
|
itemCount:
|
||||||
DevicesCubit.get(context).chosenCategory!.devices!.length,
|
DevicesCubit.getInstance().chosenCategory!.devices!.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
DeviceModel ac =
|
DeviceModel ac = DevicesCubit.getInstance()
|
||||||
DevicesCubit.get(context).chosenCategory!.devices![index];
|
.chosenCategory!
|
||||||
|
.devices![index];
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
@ -51,14 +52,14 @@ class ACsList extends StatelessWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.end,
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
children: [
|
children: [
|
||||||
BodySmall(
|
BodySmall(
|
||||||
text: DevicesCubit.get(context)
|
text: DevicesCubit.getInstance()
|
||||||
.chosenCategory!
|
.chosenCategory!
|
||||||
.devices![index]
|
.devices![index]
|
||||||
.name ??
|
.name ??
|
||||||
""),
|
""),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
DevicesCubit.get(context).selectDevice(ac);
|
DevicesCubit.getInstance().selectDevice(ac);
|
||||||
},
|
},
|
||||||
icon: const Icon(
|
icon: const Icon(
|
||||||
Icons.arrow_forward_ios,
|
Icons.arrow_forward_ios,
|
||||||
@ -83,7 +84,7 @@ class ACsList extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
ACModeControlUnit(
|
ACModeControlUnit(
|
||||||
model: ac,
|
acDevice: ac,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
],
|
],
|
||||||
|
@ -21,9 +21,9 @@ class ACsView extends StatelessWidget {
|
|||||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
DeviceModel? selectedAC;
|
DeviceModel? selectedAC;
|
||||||
if (DevicesCubit.get(context).getSelectedDevice() is DeviceModel) {
|
if (DevicesCubit.getInstance().getSelectedDevice() is DeviceModel) {
|
||||||
selectedAC =
|
selectedAC =
|
||||||
DevicesCubit.get(context).getSelectedDevice() as DeviceModel;
|
DevicesCubit.getInstance().getSelectedDevice() as DeviceModel;
|
||||||
}
|
}
|
||||||
return AnnotatedRegion(
|
return AnnotatedRegion(
|
||||||
value: SystemUiOverlayStyle(
|
value: SystemUiOverlayStyle(
|
||||||
|
@ -20,7 +20,7 @@ class CategoryViewAppBar extends StatelessWidget
|
|||||||
toolbarHeight: Constants.appBarHeight,
|
toolbarHeight: Constants.appBarHeight,
|
||||||
centerTitle: true,
|
centerTitle: true,
|
||||||
title: DisplayMedium(
|
title: DisplayMedium(
|
||||||
text: DevicesCubit.get(context).chosenCategory!.name!,
|
text: DevicesCubit.getInstance().chosenCategory!.name!,
|
||||||
style: context.displayMedium.copyWith(
|
style: context.displayMedium.copyWith(
|
||||||
color: ColorsManager.primaryColor,
|
color: ColorsManager.primaryColor,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
@ -32,7 +32,7 @@ class CategoryViewAppBar extends StatelessWidget
|
|||||||
color: ColorsManager.textPrimaryColor,
|
color: ColorsManager.textPrimaryColor,
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
DevicesCubit.get(context).clearCategoriesSelection(context);
|
DevicesCubit.getInstance().clearCategoriesSelection(context);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -27,7 +27,7 @@ class UniversalACTemp extends StatelessWidget {
|
|||||||
dimension: 24,
|
dimension: 24,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// DevicesCubit.get(context)
|
// DevicesCubit.getInstance()
|
||||||
// .setTempToAll(DevicesCubit.universalACTemp - .5);
|
// .setTempToAll(DevicesCubit.universalACTemp - .5);
|
||||||
},
|
},
|
||||||
child: SvgPicture.asset(
|
child: SvgPicture.asset(
|
||||||
@ -47,7 +47,7 @@ class UniversalACTemp extends StatelessWidget {
|
|||||||
dimension: 24,
|
dimension: 24,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// DevicesCubit.get(context)
|
// DevicesCubit.getInstance()
|
||||||
// .setTempToAll(DevicesCubit.universalACTemp + .5);
|
// .setTempToAll(DevicesCubit.universalACTemp + .5);
|
||||||
},
|
},
|
||||||
child: SvgPicture.asset(
|
child: SvgPicture.asset(
|
||||||
|
@ -25,7 +25,7 @@ class CurtainList extends StatelessWidget {
|
|||||||
const BodySmall(text: "All Curtains"),
|
const BodySmall(text: "All Curtains"),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 5),
|
||||||
UniversalSwitch(
|
UniversalSwitch(
|
||||||
category: DevicesCubit.get(context).chosenCategory!,
|
category: DevicesCubit.getInstance().chosenCategory!,
|
||||||
),
|
),
|
||||||
|
|
||||||
// other ACs controls
|
// other ACs controls
|
||||||
@ -34,16 +34,17 @@ class CurtainList extends StatelessWidget {
|
|||||||
physics: const NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
padding: const EdgeInsets.all(0),
|
padding: const EdgeInsets.all(0),
|
||||||
itemCount:
|
itemCount:
|
||||||
DevicesCubit.get(context).chosenCategory!.devices!.length,
|
DevicesCubit.getInstance().chosenCategory!.devices!.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
DeviceModel curtain =
|
DeviceModel curtain = DevicesCubit.getInstance()
|
||||||
DevicesCubit.get(context).chosenCategory!.devices![index];
|
.chosenCategory!
|
||||||
|
.devices![index];
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
BodySmall(
|
BodySmall(
|
||||||
text: DevicesCubit.get(context)
|
text: DevicesCubit.getInstance()
|
||||||
.chosenCategory!
|
.chosenCategory!
|
||||||
.devices![index]
|
.devices![index]
|
||||||
.name ??
|
.name ??
|
||||||
|
@ -20,7 +20,7 @@ class LightBrightness extends StatelessWidget {
|
|||||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
// onHorizontalDragUpdate: (details) => DevicesCubit().get(context)
|
// onHorizontalDragUpdate: (details) => DevicesCubit.getInstance().get(context)
|
||||||
// .onHorizontalDragUpdate(light, details.localPosition.dx,
|
// .onHorizontalDragUpdate(light, details.localPosition.dx,
|
||||||
// MediaQuery.of(context).size.width - 15),
|
// MediaQuery.of(context).size.width - 15),
|
||||||
child: Stack(
|
child: Stack(
|
||||||
|
@ -27,10 +27,10 @@ class LightInterfaceModes extends StatelessWidget {
|
|||||||
Wrap(
|
Wrap(
|
||||||
spacing: 25,
|
spacing: 25,
|
||||||
children: List.generate(
|
children: List.generate(
|
||||||
DevicesCubit.get(context).lightModes.length,
|
DevicesCubit.getInstance().lightModes.length,
|
||||||
(index) => InkWell(
|
(index) => InkWell(
|
||||||
// onTap: () => DevicesCubit.get(context).setLightingMode(
|
// onTap: () => DevicesCubit.getInstance().setLightingMode(
|
||||||
// light, DevicesCubit.get(context).lightModes[index]!),
|
// light, DevicesCubit.getInstance().lightModes[index]!),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
|
@ -34,7 +34,7 @@ class LightInterfaceRecentColor extends StatelessWidget {
|
|||||||
4,
|
4,
|
||||||
(index) => InkWell(
|
(index) => InkWell(
|
||||||
// onTap: () {
|
// onTap: () {
|
||||||
// DevicesCubit.get(context)
|
// DevicesCubit.getInstance()
|
||||||
// .setColor(light, light.recentColors[index]);
|
// .setColor(light, light.recentColors[index]);
|
||||||
// },
|
// },
|
||||||
child: Container(
|
child: Container(
|
||||||
|
@ -60,7 +60,7 @@ class LightInterfaceSlider extends StatelessWidget {
|
|||||||
// value: light.brightness,
|
// value: light.brightness,
|
||||||
value: 100,
|
value: 100,
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
// DevicesCubit.get(context).setBrightness(light, value);
|
// DevicesCubit.getInstance().setBrightness(light, value);
|
||||||
},
|
},
|
||||||
min: 0,
|
min: 0,
|
||||||
max: 100,
|
max: 100,
|
||||||
|
@ -51,7 +51,7 @@ class LightInterfaceSwitch extends StatelessWidget {
|
|||||||
iconSize: MaterialStateProperty.all(25),
|
iconSize: MaterialStateProperty.all(25),
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// DevicesCubit.get(context).toggleLight(light);
|
// DevicesCubit.getInstance().toggleLight(light);
|
||||||
},
|
},
|
||||||
icon: const Icon(
|
icon: const Icon(
|
||||||
Icons.power_settings_new,
|
Icons.power_settings_new,
|
||||||
|
@ -32,7 +32,7 @@ class LightsList extends StatelessWidget {
|
|||||||
BodySmall(text: lights[index].name ?? ""),
|
BodySmall(text: lights[index].name ?? ""),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
DevicesCubit.get(context).selectDevice(lights[index]);
|
DevicesCubit.getInstance().selectDevice(lights[index]);
|
||||||
},
|
},
|
||||||
icon: const Icon(
|
icon: const Icon(
|
||||||
Icons.arrow_forward_ios,
|
Icons.arrow_forward_ios,
|
||||||
|
@ -19,9 +19,9 @@ class LightsView extends StatelessWidget {
|
|||||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
DeviceModel? selectedLight;
|
DeviceModel? selectedLight;
|
||||||
if (DevicesCubit.get(context).getSelectedDevice() is DeviceModel) {
|
if (DevicesCubit.getInstance().getSelectedDevice() is DeviceModel) {
|
||||||
selectedLight =
|
selectedLight =
|
||||||
DevicesCubit.get(context).getSelectedDevice() as DeviceModel;
|
DevicesCubit.getInstance().getSelectedDevice() as DeviceModel;
|
||||||
}
|
}
|
||||||
List<DeviceModel> lights = [];
|
List<DeviceModel> lights = [];
|
||||||
if (DevicesCubit.allCategories![1].devices != null) {
|
if (DevicesCubit.allCategories![1].devices != null) {
|
||||||
|
@ -28,7 +28,7 @@ class RoomPage extends StatelessWidget {
|
|||||||
physics: const NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
itemCount: room.devices!.length,
|
itemCount: room.devices!.length,
|
||||||
itemBuilder: (_, index) {
|
itemBuilder: (context, index) {
|
||||||
return RoomPageSwitch(device: room.devices![index]);
|
return RoomPageSwitch(device: room.devices![index]);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -33,7 +33,7 @@ class RoomPageSwitch extends StatelessWidget {
|
|||||||
context,
|
context,
|
||||||
CustomPageRoute(
|
CustomPageRoute(
|
||||||
builder: (context) => BlocProvider(
|
builder: (context) => BlocProvider(
|
||||||
create: (context) => DevicesCubit(),
|
create: (context) => DevicesCubit.getInstance(),
|
||||||
child: AcInterface(deviceModel: device),
|
child: AcInterface(deviceModel: device),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -57,7 +57,7 @@ class RoomPageSwitch extends StatelessWidget {
|
|||||||
context,
|
context,
|
||||||
CustomPageRoute(
|
CustomPageRoute(
|
||||||
builder: (context) => BlocProvider(
|
builder: (context) => BlocProvider(
|
||||||
create: (context) => DevicesCubit(),
|
create: (context) => DevicesCubit.getInstance(),
|
||||||
child: LightInterface(light: device),
|
child: LightInterface(light: device),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -67,7 +67,7 @@ class RoomPageSwitch extends StatelessWidget {
|
|||||||
context,
|
context,
|
||||||
CustomPageRoute(
|
CustomPageRoute(
|
||||||
builder: (context) => BlocProvider(
|
builder: (context) => BlocProvider(
|
||||||
create: (context) => DevicesCubit(),
|
create: (context) => DevicesCubit.getInstance(),
|
||||||
child: ThreeGangInterface(
|
child: ThreeGangInterface(
|
||||||
gangSwitch: device,
|
gangSwitch: device,
|
||||||
),
|
),
|
||||||
|
@ -23,16 +23,16 @@ class GangSwitch extends StatelessWidget {
|
|||||||
: InkWell(
|
: InkWell(
|
||||||
overlayColor: MaterialStateProperty.all(Colors.transparent),
|
overlayColor: MaterialStateProperty.all(Colors.transparent),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
DevicesCubit.get(context)
|
// DevicesCubit.getInstance()
|
||||||
.deviceControl(control)
|
// .deviceControl(control)
|
||||||
.then((value) {
|
// .then((value) {
|
||||||
print('Device control response: $value');
|
// print('Device control response: $value');
|
||||||
if (control.value ?? true) {
|
// if (control.value ?? true) {
|
||||||
control.value = false;
|
// control.value = false;
|
||||||
} else {
|
// } else {
|
||||||
control.value = true;
|
// control.value = true;
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
},
|
},
|
||||||
child: Stack(
|
child: Stack(
|
||||||
alignment: !control.value!
|
alignment: !control.value!
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
|
||||||
|
|
||||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/category_view_app_bar.dart';
|
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_interface_body.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_interface_body.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||||
import 'package:syncrow_app/generated/assets.dart';
|
import 'package:syncrow_app/generated/assets.dart';
|
||||||
|
@ -25,7 +25,7 @@ class UniversalSwitch extends StatelessWidget {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
DevicesCubit.get(context).turnAllDevicesOn(category);
|
DevicesCubit.getInstance().turnAllDevicesOn(category);
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
height: 60,
|
height: 60,
|
||||||
@ -57,7 +57,7 @@ class UniversalSwitch extends StatelessWidget {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
DevicesCubit.get(context).turnAllDevicesOff(category);
|
DevicesCubit.getInstance().turnAllDevicesOff(category);
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
height: 60,
|
height: 60,
|
||||||
|
@ -34,12 +34,12 @@ class WizartSwitches extends StatelessWidget {
|
|||||||
itemBuilder: (_, index) {
|
itemBuilder: (_, index) {
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
DevicesCubit.get(context).selectCategory(index);
|
DevicesCubit.getInstance().selectCategory(index);
|
||||||
//Navigate to the chosen category view without animation
|
//Navigate to the chosen category view without animation
|
||||||
|
|
||||||
Navigator.push(context,
|
Navigator.push(context,
|
||||||
CustomPageRoute(builder: (context) {
|
CustomPageRoute(builder: (context) {
|
||||||
return DevicesCubit.get(context)
|
return DevicesCubit.getInstance()
|
||||||
.chosenCategoryView!;
|
.chosenCategoryView!;
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
@ -26,9 +26,9 @@ class CustomSwitch extends StatelessWidget {
|
|||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (device != null) {
|
if (device != null) {
|
||||||
DevicesCubit.get(context).turnOnOffDevice(device!);
|
DevicesCubit.getInstance().turnOnOffDevice(device!);
|
||||||
} else if (category != null) {
|
} else if (category != null) {
|
||||||
DevicesCubit.get(context).changeCategorySwitchValue(category!);
|
DevicesCubit.getInstance().changeCategorySwitchValue(category!);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
|
@ -23,7 +23,7 @@ class DevicesDefaultSwitch extends StatelessWidget {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
DevicesCubit.get(context).turnOnOffDevice(model);
|
DevicesCubit.getInstance().turnOnOffDevice(model);
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
height: 60,
|
height: 60,
|
||||||
@ -49,7 +49,7 @@ class DevicesDefaultSwitch extends StatelessWidget {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
DevicesCubit.get(context).turnOnOffDevice(model);
|
DevicesCubit.getInstance().turnOnOffDevice(model);
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
height: 60,
|
height: 60,
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
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/auth/bloc/auth_cubit.dart';
|
import 'package:syncrow_app/features/auth/bloc/auth_cubit.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
|
||||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/theme_manager.dart';
|
import 'package:syncrow_app/utils/resource_manager/theme_manager.dart';
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
import 'package:syncrow_app/features/app_layout/view/app_layout.dart';
|
import 'package:syncrow_app/features/app_layout/view/app_layout.dart';
|
||||||
import 'package:syncrow_app/features/auth/view/widgets/didnt_get_code/didnt_get_code_view.dart';
|
import 'package:syncrow_app/features/auth/view/widgets/didnt_get_code/didnt_get_code_view.dart';
|
||||||
import 'package:syncrow_app/features/auth/view/widgets/login/login_view.dart';
|
import 'package:syncrow_app/features/auth/view/widgets/login/login_view.dart';
|
||||||
@ -8,8 +7,6 @@ import 'package:syncrow_app/features/auth/view/widgets/privacy_policy/privacy_po
|
|||||||
import 'package:syncrow_app/features/auth/view/widgets/sign_up/sign_up_view.dart';
|
import 'package:syncrow_app/features/auth/view/widgets/sign_up/sign_up_view.dart';
|
||||||
import 'package:syncrow_app/features/auth/view/widgets/user_agreement/user_agreement_view.dart';
|
import 'package:syncrow_app/features/auth/view/widgets/user_agreement/user_agreement_view.dart';
|
||||||
import 'package:syncrow_app/features/dashboard/view/dashboard_view.dart';
|
import 'package:syncrow_app/features/dashboard/view/dashboard_view.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
|
||||||
import 'package:syncrow_app/features/devices/view/devices_view.dart';
|
|
||||||
import 'package:syncrow_app/features/layout/view/layout_view.dart';
|
import 'package:syncrow_app/features/layout/view/layout_view.dart';
|
||||||
import 'package:syncrow_app/features/menu/view/menu_view.dart';
|
import 'package:syncrow_app/features/menu/view/menu_view.dart';
|
||||||
import 'package:syncrow_app/features/profile/view/profile_view.dart';
|
import 'package:syncrow_app/features/profile/view/profile_view.dart';
|
||||||
|
@ -8,6 +8,8 @@ class DevicesAPI {
|
|||||||
|
|
||||||
static Future<Map<String, dynamic>> controlDevice(
|
static Future<Map<String, dynamic>> controlDevice(
|
||||||
DeviceControlModel controlModel) async {
|
DeviceControlModel controlModel) async {
|
||||||
|
// print(
|
||||||
|
// 'contoling [${controlModel.deviceId}] with code [${controlModel.code}] and value [${controlModel.value}');
|
||||||
final response = await _httpService.post(
|
final response = await _httpService.post(
|
||||||
path: ApiEndpoints.control,
|
path: ApiEndpoints.control,
|
||||||
body: controlModel.toJson(),
|
body: controlModel.toJson(),
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
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;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
//ignore_for_file: constant_identifier_names
|
//ignore_for_file: constant_identifier_names
|
||||||
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';
|
||||||
|
|
||||||
abstract class Constants {
|
abstract class Constants {
|
||||||
static const String languageCode = "en";
|
static const String languageCode = "en";
|
||||||
@ -129,3 +130,71 @@ Map<DeviceType, List<FunctionModel>> devicesFunctionsMap = {
|
|||||||
values: '{"unit":"s","min":0,"max":43200,"scale":0,"step":1}'),
|
values: '{"unit":"s","min":0,"max":43200,"scale":0,"step":1}'),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum TempModes { hot, cold, wind }
|
||||||
|
|
||||||
|
enum FanSpeeds { auto, low, middle, high }
|
||||||
|
|
||||||
|
final Map<FanSpeeds, String> fanSpeedsIconMap = {
|
||||||
|
FanSpeeds.auto: Assets.iconsFan0,
|
||||||
|
FanSpeeds.low: Assets.iconsFan1,
|
||||||
|
FanSpeeds.middle: Assets.iconsFan2,
|
||||||
|
FanSpeeds.high: Assets.iconsFan3,
|
||||||
|
};
|
||||||
|
|
||||||
|
final Map<TempModes, String> tempModesIconMap = {
|
||||||
|
TempModes.hot: Assets.iconsSunnyMode,
|
||||||
|
TempModes.cold: Assets.iconsColdMode,
|
||||||
|
TempModes.wind: Assets.iconsWindyMode,
|
||||||
|
};
|
||||||
|
|
||||||
|
final Map<String, FanSpeeds> fanSpeedsMap = {
|
||||||
|
'auto': FanSpeeds.auto,
|
||||||
|
'low': FanSpeeds.low,
|
||||||
|
'middle': FanSpeeds.middle,
|
||||||
|
'high': FanSpeeds.high,
|
||||||
|
};
|
||||||
|
|
||||||
|
final Map<String, TempModes> tempModesMap = {
|
||||||
|
'hot': TempModes.hot,
|
||||||
|
'cold': TempModes.cold,
|
||||||
|
'wind': TempModes.wind,
|
||||||
|
};
|
||||||
|
|
||||||
|
final Map<FanSpeeds, String> reversedFanSpeedsMap =
|
||||||
|
fanSpeedsMap.map((key, value) => MapEntry(value, key));
|
||||||
|
|
||||||
|
final Map<TempModes, String> reversedTempModesMap =
|
||||||
|
tempModesMap.map((key, value) => MapEntry(value, key));
|
||||||
|
|
||||||
|
String getNextFanSpeedKey(FanSpeeds currentFanSpeed) {
|
||||||
|
const List<FanSpeeds> speeds = FanSpeeds.values;
|
||||||
|
final int currentIndex = speeds.indexOf(currentFanSpeed);
|
||||||
|
|
||||||
|
// Return null if currentFanSpeed is the last value
|
||||||
|
if (currentIndex == speeds.length - 1) {
|
||||||
|
return reversedFanSpeedsMap[FanSpeeds.auto]!;
|
||||||
|
}
|
||||||
|
|
||||||
|
final FanSpeeds nextSpeed = speeds[currentIndex + 1];
|
||||||
|
return reversedFanSpeedsMap[nextSpeed]!;
|
||||||
|
}
|
||||||
|
|
||||||
|
K? getNextItem<K, V>(Map<K, V> map, V value) {
|
||||||
|
// Iterate over the map entries
|
||||||
|
for (var entry in map.entries) {
|
||||||
|
// If the current value matches the provided value
|
||||||
|
if (entry.value == value) {
|
||||||
|
// Get the index of the current entry
|
||||||
|
final index = map.keys.toList().indexOf(entry.key);
|
||||||
|
// If the index is not the last item, return the next item
|
||||||
|
if (index < map.length - 1) {
|
||||||
|
return map.keys.elementAt(index + 1);
|
||||||
|
}
|
||||||
|
// If it's the last item, return null
|
||||||
|
return map.keys.elementAt(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If the value is not found, return null
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user