From 288ea6a1e2048d08efebc4bd17a9706ef95b4f37 Mon Sep 17 00:00:00 2001 From: Abdullah Alassaf Date: Sun, 30 Jun 2024 15:10:01 +0300 Subject: [PATCH] Bug fixes --- lib/features/auth/bloc/auth_cubit.dart | 4 +- lib/features/auth/view/otp_view.dart | 17 +++-- lib/features/devices/model/device_model.dart | 38 +++++------ .../ceiling_sensor_interface.dart | 62 +++++++++-------- .../view/widgets/room_page_switch.dart | 5 +- .../view/widgets/three_gang/timer_screen.dart | 66 +++++++++++-------- .../widgets/manage_home/assign_devices.dart | 2 +- lib/utils/helpers/misc_string_helpers.dart | 15 +++-- 8 files changed, 112 insertions(+), 97 deletions(-) diff --git a/lib/features/auth/bloc/auth_cubit.dart b/lib/features/auth/bloc/auth_cubit.dart index 526a148..d665132 100644 --- a/lib/features/auth/bloc/auth_cubit.dart +++ b/lib/features/auth/bloc/auth_cubit.dart @@ -253,7 +253,7 @@ class AuthCubit extends Cubit { emit(AuthLoginError(message: 'Something went wrong')); } } catch (failure) { - emit(AuthLoginError(message: failure.toString())); + emit(AuthLoginError(message: 'Something went wrong')); return; } } @@ -268,7 +268,7 @@ class AuthCubit extends Cubit { (Route route) => false, ); } catch (failure) { - emit(AuthLogoutError(message: failure.toString())); + emit(AuthLogoutError(message: 'Something went wrong')); return; } } diff --git a/lib/features/auth/view/otp_view.dart b/lib/features/auth/view/otp_view.dart index 8d3e7c7..e8ca1da 100644 --- a/lib/features/auth/view/otp_view.dart +++ b/lib/features/auth/view/otp_view.dart @@ -18,8 +18,8 @@ import 'package:syncrow_app/utils/resource_manager/constants.dart'; import 'package:syncrow_app/utils/resource_manager/font_manager.dart'; class OtpView extends StatefulWidget { - final bool isForgetPage; - const OtpView({super.key,this.isForgetPage=false}); + final bool isForgetPage; + const OtpView({super.key, this.isForgetPage = false}); @override State createState() => _OtpViewState(); @@ -121,9 +121,13 @@ class _OtpViewState extends State { if (state is AuthOtpSuccess) { Navigator.of(context).pop(); Navigator.of(context).pop(); - widget.isForgetPage? - Navigator.push(context, MaterialPageRoute(builder: (context) => const CreateNewPasswordPage(),)): - Navigator.popAndPushNamed(context, Routes.homeRoute); + widget.isForgetPage + ? Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const CreateNewPasswordPage(), + )) + : Navigator.popAndPushNamed(context, Routes.homeRoute); } if (state is ResendOtpSuccess) { startTimer(30); @@ -194,8 +198,7 @@ class _OtpViewState extends State { }, child: RichText( text: TextSpan( - text: - 'We have sent the verification codeWe have sent the verification code to', + text: 'We have sent the verification code to', style: Theme.of(context).textTheme.titleSmall!.copyWith( color: Colors.white, fontWeight: FontsManager.regular, diff --git a/lib/features/devices/model/device_model.dart b/lib/features/devices/model/device_model.dart index 4d84eab..24cd95e 100644 --- a/lib/features/devices/model/device_model.dart +++ b/lib/features/devices/model/device_model.dart @@ -10,6 +10,7 @@ class DeviceModel { String? model; String? name; String? icon; + String? type; bool? isOnline; List status = []; String? productName; @@ -19,21 +20,21 @@ class DeviceModel { DeviceType? productType; bool isSelected = false; late List functions; - DeviceModel({ - this.activeTime, - // this.id, - this.localKey, - this.model, - this.name, - this.isOnline, - required this.status, - this.productName, - this.timeZone, - this.updateTime, - this.uuid, - this.productType, - this.icon, - }) { + DeviceModel( + {this.activeTime, + // this.id, + this.localKey, + this.model, + this.name, + this.isOnline, + required this.status, + this.productName, + this.timeZone, + this.updateTime, + this.uuid, + this.productType, + this.icon, + this.type}) { functions = getFunctions(productType!); } @@ -43,8 +44,7 @@ class DeviceModel { if (type == DeviceType.LightBulb) { tempIcon = Assets.assetsIconsLight; - } else if (type == DeviceType.CeilingSensor || - type == DeviceType.WallSensor) { + } else if (type == DeviceType.CeilingSensor || type == DeviceType.WallSensor) { tempIcon = Assets.assetsIconsSensors; } else if (type == DeviceType.AC) { tempIcon = Assets.assetsIconsAC; @@ -72,6 +72,7 @@ class DeviceModel { updateTime: json['updateTime'], uuid: json['uuid'], productType: type, + type: json['productType'], status: [], ); } @@ -92,6 +93,5 @@ class DeviceModel { }; } - List getFunctions(DeviceType type) => - devicesFunctionsMap[productType] ?? []; + List getFunctions(DeviceType type) => devicesFunctionsMap[productType] ?? []; } diff --git a/lib/features/devices/view/widgets/ceiling_sensor/ceiling_sensor_interface.dart b/lib/features/devices/view/widgets/ceiling_sensor/ceiling_sensor_interface.dart index bfc050f..3a186c1 100644 --- a/lib/features/devices/view/widgets/ceiling_sensor/ceiling_sensor_interface.dart +++ b/lib/features/devices/view/widgets/ceiling_sensor/ceiling_sensor_interface.dart @@ -160,19 +160,19 @@ class CeilingSensorInterface extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Column( - mainAxisSize: MainAxisSize.min, - children: [ - const Flexible(child: BodySmall(text: 'Sports Para')), - Flexible( - child: BodyLarge( + Flexible( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const BodySmall(text: 'Sports Para'), + BodyLarge( text: '0', style: context.bodyLarge.copyWith( fontWeight: FontsManager.bold, ), ), - ), - ], + ], + ), ), Padding( padding: const EdgeInsets.symmetric(horizontal: 10), @@ -182,24 +182,23 @@ class CeilingSensorInterface extends StatelessWidget { color: ColorsManager.greyColor, ), ), - Column( - mainAxisSize: MainAxisSize.min, - children: [ - const Flexible( - child: BodySmall( - text: 'Detection Range', - textOverflow: TextOverflow.ellipsis, - )), - Flexible( - child: BodyLarge( + Flexible( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const BodySmall( + text: 'Detection Range', + textOverflow: TextOverflow.ellipsis, + ), + BodyLarge( text: '0.0M', textOverflow: TextOverflow.ellipsis, style: context.bodyLarge.copyWith( fontWeight: FontsManager.bold, ), ), - ), - ], + ], + ), ), Padding( padding: const EdgeInsets.symmetric(horizontal: 10), @@ -209,24 +208,23 @@ class CeilingSensorInterface extends StatelessWidget { color: ColorsManager.greyColor, ), ), - Column( - mainAxisSize: MainAxisSize.min, - children: [ - const Flexible( - child: BodySmall( - text: 'Movement', - textOverflow: TextOverflow.ellipsis, - )), - Flexible( - child: BodyLarge( + Flexible( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const BodySmall( + text: 'Movement', + textOverflow: TextOverflow.ellipsis, + ), + BodyLarge( text: 'none', textOverflow: TextOverflow.ellipsis, style: context.bodyLarge.copyWith( fontWeight: FontsManager.bold, ), ), - ), - ], + ], + ), ), ], )), diff --git a/lib/features/devices/view/widgets/room_page_switch.dart b/lib/features/devices/view/widgets/room_page_switch.dart index 3538f17..d6efc2f 100644 --- a/lib/features/devices/view/widgets/room_page_switch.dart +++ b/lib/features/devices/view/widgets/room_page_switch.dart @@ -55,7 +55,7 @@ class RoomPageSwitch extends StatelessWidget { Flexible( child: FittedBox( child: Text( - device.name ?? "", + device.type ?? "", overflow: TextOverflow.ellipsis, maxLines: 2, style: context.bodyLarge.copyWith( @@ -109,8 +109,7 @@ void showDeviceInterface(DeviceModel device, BuildContext context) { Navigator.push( context, PageRouteBuilder( - pageBuilder: (context, animation1, animation2) => DoorInterface(doorLock: device)) - ); + pageBuilder: (context, animation1, animation2) => DoorInterface(doorLock: device))); // navigateToInterface(DoorInterface(doorlock: device), context); break; case DeviceType.Gateway: diff --git a/lib/features/devices/view/widgets/three_gang/timer_screen.dart b/lib/features/devices/view/widgets/three_gang/timer_screen.dart index a45d632..d5e1c8b 100644 --- a/lib/features/devices/view/widgets/three_gang/timer_screen.dart +++ b/lib/features/devices/view/widgets/three_gang/timer_screen.dart @@ -48,6 +48,7 @@ class TimerScreen extends StatelessWidget { builder: (context, state) { Duration duration = Duration.zero; int countNum = 0; + int tabNum = 0; if (state is UpdateTimerState) { countNum = state.seconds; } else if (state is TimerRunInProgress) { @@ -57,6 +58,10 @@ class TimerScreen extends StatelessWidget { } else if (state is LoadingNewSate) { countNum = 0; } + + if (state is ChangeSlidingSegmentState) { + tabNum = state.value; + } return PopScope( canPop: false, onPopInvoked: (didPop) { @@ -129,35 +134,38 @@ class TimerScreen extends StatelessWidget { }, ), ), - countNum > 0 - ? BodyLarge( - text: _formatDuration(countNum), - fontColor: ColorsManager.slidingBlueColor, - fontSize: 40, - ) - : CupertinoTimerPicker( - mode: CupertinoTimerPickerMode.hm, - onTimerDurationChanged: (Duration newDuration) { - duration = newDuration; - }, - ), - GestureDetector( - onTap: () { - if (state is LoadingNewSate) { - return; - } - if (countNum > 0) { - BlocProvider.of(context).add( - SetCounterValue( - deviceCode: deviceCode, duration: Duration.zero)); - } else if (duration != Duration.zero) { - BlocProvider.of(context).add( - SetCounterValue( - deviceCode: deviceCode, duration: duration)); - } - }, - child: SvgPicture.asset( - countNum > 0 ? Assets.pauseIcon : Assets.playIcon)) + if (tabNum == 0) + countNum > 0 + ? BodyLarge( + text: _formatDuration(countNum), + fontColor: ColorsManager.slidingBlueColor, + fontSize: 40, + ) + : CupertinoTimerPicker( + mode: CupertinoTimerPickerMode.hm, + onTimerDurationChanged: (Duration newDuration) { + duration = newDuration; + }, + ), + if (tabNum == 0) + GestureDetector( + onTap: () { + if (state is LoadingNewSate) { + return; + } + if (countNum > 0) { + BlocProvider.of(context).add( + SetCounterValue( + deviceCode: deviceCode, + duration: Duration.zero)); + } else if (duration != Duration.zero) { + BlocProvider.of(context).add( + SetCounterValue( + deviceCode: deviceCode, duration: duration)); + } + }, + child: SvgPicture.asset( + countNum > 0 ? Assets.pauseIcon : Assets.playIcon)) ], ))); }, diff --git a/lib/features/menu/view/widgets/manage_home/assign_devices.dart b/lib/features/menu/view/widgets/manage_home/assign_devices.dart index 51b5710..bc097fb 100644 --- a/lib/features/menu/view/widgets/manage_home/assign_devices.dart +++ b/lib/features/menu/view/widgets/manage_home/assign_devices.dart @@ -20,7 +20,7 @@ class AssignDeviceView extends StatelessWidget { child: BlocConsumer(listener: (context, state) { if (state is FetchDeviceByRoomIdState) { if (state.allDevices.isEmpty) { - CustomSnackBar.displaySnackBar('No devices available for this user'); + CustomSnackBar.displaySnackBar('You do not have the permission to assign devices'); Navigator.of(context).pop(); } } diff --git a/lib/utils/helpers/misc_string_helpers.dart b/lib/utils/helpers/misc_string_helpers.dart index b0b71aa..14a2a92 100644 --- a/lib/utils/helpers/misc_string_helpers.dart +++ b/lib/utils/helpers/misc_string_helpers.dart @@ -63,9 +63,16 @@ class StringHelpers { } static String toTitleCase(String text) { - return text - .split(' ') - .map((word) => word[0].toUpperCase() + word.substring(1)) - .join(' '); + if (text.contains(' ')) { + //remove empty elements + String title = text.split(' ').where((element) => element.isNotEmpty).join(' '); + String result = title + .split(' ') + .map((element) => element[0].toUpperCase() + element.substring(1)) + .join(' '); + return result; + } else { + return text.toUpperCase(); + } } }