From 33b7149dde242a29998fd80b3515eb48f55a4e90 Mon Sep 17 00:00:00 2001 From: Mohammad Salameh Date: Mon, 4 Mar 2024 17:10:34 +0300 Subject: [PATCH] fixed padding bug fixed AC interface routing issue --- lib/features/devices/bloc/devices_cubit.dart | 3 + lib/features/devices/view/devices_view.dart | 6 +- .../devices/view/widgets/ACs/acs_list.dart | 131 +++++++++--------- .../devices/view/widgets/ACs/acs_view.dart | 80 ++++++----- .../view/widgets/devices_view_body.dart | 5 +- 5 files changed, 119 insertions(+), 106 deletions(-) diff --git a/lib/features/devices/bloc/devices_cubit.dart b/lib/features/devices/bloc/devices_cubit.dart index 59e7eee..9ee4b30 100644 --- a/lib/features/devices/bloc/devices_cubit.dart +++ b/lib/features/devices/bloc/devices_cubit.dart @@ -289,6 +289,7 @@ class DevicesCubit extends Cubit { device.status = true; } } + updateDevicesStatus(category); emit(CategorySwitchChanged()); } @@ -319,6 +320,7 @@ class DevicesCubit extends Cubit { for (var device in category.devices) { device.status = false; } + changeCategorySwitchValue(category); updateDevicesStatus(category); emit(CategorySwitchChanged()); } @@ -327,6 +329,7 @@ class DevicesCubit extends Cubit { for (var device in category.devices) { device.status = true; } + changeCategorySwitchValue(category); updateDevicesStatus(category); emit(CategorySwitchChanged()); } diff --git a/lib/features/devices/view/devices_view.dart b/lib/features/devices/view/devices_view.dart index 00f315d..e07b786 100644 --- a/lib/features/devices/view/devices_view.dart +++ b/lib/features/devices/view/devices_view.dart @@ -11,7 +11,11 @@ class CategoriesView extends StatelessWidget { return BlocProvider( create: (context) => DevicesCubit(), child: BlocBuilder( - builder: (context, state) => const DevicesViewBody(), + builder: (context, state) => Container( + padding: const EdgeInsets.all(8), + width: MediaQuery.sizeOf(context).width, + height: MediaQuery.sizeOf(context).height, + child: const DevicesViewBody()), ), ); } diff --git a/lib/features/devices/view/widgets/ACs/acs_list.dart b/lib/features/devices/view/widgets/ACs/acs_list.dart index 61f4a5b..438ceb5 100644 --- a/lib/features/devices/view/widgets/ACs/acs_list.dart +++ b/lib/features/devices/view/widgets/ACs/acs_list.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.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'; @@ -18,75 +19,79 @@ class ACsList extends StatelessWidget { @override Widget build(BuildContext context) { DevicesCategoryModel category = DevicesCubit.categories[0]; - return SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - // universal AC controller - const SizedBox(height: 10), - const BodySmall(text: "All ACs"), - const SizedBox(height: 5), - UniversalSwitch( - category: category, - ), - const SizedBox(height: 10), - const UniversalACTemp(), - const SizedBox(height: 10), + return BlocBuilder( + builder: (context, state) { + return SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + // universal AC controller + const SizedBox(height: 10), + const BodySmall(text: "All ACs"), + const SizedBox(height: 5), + UniversalSwitch( + category: category, + ), + const SizedBox(height: 10), + const UniversalACTemp(), + const SizedBox(height: 10), - // other ACs controls - ListView.builder( - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - padding: const EdgeInsets.all(0), - itemCount: category.devices.length, - itemBuilder: (context, index) { - ACModel ac = category.devices[index] as ACModel; - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.end, + // other ACs controls + ListView.builder( + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + padding: const EdgeInsets.all(0), + itemCount: category.devices.length, + itemBuilder: (context, index) { + ACModel ac = category.devices[index] as ACModel; + return Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - BodySmall(text: 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), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + BodySmall(text: 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, + ), ), - iconSize: MaterialStateProperty.all(15), - alignment: Alignment.bottomRight, - ), + ], ), + const SizedBox(height: 5), + if (category.devices[index] is ACModel) + DevicesDefaultSwitch( + model: ac, + ), + const SizedBox(height: 10), + ACTempWidget( + ac, + ), + const SizedBox(height: 10), + if (category.devices[index] is ACModel) + ACModeControlUnit( + model: ac, + ), + const SizedBox(height: 10), ], - ), - const SizedBox(height: 5), - if (category.devices[index] is ACModel) - DevicesDefaultSwitch( - model: ac, - ), - const SizedBox(height: 10), - ACTempWidget( - ac, - ), - const SizedBox(height: 10), - if (category.devices[index] is ACModel) - ACModeControlUnit( - model: ac, - ), - const SizedBox(height: 10), - ], - ); - }, + ); + }, + ), + ], ), - ], - ), + ); + }, ); } } diff --git a/lib/features/devices/view/widgets/ACs/acs_view.dart b/lib/features/devices/view/widgets/ACs/acs_view.dart index c7bb4f4..05ad689 100644 --- a/lib/features/devices/view/widgets/ACs/acs_view.dart +++ b/lib/features/devices/view/widgets/ACs/acs_view.dart @@ -19,49 +19,53 @@ class ACsView extends StatelessWidget { Widget build(BuildContext context) { return BlocProvider( create: (context) => AcCubit(), - child: BlocBuilder( + child: BlocBuilder( builder: (context, state) { - 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), - 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, + return BlocBuilder( + builder: (context, state) { + 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), + 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: selectedAC != null + ? AcInterface(acModel: selectedAC) + : const ACsList(), + ), ), - fit: BoxFit.cover, - opacity: 0.4, - ), - ), - child: Padding( - padding: const EdgeInsets.only( - top: 60, right: 15, left: 15, bottom: 80), - child: SizedBox.expand( - child: selectedAC != null - ? AcInterface(acModel: selectedAC) - : const ACsList(), ), + bottomNavigationBar: const DefaultNavBar(), ), ), - bottomNavigationBar: const DefaultNavBar(), - ), - ), + ); + }, ); }, ), diff --git a/lib/features/devices/view/widgets/devices_view_body.dart b/lib/features/devices/view/widgets/devices_view_body.dart index 3e72de4..8c95b93 100644 --- a/lib/features/devices/view/widgets/devices_view_body.dart +++ b/lib/features/devices/view/widgets/devices_view_body.dart @@ -26,10 +26,7 @@ class DevicesViewBody extends StatelessWidget { : Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - SizedBox( - width: MediaQuery.sizeOf(context).width, - height: MediaQuery.sizeOf(context).height - - MediaQuery.sizeOf(context).height * .3, + Expanded( child: PageView( controller: pageController, children: const [