diff --git a/lib/features/app_layout/bloc/home_cubit.dart b/lib/features/app_layout/bloc/home_cubit.dart index 04d2b81..e13b6ca 100644 --- a/lib/features/app_layout/bloc/home_cubit.dart +++ b/lib/features/app_layout/bloc/home_cubit.dart @@ -6,11 +6,14 @@ import 'package:syncrow_app/features/app_layout/view/widgets/app_bar_home_dropdo 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/model/room_model.dart'; +import 'package:syncrow_app/features/devices/view/widgets/curtains/blind_view.dart'; import 'package:syncrow_app/features/devices/view/widgets/devices_view_body.dart'; import 'package:syncrow_app/features/menu/view/menu_view.dart'; import 'package:syncrow_app/features/scene/view/scene_view.dart'; import 'package:syncrow_app/generated/assets.dart'; +import 'package:syncrow_app/navigation/navigation_service.dart'; import 'package:syncrow_app/services/api/spaces_api.dart'; +import 'package:syncrow_app/utils/helpers/custom_page_route.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; part 'home_state.dart'; @@ -168,7 +171,14 @@ class HomeCubit extends Cubit { foregroundColor: MaterialStateProperty.all(ColorsManager.textPrimaryColor), ), - onPressed: () {}, + onPressed: () { + Navigator.push( + NavigationService.navigatorKey.currentContext!, + CustomPageRoute( + builder: (context) => const BlindsView(), + ), + ); + }, ), ], 'Devices': [ diff --git a/lib/features/devices/bloc/devices_cubit.dart b/lib/features/devices/bloc/devices_cubit.dart index 346af12..117b468 100644 --- a/lib/features/devices/bloc/devices_cubit.dart +++ b/lib/features/devices/bloc/devices_cubit.dart @@ -391,45 +391,76 @@ class DevicesCubit extends Cubit { //////////////////////////////////CURTAINS////////////////////////////////////// double height = 310; double _openPercentage = 0; + bool isMoving = false; openCurtain() async { - for (var i = 0; i < 10; i++) { - if (state is! CurtainsIsMoving) { + if (state is CurtainsIsOpening) { + return; + } + + isMoving = true; + while (_openPercentage < 100.0) { + if (state is CurtainsIsClosing) { + // interrupted by the closing process + pauseCurtain(); break; } - emit(CurtainsIsMoving()); + emit(CurtainsIsOpening()); - await Future.delayed(const Duration(milliseconds: 200), () { - if (_openPercentage < 100.0) { + if (isMoving) { + await Future.delayed(const Duration(milliseconds: 200), () { _openPercentage += 10.0; height -= 24.5; - } else { - emit(CurtainsStopped()); - } - }); + + if (_openPercentage >= 100.0) { + print('done open'); + pauseCurtain(); + } + }); + } else { + print('stopped open'); + pauseCurtain(); + break; + } } } closeCurtain() async { - for (var i = 0; i < 10; i++) { - if (state is! CurtainsIsMoving) { + if (state is CurtainsIsClosing) { + return; + } + + isMoving = true; + while (_openPercentage > 0.0) { + if (state is CurtainsIsOpening) { + // interrupted by the opening process + pauseCurtain(); break; } - await Future.delayed(const Duration(milliseconds: 200), () { - if (_openPercentage > 0.0) { + emit(CurtainsIsClosing()); + + if (isMoving) { + await Future.delayed(const Duration(milliseconds: 200), () { _openPercentage -= 10.0; height += 24.5; - emit(CurtainsIsMoving()); - } else { - emit(CurtainsStopped()); - } - }); + + if (_openPercentage <= 0.0) { + print('done close'); + pauseCurtain(); + } + }); + } else { + print('stopped close'); + pauseCurtain(); + break; + } } } pauseCurtain() { + isMoving = false; emit(CurtainsStopped()); } } diff --git a/lib/features/devices/bloc/devices_state.dart b/lib/features/devices/bloc/devices_state.dart index 410858a..e1a45d4 100644 --- a/lib/features/devices/bloc/devices_state.dart +++ b/lib/features/devices/bloc/devices_state.dart @@ -82,6 +82,8 @@ class DevicesCategoriesError extends DevicesState { } // Curtains -class CurtainsIsMoving extends DevicesState {} +class CurtainsIsOpening extends DevicesState {} + +class CurtainsIsClosing extends DevicesState {} class CurtainsStopped extends DevicesState {} diff --git a/lib/features/devices/view/widgets/curtains/blind_view.dart b/lib/features/devices/view/widgets/curtains/blind_view.dart index 049a24a..f0cf8c4 100644 --- a/lib/features/devices/view/widgets/curtains/blind_view.dart +++ b/lib/features/devices/view/widgets/curtains/blind_view.dart @@ -9,21 +9,24 @@ class BlindsView extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return const DefaultScaffold( - title: 'Blinds', - child: Column( - children: [ - Spacer(), - BlindsBlades(), - // SizedBox(height: 80), - // BlindsBottons(), - Spacer(), - ], - ), - ); - }, + return BlocProvider( + create: (context) => DevicesCubit.getInstance(), + child: BlocBuilder( + builder: (context, state) { + return const DefaultScaffold( + title: 'Blinds', + child: Column( + children: [ + Spacer(), + BlindsBlades(), + // SizedBox(height: 80), + // BlindsBottons(), + Spacer(), + ], + ), + ); + }, + ), ); } } diff --git a/lib/utils/resource_manager/constants.dart b/lib/utils/resource_manager/constants.dart index badf561..748bf97 100644 --- a/lib/utils/resource_manager/constants.dart +++ b/lib/utils/resource_manager/constants.dart @@ -392,7 +392,6 @@ enum MemberRole { OtherMember, } -//TODO sort memebers by role List> members = [ { 'name': 'member 1',