mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-27 02:24:55 +00:00
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:
133
lib/features/app_layout/bloc/spaces_cubit.dart
Normal file
133
lib/features/app_layout/bloc/spaces_cubit.dart
Normal file
@ -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
|
||||
}
|
||||
19
lib/features/app_layout/bloc/spaces_state.dart
Normal file
19
lib/features/app_layout/bloc/spaces_state.dart
Normal file
@ -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);
|
||||
}
|
||||
29
lib/features/app_layout/model/space_model.dart
Normal file
29
lib/features/app_layout/model/space_model.dart
Normal file
@ -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!);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user