mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 17:47:28 +00:00
built Lights List
This commit is contained in:
@ -6,9 +6,7 @@ import 'package:syncrow_app/features/devices/model/ac_model.dart';
|
|||||||
part 'ac_state.dart';
|
part 'ac_state.dart';
|
||||||
|
|
||||||
class AcCubit extends Cubit<AcState> {
|
class AcCubit extends Cubit<AcState> {
|
||||||
AcCubit() : super(AcInitial()) {
|
AcCubit() : super(AcInitial());
|
||||||
updateACsStatus();
|
|
||||||
}
|
|
||||||
|
|
||||||
static AcCubit get(context) => BlocProvider.of(context);
|
static AcCubit get(context) => BlocProvider.of(context);
|
||||||
|
|
||||||
@ -26,52 +24,6 @@ class AcCubit extends Cubit<AcState> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void turnACOn(ACModel model) {
|
|
||||||
if (model.status == false) {
|
|
||||||
model.status = true;
|
|
||||||
updateACsStatus();
|
|
||||||
emit(ACTurnedOn());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void turnACOff(ACModel model) {
|
|
||||||
if (model.status == true) {
|
|
||||||
model.status = false;
|
|
||||||
updateACsStatus();
|
|
||||||
emit(ACTurnedOff());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateACsStatus() {
|
|
||||||
bool? tempStatus = DevicesCubit.categories[0].devices[0].status;
|
|
||||||
for (var AC in DevicesCubit.categories[0].devices) {
|
|
||||||
//check if there any AC have a different status than the initial ==> turn off the universal switch
|
|
||||||
if (AC.status != tempStatus) {
|
|
||||||
DevicesCubit.categories[0].devicesStatus = null;
|
|
||||||
emit(ACsStatusChanged());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
DevicesCubit.categories[0].devicesStatus = tempStatus;
|
|
||||||
emit(ACsStatusChanged());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void turnAllACsOff() {
|
|
||||||
for (var ac in DevicesCubit.categories[0].devices) {
|
|
||||||
ac.status = false;
|
|
||||||
}
|
|
||||||
updateACsStatus();
|
|
||||||
emit(SwitchACsOff());
|
|
||||||
}
|
|
||||||
|
|
||||||
void turnAllACsOn() {
|
|
||||||
for (var ac in DevicesCubit.categories[0].devices) {
|
|
||||||
ac.status = true;
|
|
||||||
}
|
|
||||||
updateACsStatus();
|
|
||||||
emit(SwitchACsOn());
|
|
||||||
}
|
|
||||||
|
|
||||||
void setTempToAll(double temperature) {
|
void setTempToAll(double temperature) {
|
||||||
for (var element in DevicesCubit.categories[0].devices) {
|
for (var element in DevicesCubit.categories[0].devices) {
|
||||||
if (element is ACModel) {
|
if (element is ACModel) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
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/devices/model/ac_model.dart';
|
import 'package:syncrow_app/features/devices/model/ac_model.dart';
|
||||||
|
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/light_model.dart';
|
import 'package:syncrow_app/features/devices/model/light_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/curtains/curtain_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/gateway/gateway_view.dart';
|
||||||
@ -15,9 +16,7 @@ import '../view/widgets/lights/lights_view.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());
|
||||||
// getCategories();
|
|
||||||
}
|
|
||||||
|
|
||||||
void changeCategorySwitchValue(DevicesCategoryModel category) {
|
void changeCategorySwitchValue(DevicesCategoryModel category) {
|
||||||
if (category.devicesStatus != null) {
|
if (category.devicesStatus != null) {
|
||||||
@ -37,6 +36,44 @@ class DevicesCubit extends Cubit<DevicesState> {
|
|||||||
|
|
||||||
static DevicesCubit get(context) => BlocProvider.of(context);
|
static DevicesCubit get(context) => BlocProvider.of(context);
|
||||||
|
|
||||||
|
void turnOnOffDevice(DeviceModel device) {
|
||||||
|
device.status = !device.status!;
|
||||||
|
DevicesCategoryModel category =
|
||||||
|
categories.firstWhere((category) => category.devices.contains(device));
|
||||||
|
updateDevicesStatus(category);
|
||||||
|
emit(DeviceSwitchChanged());
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateDevicesStatus(DevicesCategoryModel category) {
|
||||||
|
bool? tempStatus = category.devices[0].status;
|
||||||
|
for (var AC in category.devices) {
|
||||||
|
//check if there any AC have a different status than the initial ==> turn off the universal switch
|
||||||
|
if (AC.status != tempStatus) {
|
||||||
|
category.devicesStatus = null;
|
||||||
|
emit(DeviceSwitchChanged());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
category.devicesStatus = tempStatus;
|
||||||
|
emit(DeviceSwitchChanged());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void turnAllDevicesOff(DevicesCategoryModel category) {
|
||||||
|
for (var device in category.devices) {
|
||||||
|
device.status = false;
|
||||||
|
}
|
||||||
|
updateDevicesStatus(category);
|
||||||
|
emit(CategorySwitchChanged());
|
||||||
|
}
|
||||||
|
|
||||||
|
void turnAllDevicesOn(DevicesCategoryModel category) {
|
||||||
|
for (var device in category.devices) {
|
||||||
|
device.status = true;
|
||||||
|
}
|
||||||
|
updateDevicesStatus(category);
|
||||||
|
emit(CategorySwitchChanged());
|
||||||
|
}
|
||||||
|
|
||||||
static List<DevicesCategoryModel> categories = [
|
static List<DevicesCategoryModel> categories = [
|
||||||
DevicesCategoryModel(
|
DevicesCategoryModel(
|
||||||
devices: [
|
devices: [
|
||||||
|
@ -17,8 +17,4 @@ class DevicesCategoryChanged extends DevicesState {}
|
|||||||
|
|
||||||
class CategorySwitchChanged extends DevicesState {}
|
class CategorySwitchChanged extends DevicesState {}
|
||||||
|
|
||||||
class SwitchACsOff extends DevicesState {}
|
class DeviceSwitchChanged extends DevicesState {}
|
||||||
|
|
||||||
class SwitchACsOn extends DevicesState {}
|
|
||||||
|
|
||||||
class SetACsTemp extends DevicesState {}
|
|
||||||
|
@ -3,8 +3,8 @@ import 'package:syncrow_app/features/devices/bloc/AC/ac_cubit.dart';
|
|||||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
import 'package:syncrow_app/features/devices/bloc/devices_cubit.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/devices/view/widgets/ACs/ac_temp_widget.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_temp_widget.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/universal_ac_switch.dart';
|
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/universal_ac_temp.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/ACs/universal_ac_temp.dart';
|
||||||
|
import 'package:syncrow_app/features/devices/view/widgets/universal_switch.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/devices_default_switch.dart';
|
import 'package:syncrow_app/features/shared_widgets/devices_default_switch.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
|
||||||
|
|
||||||
@ -25,7 +25,9 @@ class ACsList extends StatelessWidget {
|
|||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
const BodySmall(text: "All ACs"),
|
const BodySmall(text: "All ACs"),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 5),
|
||||||
const UniversalACSwitch(),
|
UniversalSwitch(
|
||||||
|
category: DevicesCubit.categories[0],
|
||||||
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
const UniversalACTemp(),
|
const UniversalACTemp(),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
|
56
lib/features/devices/view/widgets/lights/lights_list.dart
Normal file
56
lib/features/devices/view/widgets/lights/lights_list.dart
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../../../../shared_widgets/devices_default_switch.dart';
|
||||||
|
import '../../../../shared_widgets/text_widgets/body_small.dart';
|
||||||
|
import '../../../model/light_model.dart';
|
||||||
|
|
||||||
|
class LightsList extends StatelessWidget {
|
||||||
|
const LightsList({
|
||||||
|
super.key,
|
||||||
|
required this.lights,
|
||||||
|
});
|
||||||
|
|
||||||
|
final List<LightModel> lights;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ListView.builder(
|
||||||
|
shrinkWrap: true,
|
||||||
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
|
padding: const EdgeInsets.all(0),
|
||||||
|
itemCount: lights.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
BodySmall(text: lights[index].name ?? ""),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
var device = lights[index];
|
||||||
|
// LightsCubit.get(context).selectAC(device);
|
||||||
|
},
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.arrow_forward_ios,
|
||||||
|
),
|
||||||
|
style: ButtonStyle(
|
||||||
|
padding: MaterialStateProperty.all(
|
||||||
|
const EdgeInsets.all(0),
|
||||||
|
),
|
||||||
|
iconSize: MaterialStateProperty.all(15),
|
||||||
|
alignment: Alignment.bottomRight,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 5),
|
||||||
|
DevicesDefaultSwitch(model: lights[index]),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,17 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_app/features/devices/view/widgets/lights/lights_list.dart';
|
||||||
|
|
||||||
|
import '../../../../../generated/assets.dart';
|
||||||
|
import '../../../../../utils/resource_manager/color_manager.dart';
|
||||||
|
import '../../../../app_layout/view/widgets/default_app_bar.dart';
|
||||||
|
import '../../../../app_layout/view/widgets/default_nav_bar.dart';
|
||||||
|
import '../../../../shared_widgets/text_widgets/body_small.dart';
|
||||||
|
import '../../../bloc/devices_cubit.dart';
|
||||||
import '../../../bloc/lights/lights_cubit.dart';
|
import '../../../bloc/lights/lights_cubit.dart';
|
||||||
|
import '../../../model/light_model.dart';
|
||||||
|
import '../universal_switch.dart';
|
||||||
|
|
||||||
class LightsView extends StatelessWidget {
|
class LightsView extends StatelessWidget {
|
||||||
const LightsView({super.key});
|
const LightsView({super.key});
|
||||||
@ -11,9 +21,60 @@ class LightsView extends StatelessWidget {
|
|||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => LightsCubit(),
|
create: (context) => LightsCubit(),
|
||||||
child: BlocBuilder<LightsCubit, LightsState>(
|
child: BlocBuilder<LightsCubit, LightsState>(
|
||||||
builder: (context, state) => const Center(
|
builder: (context, state) {
|
||||||
child: Text('LightsView'),
|
List<LightModel> lights = [];
|
||||||
),
|
for (var device in DevicesCubit.categories[1].devices) {
|
||||||
|
if (device is LightModel) {
|
||||||
|
lights.add(device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return AnnotatedRegion(
|
||||||
|
value: SystemUiOverlayStyle(
|
||||||
|
statusBarColor: ColorsManager.primaryColor.withOpacity(0.5),
|
||||||
|
statusBarIconBrightness: Brightness.light,
|
||||||
|
),
|
||||||
|
child: SafeArea(
|
||||||
|
child: Scaffold(
|
||||||
|
backgroundColor: ColorsManager.backgroundColor,
|
||||||
|
extendBodyBehindAppBar: true,
|
||||||
|
extendBody: true,
|
||||||
|
appBar: const DefaultAppBar(),
|
||||||
|
body: Container(
|
||||||
|
width: MediaQuery.sizeOf(context).width,
|
||||||
|
height: MediaQuery.sizeOf(context).height,
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
image: DecorationImage(
|
||||||
|
image: AssetImage(
|
||||||
|
Assets.imagesBackground,
|
||||||
|
),
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
opacity: 0.4,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
top: 60, right: 15, left: 15, bottom: 80),
|
||||||
|
child: SizedBox.expand(
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
const BodySmall(text: "All Lights"),
|
||||||
|
UniversalSwitch(
|
||||||
|
category: DevicesCubit.categories[1],
|
||||||
|
),
|
||||||
|
LightsList(lights: lights),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
bottomNavigationBar: const DefaultNavBar(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,28 +1,31 @@
|
|||||||
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/devices/bloc/devices_cubit.dart';
|
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||||
|
import 'package:syncrow_app/features/devices/model/device_category_model.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/strings_manager.dart';
|
import 'package:syncrow_app/utils/resource_manager/strings_manager.dart';
|
||||||
|
|
||||||
import '../../../../../utils/resource_manager/color_manager.dart';
|
import '../../../../utils/resource_manager/color_manager.dart';
|
||||||
import '../../../../shared_widgets/text_widgets/body_medium.dart';
|
import '../../../shared_widgets/text_widgets/body_medium.dart';
|
||||||
import '../../../bloc/AC/ac_cubit.dart';
|
|
||||||
|
|
||||||
class UniversalACSwitch extends StatelessWidget {
|
class UniversalSwitch extends StatelessWidget {
|
||||||
const UniversalACSwitch({
|
const UniversalSwitch({
|
||||||
super.key,
|
super.key,
|
||||||
|
required this.category,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final DevicesCategoryModel category;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<AcCubit, AcState>(
|
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
bool? status = DevicesCubit.categories[0].devicesStatus;
|
bool? status = category.devicesStatus;
|
||||||
return Row(
|
return Row(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Expanded(
|
Expanded(
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
AcCubit.get(context).turnAllACsOn();
|
DevicesCubit.get(context).turnAllDevicesOn(category);
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
height: 60,
|
height: 60,
|
||||||
@ -54,7 +57,7 @@ class UniversalACSwitch extends StatelessWidget {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
AcCubit.get(context).turnAllACsOff();
|
DevicesCubit.get(context).turnAllDevicesOff(category);
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
height: 60,
|
height: 60,
|
@ -1,28 +1,29 @@
|
|||||||
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/devices/bloc/AC/ac_cubit.dart';
|
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/ac_model.dart';
|
|
||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
|
|
||||||
|
import '../devices/bloc/devices_cubit.dart';
|
||||||
|
|
||||||
class DevicesDefaultSwitch extends StatelessWidget {
|
class DevicesDefaultSwitch extends StatelessWidget {
|
||||||
const DevicesDefaultSwitch({
|
const DevicesDefaultSwitch({
|
||||||
super.key,
|
super.key,
|
||||||
required this.model,
|
required this.model,
|
||||||
});
|
});
|
||||||
|
|
||||||
final ACModel model;
|
final DeviceModel model;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<AcCubit, AcState>(
|
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return Row(
|
return Row(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Expanded(
|
Expanded(
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
AcCubit.get(context).turnACOn(model);
|
DevicesCubit.get(context).turnOnOffDevice(model);
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
height: 60,
|
height: 60,
|
||||||
@ -48,7 +49,7 @@ class DevicesDefaultSwitch extends StatelessWidget {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
AcCubit.get(context).turnACOff(model);
|
DevicesCubit.get(context).turnOnOffDevice(model);
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
height: 60,
|
height: 60,
|
||||||
|
Reference in New Issue
Block a user