Removed location from models

Added the spaces models
Added the rooms models
Added the Spaces cubit
Implemented the home dropdown functionality
This commit is contained in:
Mohammad Salameh
2024-03-06 21:34:23 +03:00
parent b99247c937
commit b3fcca639a
23 changed files with 359 additions and 138 deletions
@@ -0,0 +1,133 @@
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';
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: [],
),
SpaceModel(
id: '1',
name: 'Office',
rooms: [],
),
SpaceModel(
id: '2',
name: 'Parent\'s House',
rooms: [],
),
];
List<RoomModel> 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: '',
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: '',
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: '',
image: '',
timer: null,
),
],
icon: Assets.iconsCurtain,
name: 'Curtains',
type: DeviceType.Curtain,
page: const CurtainView(),
),
DevicesCategoryModel(
devices: [],
icon: Assets.iconsScreen,
name: 'Gateway',
type: DeviceType.Gateway,
page: const GateWayView(),
),
]),
RoomModel(id: '1', name: 'Bedroom', categories: []),
];
SpaceModel selectedSpace = spaces.first;
selectSpace(SpaceModel space) {
selectedSpace = space;
emit(SpacesSelected(space));
}
//TODO implement the methods to fetch the spaces from the API
}
@@ -0,0 +1,19 @@
part of 'spaces_cubit.dart';
abstract class SpacesState {}
class SpacesInitial extends SpacesState {}
class SpacesLoading extends SpacesState {}
class SpacesLoaded extends SpacesState {
final List<SpaceModel> spaces;
SpacesLoaded(this.spaces);
}
class SpacesSelected extends SpacesState {
final SpaceModel space;
SpacesSelected(this.space);
}
@@ -0,0 +1,29 @@
import 'package:syncrow_app/features/devices/model/room_model.dart';
class SpaceModel {
final String id;
final String name;
final List<RoomModel> rooms;
SpaceModel({
required this.id,
required this.name,
required this.rooms,
});
Map<String, dynamic> toJson() {
return {
'id': id,
'name': name,
'rooms': rooms,
};
}
factory SpaceModel.fromJson(Map<String, dynamic> json) {
return SpaceModel(
id: json['id'],
name: json['name'],
rooms: json['rooms'],
);
}
}
@@ -1,9 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_app/features/app_layout/bloc/spaces_cubit.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
import 'package:syncrow_app/utils/context_extension.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
import '../../../../generated/assets.dart';
import '../../../shared_widgets/text_widgets/body_large.dart';
class AppBarHomeDropdown extends StatelessWidget {
const AppBarHomeDropdown({
@@ -12,33 +15,57 @@ class AppBarHomeDropdown extends StatelessWidget {
@override
Widget build(BuildContext context) {
return TextButton(
onPressed: () {},
child: SizedBox(
width: 150,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SvgPicture.asset(
Assets.iconsHome,
width: 25,
height: 25,
colorFilter: const ColorFilter.mode(
ColorsManager.textPrimaryColor,
BlendMode.srcIn,
return BlocBuilder<SpacesCubit, SpacesState>(
builder: (context, state) {
return DropdownButton(
icon: const Icon(
Icons.expand_more,
color: Colors.black,
size: 25,
),
underline: const SizedBox.shrink(),
padding: const EdgeInsets.all(0),
borderRadius: BorderRadius.circular(20),
value: SpacesCubit.get(context).selectedSpace,
items: SpacesCubit.spaces.map((space) {
return DropdownMenuItem(
value: space,
child: SizedBox(
width: 100,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SvgPicture.asset(
Assets.iconsHome,
width: 25,
height: 25,
colorFilter: const ColorFilter.mode(
ColorsManager.textPrimaryColor,
BlendMode.srcIn,
),
),
const SizedBox(width: 5),
Expanded(
child: BodyMedium(
text: space.name,
style: context.bodyMedium.copyWith(
fontSize: 15,
color: ColorsManager.textPrimaryColor,
overflow: TextOverflow.ellipsis,
),
),
),
],
),
),
),
const SizedBox(width: 5),
const BodyLarge(text: 'Home'),
const SizedBox(width: 5),
const Icon(
Icons.expand_more,
color: Colors.black,
)
],
),
),
);
}).toList(),
onChanged: (value) {
SpacesCubit.get(context).selectSpace(value!);
},
);
},
);
}
}
+1 -1
View File
@@ -12,7 +12,7 @@ class AcCubit extends Cubit<AcState> {
static AcCubit get(context) => BlocProvider.of(context);
static DevicesCategoryModel category = DevicesCubit.categories[0];
static DevicesCategoryModel category = DevicesCubit.allCategories[0];
ACModel? getSelectedAC() {
for (var ac in category.devices) {
@@ -9,5 +9,5 @@ class CurtainsCubit extends Cubit<CurtainsState> {
static CurtainsCubit get(context) => BlocProvider.of(context);
static DevicesCategoryModel category = DevicesCubit.categories[4];
static DevicesCategoryModel category = DevicesCubit.allCategories[3];
}
+32 -21
View File
@@ -1,6 +1,7 @@
import 'package:flutter/material.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/curtain_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/view/widgets/curtains/curtain_view.dart';
@@ -20,7 +21,7 @@ class DevicesCubit extends Cubit<DevicesState> {
static DevicesCubit get(context) => BlocProvider.of(context);
static List<DevicesCategoryModel> categories = [
static List<DevicesCategoryModel> allCategories = [
DevicesCategoryModel(
devices: [
ACModel(
@@ -32,7 +33,6 @@ class DevicesCubit extends Cubit<DevicesState> {
tempMode: 0,
coolTo: 20,
type: '',
location: '',
image: '',
timer: null,
bounds: Bounds(
@@ -49,7 +49,6 @@ class DevicesCubit extends Cubit<DevicesState> {
tempMode: 0,
coolTo: 20,
type: '',
location: '',
image: '',
timer: null,
bounds: Bounds(
@@ -66,7 +65,6 @@ class DevicesCubit extends Cubit<DevicesState> {
tempMode: 0,
coolTo: 20,
type: '',
location: '',
image: '',
timer: null,
bounds: Bounds(
@@ -83,7 +81,6 @@ class DevicesCubit extends Cubit<DevicesState> {
tempMode: 0,
coolTo: 20,
type: '',
location: '',
image: '',
timer: null,
bounds: Bounds(
@@ -108,7 +105,6 @@ class DevicesCubit extends Cubit<DevicesState> {
lightingMode: 1,
timer: null,
type: '',
location: '',
image: '',
recentColors: [
0xFF83D9FF,
@@ -126,7 +122,6 @@ class DevicesCubit extends Cubit<DevicesState> {
lightingMode: 1,
timer: null,
type: '',
location: '',
image: '',
recentColors: [
0xFF83D9FF,
@@ -144,7 +139,6 @@ class DevicesCubit extends Cubit<DevicesState> {
lightingMode: 1,
timer: null,
type: '',
location: '',
image: '',
recentColors: [
0xFF83D9FF,
@@ -162,7 +156,6 @@ class DevicesCubit extends Cubit<DevicesState> {
lightingMode: 1,
timer: null,
type: '',
location: '',
image: '',
recentColors: [
0xFF83D9FF,
@@ -180,7 +173,6 @@ class DevicesCubit extends Cubit<DevicesState> {
lightingMode: 1,
timer: null,
type: '',
location: '',
image: '',
recentColors: [
0xFF83D9FF,
@@ -203,7 +195,26 @@ class DevicesCubit extends Cubit<DevicesState> {
page: const DoorView(),
),
DevicesCategoryModel(
devices: [],
devices: [
CurtainModel(
openPercentage: 10,
id: "1",
name: "Living Room Curtain",
status: false,
type: '',
image: '',
timer: null,
),
CurtainModel(
openPercentage: 20,
id: "2",
name: "Master Bedroom Curtain",
status: false,
type: '',
image: '',
timer: null,
),
],
icon: Assets.iconsCurtain,
name: 'Curtains',
type: DeviceType.Curtain,
@@ -226,25 +237,25 @@ class DevicesCubit extends Cubit<DevicesState> {
];
selectCategory(int index) {
for (var i = 0; i < categories.length; i++) {
for (var i = 0; i < allCategories.length; i++) {
if (i == index) {
categories[i].isSelected = true;
allCategories[i].isSelected = true;
} else {
categories[i].isSelected = false;
allCategories[i].isSelected = false;
}
}
emit(DevicesCategoryChanged());
}
unselectAllCategories() {
for (var category in categories) {
for (var category in allCategories) {
category.isSelected = false;
}
emit(DevicesCategoryChanged());
}
Widget? get chosenCategoryView {
for (var category in categories) {
for (var category in allCategories) {
if (category.isSelected) {
return category.page;
}
@@ -253,7 +264,7 @@ class DevicesCubit extends Cubit<DevicesState> {
}
selectDevice(DeviceModel device) {
for (var category in categories) {
for (var category in allCategories) {
for (var device in category.devices) {
if (device.isSelected) {
category.isSelected = false;
@@ -267,7 +278,7 @@ class DevicesCubit extends Cubit<DevicesState> {
}
DeviceModel? getSelectedDevice() {
for (var category in categories) {
for (var category in allCategories) {
for (var device in category.devices) {
if (device.isSelected) {
return device;
@@ -296,8 +307,8 @@ class DevicesCubit extends Cubit<DevicesState> {
turnOnOffDevice(DeviceModel device) {
device.status = !device.status!;
DevicesCategoryModel category =
categories.firstWhere((category) => category.devices.contains(device));
DevicesCategoryModel category = allCategories
.firstWhere((category) => category.devices.contains(device));
updateDevicesStatus(category);
emit(DeviceSwitchChanged());
}
@@ -354,7 +365,7 @@ class DevicesCubit extends Cubit<DevicesState> {
}
clearCategoriesSelection(BuildContext context) {
for (var category in categories) {
for (var category in allCategories) {
category.isSelected = false;
for (var device in category.devices) {
device.isSelected = false;
-3
View File
@@ -21,7 +21,6 @@ class ACModel extends DeviceModel {
required super.name,
required super.type,
required super.status,
required super.location,
required super.image,
required super.timer,
});
@@ -36,7 +35,6 @@ class ACModel extends DeviceModel {
'name': name,
'status': status,
'type': type,
'location': location,
'image': image,
};
}
@@ -50,7 +48,6 @@ class ACModel extends DeviceModel {
fanSpeed: json['fanSpeed'],
tempMode: json['tempMode'],
type: json['type'],
location: json['location'],
image: json['image'],
timer: json['timer'],
coolTo: json['coolTo'],
@@ -9,7 +9,6 @@ class CurtainModel extends DeviceModel {
required super.name,
required super.type,
required super.status,
required super.location,
required super.image,
required super.timer,
});
@@ -22,7 +21,6 @@ class CurtainModel extends DeviceModel {
'name': name,
'status': status,
'type': type,
'location': location,
'image': image,
};
}
@@ -35,7 +33,6 @@ class CurtainModel extends DeviceModel {
openPercentage: json['openPercentage'],
timer: json['timer'],
type: json['type'],
location: json['location'],
image: json['image'],
);
}
@@ -3,7 +3,6 @@ abstract class DeviceModel {
final String? name;
final String? type;
bool? status;
final String? location;
final String? image;
final double? timer;
bool isSelected = false;
@@ -13,7 +12,6 @@ abstract class DeviceModel {
required this.name,
required this.type,
required this.status,
required this.location,
required this.image,
required this.timer,
});
@@ -17,7 +17,6 @@ class LightModel extends DeviceModel {
required super.name,
required super.type,
required super.status,
required super.location,
required super.image,
required super.timer,
});
@@ -33,7 +32,6 @@ class LightModel extends DeviceModel {
'name': name,
'status': status,
'type': type,
'location': location,
'image': image,
};
}
@@ -48,7 +46,6 @@ class LightModel extends DeviceModel {
lightingMode: json['lightingMode'],
timer: json['timer'],
type: json['type'],
location: json['location'],
image: json['image'],
recentColors: json['recentColors'],
);
@@ -0,0 +1,30 @@
import 'package:syncrow_app/features/devices/model/device_category_model.dart';
class RoomModel {
final String id;
final String name;
final List<DevicesCategoryModel> categories;
RoomModel({
required this.id,
required this.name,
required this.categories,
});
Map<String, dynamic> toJson() {
return {
'id': id,
'name': name,
'devices': categories,
};
}
factory RoomModel.fromJson(Map<String, dynamic> json) {
return RoomModel(
id: json['id'],
name: json['name'],
categories: json['devices'],
);
}
}
@@ -36,40 +36,19 @@ class CurtainList extends StatelessWidget {
padding: const EdgeInsets.all(0),
itemCount: CurtainsCubit.category.devices.length,
itemBuilder: (context, index) {
CurtainModel ac =
CurtainModel curtain =
CurtainsCubit.category.devices[index] as CurtainModel;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
BodySmall(
text:
CurtainsCubit.category.devices[index].name ??
""),
IconButton(
onPressed: () {
DevicesCubit.get(context).selectDevice(ac);
},
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: 20),
BodySmall(
text:
CurtainsCubit.category.devices[index].name ?? ""),
const SizedBox(height: 5),
if (CurtainsCubit.category.devices[index] is CurtainModel)
DevicesDefaultSwitch(
model: ac,
model: curtain,
),
],
);
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
import 'package:syncrow_app/features/devices/view/widgets/devices_categories_view.dart';
import 'package:syncrow_app/features/devices/view/widgets/wizard_page.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/title_medium.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart';
@@ -35,7 +35,7 @@ class DevicesViewBody extends StatelessWidget {
child: PageView(
controller: pageController,
children: const [
DevicesCategoriesView(),
WizardPage(),
Padding(
padding: EdgeInsets.symmetric(
horizontal: Constants.defaultPadding),
@@ -28,7 +28,7 @@ class LightsView extends StatelessWidget {
DevicesCubit.get(context).getSelectedDevice() as LightModel;
}
List<LightModel> lights = [];
for (var device in DevicesCubit.categories[1].devices) {
for (var device in DevicesCubit.allCategories[1].devices) {
if (device is LightModel) {
lights.add(device);
}
@@ -30,7 +30,7 @@ class LightsViewList extends StatelessWidget {
children: [
const BodySmall(text: "All Lights"),
UniversalSwitch(
category: DevicesCubit.categories[1],
category: DevicesCubit.allCategories[1],
),
LightsList(lights: lights),
],
@@ -28,7 +28,7 @@ class Switches extends StatelessWidget {
padding: const EdgeInsets.only(top: 10),
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: DevicesCubit.categories.length,
itemCount: DevicesCubit.allCategories.length,
itemBuilder: (_, index) {
return InkWell(
onTap: () {
@@ -51,11 +51,11 @@ class Switches extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SvgPicture.asset(
DevicesCubit.categories[index].icon,
DevicesCubit.allCategories[index].icon,
fit: BoxFit.contain,
),
CustomSwitch(
category: DevicesCubit.categories[index],
category: DevicesCubit.allCategories[index],
),
],
),
@@ -63,7 +63,7 @@ class Switches extends StatelessWidget {
child: FittedBox(
fit: BoxFit.scaleDown,
child: BodyLarge(
text: DevicesCubit.categories[index].name,
text: DevicesCubit.allCategories[index].name,
style: context.bodyLarge.copyWith(
fontWeight: FontWeight.bold,
height: 0,
@@ -7,8 +7,8 @@ import 'package:syncrow_app/features/shared_widgets/text_widgets/title_medium.da
import 'package:syncrow_app/utils/resource_manager/constants.dart';
import 'package:syncrow_app/utils/resource_manager/strings_manager.dart';
class DevicesCategoriesView extends StatelessWidget {
const DevicesCategoriesView({
class WizardPage extends StatelessWidget {
const WizardPage({
super.key,
});