From 13f244ff19447bb7f996b254de7979222df771e1 Mon Sep 17 00:00:00 2001 From: mohammad Date: Mon, 28 Oct 2024 17:08:49 +0300 Subject: [PATCH] power_clamp_issue&search_issue --- .../power_clamp_bloc/power_clamp_bloc.dart | 49 +-- .../widgets/power_clamp/power_clamp_card.dart | 16 +- .../widgets/power_clamp/power_clamp_page.dart | 14 +- .../widgets/power_clamp/power_info_card.dart | 89 +++--- .../devices/view/widgets/room_page.dart | 47 ++- .../devices/view/widgets/rooms_slider.dart | 14 +- .../devices/view/widgets/wizard_page.dart | 279 ++++++++++-------- 7 files changed, 295 insertions(+), 213 deletions(-) diff --git a/lib/features/devices/bloc/power_clamp_bloc/power_clamp_bloc.dart b/lib/features/devices/bloc/power_clamp_bloc/power_clamp_bloc.dart index 48224a1..b5c235a 100644 --- a/lib/features/devices/bloc/power_clamp_bloc/power_clamp_bloc.dart +++ b/lib/features/devices/bloc/power_clamp_bloc/power_clamp_bloc.dart @@ -22,7 +22,8 @@ class PowerClampBloc extends Bloc { on(_filterRecordsByDate); } DateTime? dateTime = DateTime.now(); - String formattedDate = DateFormat('yyyy/MM/dd').format(DateTime.now()); + + String formattedDate = DateFormat('dd/MM/yyyy').format(DateTime.now()); bool lowBattery = false; bool closingReminder = false; bool doorAlarm = false; @@ -305,8 +306,8 @@ class PowerClampBloc extends Bloc { (newDate) { if (newDate != null) { dateTime = newDate; - formattedDate = DateFormat('yyyy/MM/dd').format(dateTime!); - + // formattedDate = DateFormat('yyyy/MM/dd').format(dateTime!); + formattedDate = DateFormat('dd/MM/yyyy').format(dateTime!); add(FilterRecordsByDateEvent( selectedDate: dateTime!, viewType: views[currentIndex], @@ -319,8 +320,7 @@ class PowerClampBloc extends Bloc { (newDate) { if (newDate != null) { dateTime = newDate; - formattedDate = DateFormat('yyyy-MM').format(dateTime!); - + formattedDate = DateFormat('yyyy/MM').format(dateTime!); add(FilterRecordsByDateEvent( selectedDate: dateTime!, viewType: views[currentIndex], @@ -530,13 +530,13 @@ class PowerClampBloc extends Bloc { Future dayMonthYearPicker({ required BuildContext context, }) async { - DateTime selectedDate = DateTime.now(); // Default selected date + DateTime selectedDate = DateTime.now(); return await showModalBottomSheet( context: context, builder: (BuildContext context) { return SizedBox( - height: 350, // Increased height to accommodate the buttons + height: 350, child: Column( children: [ Expanded( @@ -546,8 +546,7 @@ class PowerClampBloc extends Bloc { minimumYear: 1900, maximumYear: DateTime.now().year, onDateTimeChanged: (DateTime newDateTime) { - selectedDate = - newDateTime; // Update the selected date when changed + selectedDate = newDateTime; }, ), ), @@ -561,15 +560,13 @@ class PowerClampBloc extends Bloc { TextButton( child: const Text('Cancel'), onPressed: () { - Navigator.of(context) - .pop(); // Dismiss the modal without returning a value + Navigator.of(context).pop(); }, ), TextButton( child: const Text('OK'), onPressed: () { - Navigator.of(context) - .pop(selectedDate); // Return the selected date + Navigator.of(context).pop(selectedDate); }, ), ], @@ -591,6 +588,8 @@ class PowerClampBloc extends Bloc { .where((record) => record.eventTime!.year == event.selectedDate.year) .toList(); } else if (event.viewType == 'Month') { + formattedDate = + "${getMonthShortName(event.selectedDate.month)} ${event.selectedDate.year.toString()}"; filteredRecords = record .where((record) => record.eventTime!.year == event.selectedDate.year && @@ -604,10 +603,6 @@ class PowerClampBloc extends Bloc { record.eventTime!.day == event.selectedDate.day) .toList(); } - String getMonthShortName(int month) { - final date = DateTime(0, month); - return DateFormat.MMM().format(date); - } energyDataList = filteredRecords.map((eventDevice) { return EnergyData( @@ -615,18 +610,32 @@ class PowerClampBloc extends Bloc { ? getMonthShortName( int.tryParse(DateFormat('MM').format(eventDevice.eventTime!))!) : event.viewType == 'Month' - ? DateFormat('yyyy/MM/dd').format(eventDevice.eventTime!) + ? DateFormat('dd/MM').format(eventDevice.eventTime!) : DateFormat('HH:mm:ss').format(eventDevice.eventTime!), double.parse(eventDevice.value!), ); }).toList(); - + selectDateRange(); Future.delayed(const Duration(milliseconds: 500)); emit(FilterRecordsState(filteredRecords: energyDataList)); } + + String getMonthShortName(int month) { + final date = DateTime(0, month); + return DateFormat.MMM().format(date); + } + + String endChartDate = ''; + + void selectDateRange() async { + DateTime startDate = dateTime!; + DateTime endDate = DateTime(startDate.year, startDate.month + 1, 1) + .subtract(Duration(days: 1)); + String formattedEndDate = DateFormat('dd/MM/yyyy').format(endDate); + endChartDate = ' - $formattedEndDate'; + } } -// Event for filtering records by date // _listenToChanges() { diff --git a/lib/features/devices/view/widgets/power_clamp/power_clamp_card.dart b/lib/features/devices/view/widgets/power_clamp/power_clamp_card.dart index 5c758c8..c2cd008 100644 --- a/lib/features/devices/view/widgets/power_clamp/power_clamp_card.dart +++ b/lib/features/devices/view/widgets/power_clamp/power_clamp_card.dart @@ -22,6 +22,8 @@ class PowerClampCard extends StatelessWidget { final String? totalFactor; final Widget? dateSwitcher; final String? formattedDate; + final String? phaseType; + final String? energyConsumption; final Function()? selectDateEvent; final List? chartData; @@ -37,6 +39,7 @@ class PowerClampCard extends StatelessWidget { this.totalCurrentGeneral, this.totalFrequencyGeneral, this.totalVoltage, + this.phaseType, this.totalActive, this.totalFrequency, this.totalFactor, @@ -53,8 +56,7 @@ class PowerClampCard extends StatelessWidget { Widget build(BuildContext context) { return DefaultContainer( child: Padding( - padding: - const EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10), + padding: const EdgeInsets.only(left: 5, right: 5, top: 10, bottom: 10), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, mainAxisAlignment: MainAxisAlignment.center, @@ -116,7 +118,7 @@ class PowerClampCard extends StatelessWidget { PowerClampInfoCard( iconPath: Assets.voltageIcon, title: 'Voltage', - value: totalVoltage!, + value: '${double.parse(totalVoltage!) / 10}', unit: ' V', ), PowerClampInfoCard( @@ -152,13 +154,15 @@ class PowerClampCard extends StatelessWidget { Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - const BodyMedium( - text: 'Total consumption', + BodyMedium( + text: isGeneral == true + ? 'Total consumption' + : phaseType!, fontSize: 12, fontWeight: FontWeight.w700, ), Text( - dateTimeSelected !, + dateTimeSelected!, style: const TextStyle( fontSize: 8, fontWeight: FontWeight.w400), ), diff --git a/lib/features/devices/view/widgets/power_clamp/power_clamp_page.dart b/lib/features/devices/view/widgets/power_clamp/power_clamp_page.dart index 506cd2c..e0145d6 100644 --- a/lib/features/devices/view/widgets/power_clamp/power_clamp_page.dart +++ b/lib/features/devices/view/widgets/power_clamp/power_clamp_page.dart @@ -55,7 +55,6 @@ class _PowerClampPageState extends State { child: BlocProvider( create: (context) => PowerClampBloc(PCId: widget.device?.uuid ?? '') ..add(const PowerClampInitial()), - // ..add(const ReportLogsInitial(code: 'VoltageA')), child: BlocBuilder( builder: (context, state) { final blocProvider = context.read(); @@ -88,6 +87,7 @@ class _PowerClampPageState extends State { }, child: PageView(controller: _pageController, children: [ _buildPowerClampCard( + phaseType: '', title: 'Total Energy \nConsumption', phase: model.status.general, isGeneral: true, @@ -96,18 +96,21 @@ class _PowerClampPageState extends State { ), _buildPowerClampCard( title: 'Phase A Energy \nConsumption', + phaseType: 'Phase A consumption', phase: model.status.phaseA, chartData: chartData, blocProvider: blocProvider, ), _buildPowerClampCard( title: 'Phase B Energy \nConsumption', + phaseType: 'Phase B consumption', phase: model.status.phaseB, chartData: chartData, blocProvider: blocProvider, ), _buildPowerClampCard( title: 'Phase C Energy \nConsumption', + phaseType: 'Phase C consumption', phase: model.status.phaseC, chartData: chartData, blocProvider: blocProvider, @@ -154,6 +157,7 @@ class _PowerClampPageState extends State { List chartData, PowerClampBloc blocProvider) { return [ _buildPowerClampCard( + phaseType: '', title: 'Total Energy \nConsumption', phase: model.status.general, isGeneral: true, @@ -161,18 +165,21 @@ class _PowerClampPageState extends State { blocProvider: blocProvider, ), _buildPowerClampCard( + phaseType: 'Phase A consumption', title: 'Phase A Energy \nConsumption', phase: model.status.phaseA, chartData: chartData, blocProvider: blocProvider, ), _buildPowerClampCard( + phaseType: 'Phase B consumption', title: 'Phase B Energy \nConsumption', phase: model.status.phaseB, chartData: chartData, blocProvider: blocProvider, ), _buildPowerClampCard( + phaseType: 'Phase C consumption', title: 'Phase C Energy \nConsumption', phase: model.status.phaseC, chartData: chartData, @@ -183,15 +190,18 @@ class _PowerClampPageState extends State { Widget _buildPowerClampCard({ required String title, + required String phaseType, required Phase phase, bool isGeneral = false, required List chartData, required PowerClampBloc blocProvider, }) { return PowerClampCard( - dateTimeSelected:blocProvider.formattedDate, + dateTimeSelected: + '${blocProvider.dateTime!.day}/${blocProvider.dateTime!.month}/${blocProvider.dateTime!.year} ${blocProvider.endChartDate}', energyConsumption: _getValueOrNA(phase.dataPoints, isGeneral ? 0 : 5), title: title, + phaseType: phaseType, isGeneral: isGeneral, dateSwitcher: blocProvider.dateSwitcher(), formattedDate: blocProvider.formattedDate, diff --git a/lib/features/devices/view/widgets/power_clamp/power_info_card.dart b/lib/features/devices/view/widgets/power_clamp/power_info_card.dart index 04d21e6..1a9ddb0 100644 --- a/lib/features/devices/view/widgets/power_clamp/power_info_card.dart +++ b/lib/features/devices/view/widgets/power_clamp/power_info_card.dart @@ -21,53 +21,50 @@ class PowerClampInfoCard extends StatelessWidget { @override Widget build(BuildContext context) { return Expanded( - child: Padding( - padding: const EdgeInsets.all(5.0), - child: DefaultContainer( - height: 55, - color: ColorsManager.grayBox, - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Expanded( - child: SvgPicture.asset( - iconPath, - fit: BoxFit.fill, - ), + child: DefaultContainer( + height: 55, + color: ColorsManager.grayBox, + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Expanded( + child: SvgPicture.asset( + iconPath, + fit: BoxFit.contain, ), - Expanded( - flex: 3, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - BodyMedium( - fontWeight: FontWeight.w400, - fontSize: 8, - text: title, - ), - Row( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - BodyMedium( - fontWeight: FontWeight.w700, - fontSize: 15, - text: value, - ), - BodyMedium( - fontWeight: FontWeight.w700, - fontSize: 8, - text: unit, - ), - ], - ), - ], - ), - ) - ], - ), + ), + Expanded( + flex: 3, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + BodyMedium( + fontWeight: FontWeight.w400, + fontSize: 8, + text: title, + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + BodyMedium( + fontWeight: FontWeight.w700, + fontSize: 15, + text: value, + ), + BodyMedium( + fontWeight: FontWeight.w700, + fontSize: 8, + text: unit, + ), + ], + ), + ], + ), + ) + ], ), ), ); diff --git a/lib/features/devices/view/widgets/room_page.dart b/lib/features/devices/view/widgets/room_page.dart index 86fbed9..1a96b60 100644 --- a/lib/features/devices/view/widgets/room_page.dart +++ b/lib/features/devices/view/widgets/room_page.dart @@ -67,21 +67,38 @@ class _RoomPageState extends State { ), ), ), - Expanded( - child: GridView.builder( - gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 2, - crossAxisSpacing: 10, - mainAxisSpacing: 10, - childAspectRatio: 1.5, - ), - padding: const EdgeInsets.only(top: 10), - itemCount: _filteredDevices.length, - itemBuilder: (context, index) { - return RoomPageSwitch(device: _filteredDevices[index]); - }, - ), - ), + _filteredDevices.isNotEmpty + ? Expanded( + child: GridView.builder( + gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 2, + crossAxisSpacing: 10, + mainAxisSpacing: 10, + childAspectRatio: 1.5, + ), + padding: const EdgeInsets.only(top: 10), + itemCount: _filteredDevices.length, + itemBuilder: (context, index) { + return RoomPageSwitch(device: _filteredDevices[index]); + }, + ), + ) + : const Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Center( + child: Text( + 'No Results Found', + style: TextStyle( + color: ColorsManager.grayColor, + fontSize: 14, + fontWeight: FontWeight.w400), + )), + ], + ), + ), ], ); } diff --git a/lib/features/devices/view/widgets/rooms_slider.dart b/lib/features/devices/view/widgets/rooms_slider.dart index a53efb3..feda17e 100644 --- a/lib/features/devices/view/widgets/rooms_slider.dart +++ b/lib/features/devices/view/widgets/rooms_slider.dart @@ -22,7 +22,6 @@ class RoomsSlider extends StatelessWidget { onPageChanged: (index) { HomeCubit.getInstance().roomSliderPageChanged(index); }, - children: [ Padding( padding: const EdgeInsets.symmetric(horizontal: 15), @@ -45,15 +44,20 @@ class RoomsSlider extends StatelessWidget { (room) => InkWell( onTap: () { HomeCubit.getInstance().roomSliderPageChanged( - HomeCubit.getInstance().selectedSpace!.rooms!.indexOf(room)); + HomeCubit.getInstance() + .selectedSpace! + .rooms! + .indexOf(room)); }, child: TitleMedium( text: room.name!, style: context.titleMedium.copyWith( fontSize: 25, - color: HomeCubit.getInstance().selectedRoom == room - ? ColorsManager.textPrimaryColor - : ColorsManager.textPrimaryColor.withOpacity(.2), + color: + HomeCubit.getInstance().selectedRoom == room + ? ColorsManager.textPrimaryColor + : ColorsManager.textPrimaryColor + .withOpacity(.2), ), ), ), diff --git a/lib/features/devices/view/widgets/wizard_page.dart b/lib/features/devices/view/widgets/wizard_page.dart index 375cdf2..4db2bde 100644 --- a/lib/features/devices/view/widgets/wizard_page.dart +++ b/lib/features/devices/view/widgets/wizard_page.dart @@ -35,7 +35,7 @@ class WizardPage extends StatelessWidget { return StatefulBuilder( builder: (context, setState) { - return ListView( + return Column( children: [ if (groupsList.isNotEmpty) TextFormField( @@ -64,129 +64,170 @@ class WizardPage extends StatelessWidget { ), ), ), - GridView.builder( - gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 2, - crossAxisSpacing: 10, - mainAxisSpacing: 10, - childAspectRatio: 1.5, - ), - padding: const EdgeInsets.only(top: 10), - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - itemCount: _filteredGroups.length, - itemBuilder: (_, index) { - return GestureDetector( - onTap: () { - if (_filteredGroups[index].name == 'AC') { - Navigator.push( - context, - PageRouteBuilder( - pageBuilder: (context, animation1, animation2) => - const ACsView())); - } - if (_filteredGroups[index].name == '3G') { - Navigator.push( - context, - PageRouteBuilder( - pageBuilder: (context, animation1, animation2) => - const ThreeGangWizard())); - } - if (_filteredGroups[index].name == '2G') { - Navigator.push( - context, - PageRouteBuilder( - pageBuilder: (context, animation1, animation2) => - const TwoGangWizard())); - } - if (_filteredGroups[index].name == '1G') { - Navigator.push( - context, - PageRouteBuilder( - pageBuilder: (context, animation1, animation2) => - const OneGangWizard())); - } - if (_filteredGroups[index].name == 'WH') { - Navigator.push( - context, - PageRouteBuilder( - pageBuilder: (context, animation1, animation2) => - const WHWizard())); - } - - if (_filteredGroups[index].name == '1GT') { - Navigator.push( - context, - PageRouteBuilder( - pageBuilder: (context, animation1, animation2) => - const OneTouchWizard())); - } - - if (_filteredGroups[index].name == '2GT') { - Navigator.push( - context, - PageRouteBuilder( - pageBuilder: (context, animation1, animation2) => - const TwoTouchWizard())); - } - - if (_filteredGroups[index].name == '3GT') { - Navigator.push( - context, - PageRouteBuilder( - pageBuilder: (context, animation1, animation2) => - const ThreeTouchWizard())); - } - - if (_filteredGroups[index].name == 'GD') { - Navigator.push( - context, - PageRouteBuilder( - pageBuilder: (context, animation1, animation2) => - const GarageWizard())); - } - if (_filteredGroups[index].name == 'CUR') { - Navigator.push( - context, - PageRouteBuilder( - pageBuilder: (context, animation1, animation2) => - const CurtainsWizard())); - } - }, - child: DefaultContainer( - padding: const EdgeInsets.all(15), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.spaceBetween, + const SizedBox( + height: 10, + ), + _filteredGroups.isNotEmpty + ? Expanded( + child: ListView( + shrinkWrap: true, children: [ - Row( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - SvgPicture.asset( - _filteredGroups[index].icon!, - fit: BoxFit.contain, - ), - ], - ), - FittedBox( - fit: BoxFit.scaleDown, - child: BodyLarge( - text: _filteredGroups[index].name!, - style: context.bodyLarge.copyWith( - fontWeight: FontWeight.bold, - height: 0, - fontSize: 20, - color: Colors.grey, - ), + GridView.builder( + gridDelegate: + const SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 2, + crossAxisSpacing: 10, + mainAxisSpacing: 10, + childAspectRatio: 1.5, ), - ), + padding: const EdgeInsets.only(top: 10), + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + itemCount: _filteredGroups.length, + itemBuilder: (_, index) { + return GestureDetector( + onTap: () { + if (_filteredGroups[index].name == 'AC') { + Navigator.push( + context, + PageRouteBuilder( + pageBuilder: (context, animation1, + animation2) => + const ACsView())); + } + if (_filteredGroups[index].name == '3G') { + Navigator.push( + context, + PageRouteBuilder( + pageBuilder: (context, animation1, + animation2) => + const ThreeGangWizard())); + } + if (_filteredGroups[index].name == '2G') { + Navigator.push( + context, + PageRouteBuilder( + pageBuilder: (context, animation1, + animation2) => + const TwoGangWizard())); + } + if (_filteredGroups[index].name == '1G') { + Navigator.push( + context, + PageRouteBuilder( + pageBuilder: (context, animation1, + animation2) => + const OneGangWizard())); + } + if (_filteredGroups[index].name == 'WH') { + Navigator.push( + context, + PageRouteBuilder( + pageBuilder: (context, animation1, + animation2) => + const WHWizard())); + } + + if (_filteredGroups[index].name == '1GT') { + Navigator.push( + context, + PageRouteBuilder( + pageBuilder: (context, animation1, + animation2) => + const OneTouchWizard())); + } + + if (_filteredGroups[index].name == '2GT') { + Navigator.push( + context, + PageRouteBuilder( + pageBuilder: (context, animation1, + animation2) => + const TwoTouchWizard())); + } + + if (_filteredGroups[index].name == '3GT') { + Navigator.push( + context, + PageRouteBuilder( + pageBuilder: (context, animation1, + animation2) => + const ThreeTouchWizard())); + } + + if (_filteredGroups[index].name == 'GD') { + Navigator.push( + context, + PageRouteBuilder( + pageBuilder: (context, animation1, + animation2) => + const GarageWizard())); + } + if (_filteredGroups[index].name == 'CUR') { + Navigator.push( + context, + PageRouteBuilder( + pageBuilder: (context, animation1, + animation2) => + const CurtainsWizard())); + } + }, + child: DefaultContainer( + padding: const EdgeInsets.all(15), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + SvgPicture.asset( + _filteredGroups[index].icon!, + fit: BoxFit.contain, + ), + ], + ), + FittedBox( + fit: BoxFit.scaleDown, + child: BodyLarge( + text: _filteredGroups[index].name!, + style: context.bodyLarge.copyWith( + fontWeight: FontWeight.bold, + height: 0, + fontSize: 20, + color: Colors.grey, + ), + ), + ), + ], + ), + ), + ); + }, + ) + ], + ), + ) + : const Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Center( + child: Text( + 'No Results Found', + style: TextStyle( + color: ColorsManager.grayColor, + fontSize: 14, + fontWeight: FontWeight.w400), + )), ], ), ), - ); - }, - ), ], ); },