diff --git a/lib/features/app_layout/view/app_layout.dart b/lib/features/app_layout/view/app_layout.dart index 1d2e3a4..39605f8 100644 --- a/lib/features/app_layout/view/app_layout.dart +++ b/lib/features/app_layout/view/app_layout.dart @@ -23,7 +23,7 @@ class AppLayout extends StatelessWidget { child: Scaffold( backgroundColor: ColorsManager.backgroundColor, extendBodyBehindAppBar: true, - // extendBody: true, + extendBody: true, appBar: DefaultAppBar(), body: AppBody(), bottomNavigationBar: DefaultNavBar(), diff --git a/lib/features/app_layout/view/widgets/app_body.dart b/lib/features/app_layout/view/widgets/app_body.dart index 4db97a2..0e13d7d 100644 --- a/lib/features/app_layout/view/widgets/app_body.dart +++ b/lib/features/app_layout/view/widgets/app_body.dart @@ -26,7 +26,8 @@ class AppBody extends StatelessWidget { ), ), child: Padding( - padding: const EdgeInsets.only(top: 60, right: 15, left: 15), + padding: + const EdgeInsets.only(top: 60, right: 15, left: 15, bottom: 80), child: NavCubit.of(context).currentPage, ), ); diff --git a/lib/features/devices/bloc/ac/ac_cubit.dart b/lib/features/devices/bloc/ac/ac_cubit.dart index 6d2472c..5010649 100644 --- a/lib/features/devices/bloc/ac/ac_cubit.dart +++ b/lib/features/devices/bloc/ac/ac_cubit.dart @@ -11,11 +11,6 @@ class AcCubit extends Cubit { static AcCubit get(context) => BlocProvider.of(context); - void selectAC(ACModel model) { - model.isSelected = !model.isSelected; - emit(ACSelected()); - } - ACModel? getSelectedAC() { for (var ac in DevicesCubit.categories[0].devices) { if (ac is ACModel && ac.isSelected) { diff --git a/lib/features/devices/bloc/devices_cubit.dart b/lib/features/devices/bloc/devices_cubit.dart index 3106329..6878b12 100644 --- a/lib/features/devices/bloc/devices_cubit.dart +++ b/lib/features/devices/bloc/devices_cubit.dart @@ -179,6 +179,17 @@ class DevicesCubit extends Cubit { ), ]; + void selectCategory(int index) { + for (var i = 0; i < categories.length; i++) { + if (i == index) { + categories[i].isSelected = true; + } else { + categories[i].isSelected = false; + } + } + emit(DevicesCategoryChanged()); + } + Widget? get chosenCategoryView { for (var category in categories) { if (category.isSelected) { @@ -188,6 +199,31 @@ class DevicesCubit extends Cubit { return null; } + void selectDevice(DeviceModel device) { + for (var category in categories) { + for (var device in category.devices) { + if (device.isSelected) { + category.isSelected = false; + emit(DeviceSelected()); + return; + } + } + } + device.isSelected = !device.isSelected; + emit(DeviceSelected()); + } + + DeviceModel? getSelectedDevice() { + for (var category in categories) { + for (var device in category.devices) { + if (device.isSelected) { + return device; + } + } + } + return null; + } + void changeCategorySwitchValue(DevicesCategoryModel category) { if (category.devicesStatus != null) { category.devicesStatus = !category.devicesStatus!; @@ -252,17 +288,6 @@ class DevicesCubit extends Cubit { } } - void selectCategory(int index) { - for (var i = 0; i < categories.length; i++) { - if (i == index) { - categories[i].isSelected = true; - } else { - categories[i].isSelected = false; - } - } - emit(DevicesCategoryChanged()); - } - static void clearCategoriesSelection() { for (var category in categories) { category.isSelected = false; diff --git a/lib/features/devices/bloc/devices_state.dart b/lib/features/devices/bloc/devices_state.dart index a25c3f6..4a6ba5d 100644 --- a/lib/features/devices/bloc/devices_state.dart +++ b/lib/features/devices/bloc/devices_state.dart @@ -18,3 +18,5 @@ class DevicesCategoryChanged extends DevicesState {} class CategorySwitchChanged extends DevicesState {} class DeviceSwitchChanged extends DevicesState {} + +class DeviceSelected extends DevicesState {} diff --git a/lib/features/devices/view/widgets/ACs/acs_list.dart b/lib/features/devices/view/widgets/ACs/acs_list.dart index 9ec0024..61f4a5b 100644 --- a/lib/features/devices/view/widgets/ACs/acs_list.dart +++ b/lib/features/devices/view/widgets/ACs/acs_list.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -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/model/device_category_model.dart'; import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_mode_control_unit.dart'; @@ -52,10 +51,7 @@ class ACsList extends StatelessWidget { BodySmall(text: category.devices[index].name ?? ""), IconButton( onPressed: () { - var device = category.devices[index]; - if (device is ACModel) { - AcCubit.get(context).selectAC(device); - } + DevicesCubit.get(context).selectDevice(ac); }, icon: const Icon( Icons.arrow_forward_ios, diff --git a/lib/features/devices/view/widgets/ACs/acs_view.dart b/lib/features/devices/view/widgets/ACs/acs_view.dart index a4ff23c..c7bb4f4 100644 --- a/lib/features/devices/view/widgets/ACs/acs_view.dart +++ b/lib/features/devices/view/widgets/ACs/acs_view.dart @@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/app_layout/view/widgets/default_app_bar.dart'; import 'package:syncrow_app/features/app_layout/view/widgets/default_nav_bar.dart'; 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/model/ac_model.dart'; import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_interface.dart'; import 'package:syncrow_app/features/devices/view/widgets/ACs/acs_list.dart'; @@ -20,7 +21,11 @@ class ACsView extends StatelessWidget { create: (context) => AcCubit(), child: BlocBuilder( builder: (context, state) { - ACModel? selectedAC = AcCubit.get(context).getSelectedAC(); + ACModel? selectedAC; + if (DevicesCubit.get(context).getSelectedDevice() is ACModel) { + selectedAC = + DevicesCubit.get(context).getSelectedDevice() as ACModel; + } return AnnotatedRegion( value: SystemUiOverlayStyle( statusBarColor: ColorsManager.primaryColor.withOpacity(0.5), diff --git a/lib/features/devices/view/widgets/devices_categories_view.dart b/lib/features/devices/view/widgets/devices_categories_view.dart index 83965e2..c9a56f0 100644 --- a/lib/features/devices/view/widgets/devices_categories_view.dart +++ b/lib/features/devices/view/widgets/devices_categories_view.dart @@ -11,7 +11,7 @@ class DevicesCategoriesView extends StatelessWidget { @override Widget build(BuildContext context) { - return Column( + return const Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded( diff --git a/lib/features/devices/view/widgets/devices_view_body.dart b/lib/features/devices/view/widgets/devices_view_body.dart index cbc56fd..d8abb80 100644 --- a/lib/features/devices/view/widgets/devices_view_body.dart +++ b/lib/features/devices/view/widgets/devices_view_body.dart @@ -19,6 +19,7 @@ class DevicesViewBody extends StatelessWidget { create: (context) => DevicesCubit(), child: BlocBuilder( builder: (context, state) { + //TODO : move to NavigationCubit PageController pageController = PageController(); return state is DevicesLoading ? const Center(child: CircularProgressIndicator()) diff --git a/lib/features/devices/view/widgets/lights/light_interface.dart b/lib/features/devices/view/widgets/lights/light_interface.dart new file mode 100644 index 0000000..7f9cf69 --- /dev/null +++ b/lib/features/devices/view/widgets/lights/light_interface.dart @@ -0,0 +1,44 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; +import 'package:syncrow_app/features/devices/model/light_model.dart'; +import 'package:syncrow_app/features/shared_widgets/default_container.dart'; + +class LightInterface extends StatelessWidget { + const LightInterface({super.key, required this.light}); + + final LightModel light; + + @override + Widget build(BuildContext context) { + return SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + const SizedBox(height: 20), + Container( + constraints: const BoxConstraints( + maxHeight: 65, + ), + margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 10), + child: const DefaultContainer(child: SizedBox.expand()), + ), + Container( + constraints: const BoxConstraints( + maxHeight: 310, + ), + margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 10), + child: const SizedBox.expand(), + ), + Container( + constraints: const BoxConstraints( + maxHeight: 65, + ), + margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 10), + child: const SizedBox.expand(), + ), + ], + ), + ); + } +} diff --git a/lib/features/devices/view/widgets/lights/lights_list.dart b/lib/features/devices/view/widgets/lights/lights_list.dart index c2f1eee..84b6119 100644 --- a/lib/features/devices/view/widgets/lights/lights_list.dart +++ b/lib/features/devices/view/widgets/lights/lights_list.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart'; import 'package:syncrow_app/features/devices/view/widgets/lights/light_brightness.dart'; import '../../../../shared_widgets/devices_default_switch.dart'; @@ -31,7 +32,7 @@ class LightsList extends StatelessWidget { BodySmall(text: lights[index].name ?? ""), IconButton( onPressed: () { - // LightsCubit.get(context).selectAC(device); + DevicesCubit.get(context).selectDevice(lights[index]); }, icon: const Icon( Icons.arrow_forward_ios, diff --git a/lib/features/devices/view/widgets/lights/lights_view.dart b/lib/features/devices/view/widgets/lights/lights_view.dart index 43566b3..eab453b 100644 --- a/lib/features/devices/view/widgets/lights/lights_view.dart +++ b/lib/features/devices/view/widgets/lights/lights_view.dart @@ -1,17 +1,16 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_app/features/devices/view/widgets/lights/lights_list.dart'; +import 'package:syncrow_app/features/devices/view/widgets/lights/lights_view_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 '../../../model/light_model.dart'; -import '../universal_switch.dart'; +import 'light_interface.dart'; class LightsView extends StatelessWidget { const LightsView({super.key}); @@ -22,6 +21,11 @@ class LightsView extends StatelessWidget { create: (context) => LightsCubit(), child: BlocBuilder( builder: (context, state) { + LightModel? selectedLight; + if (DevicesCubit.get(context).getSelectedDevice() is LightModel) { + selectedLight = + DevicesCubit.get(context).getSelectedDevice() as LightModel; + } List lights = []; for (var device in DevicesCubit.categories[1].devices) { if (device is LightModel) { @@ -51,24 +55,9 @@ class LightsView extends StatelessWidget { opacity: 0.4, ), ), - child: Padding( - padding: const EdgeInsets.only( - top: 70, 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), - ], - ), - ), - ), - ), + child: selectedLight != null + ? LightInterface(light: selectedLight) + : LightsViewList(lights: lights), ), bottomNavigationBar: const DefaultNavBar(), ), diff --git a/lib/features/devices/view/widgets/lights/lights_view_list.dart b/lib/features/devices/view/widgets/lights/lights_view_list.dart new file mode 100644 index 0000000..47e8daa --- /dev/null +++ b/lib/features/devices/view/widgets/lights/lights_view_list.dart @@ -0,0 +1,37 @@ +import 'package:flutter/material.dart'; +import 'package:syncrow_app/features/devices/view/widgets/lights/lights_list.dart'; + +import '../../../../shared_widgets/text_widgets/body_small.dart'; +import '../../../bloc/devices_cubit.dart'; +import '../../../model/light_model.dart'; +import '../universal_switch.dart'; + +class LightsViewList extends StatelessWidget { + const LightsViewList({ + super.key, + required this.lights, + }); + + final List lights; + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.only(top: 70, 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), + ], + ), + ), + ), + ); + } +} diff --git a/lib/features/scene/bloc/scene_cubit.dart b/lib/features/scene/bloc/scene_cubit.dart index fe443d1..350173a 100644 --- a/lib/features/scene/bloc/scene_cubit.dart +++ b/lib/features/scene/bloc/scene_cubit.dart @@ -13,7 +13,7 @@ class SceneCubit extends Cubit { void getScenes() { emit(SceneLoading()); //TODO: remove this it's causing the Bad State because its being after the cubit is closed - Future.delayed(const Duration(seconds: 5), () { + Future.delayed(const Duration(milliseconds: 50), () { emit(SceneSuccess()); }); }