From 29d7378e93ee17065819cefba918a4c8f27f64cc Mon Sep 17 00:00:00 2001 From: MhdZiadHirati Date: Wed, 18 Oct 2023 16:39:19 +0300 Subject: [PATCH] refactoring --- lib/core/errors/custom_exception.dart | 72 +++---- .../widgets/voice_message.dart | 200 ------------------ .../screens/notification.dart | 2 +- .../splash_controller.dart | 38 ++-- 4 files changed, 57 insertions(+), 255 deletions(-) delete mode 100644 lib/features/chat/presentation_layer/widgets/voice_message.dart diff --git a/lib/core/errors/custom_exception.dart b/lib/core/errors/custom_exception.dart index 01e0577..0fde622 100644 --- a/lib/core/errors/custom_exception.dart +++ b/lib/core/errors/custom_exception.dart @@ -1,24 +1,24 @@ enum ExceptionType { - ConnectionError, + connectionError, // related to http status code exceptions - NotAuthorized, - NotAuthenticated, - NotFound, - InternalServerException, - ServiceUnavailableException, - PageGone, - ResourceAlreadyExists, - UnAcceptableOperation, + notAuthorized, + notAuthenticated, + notFound, + internalServerException, + serviceUnavailableException, + pageGone, + resourceAlreadyExists, + unAcceptableOperation, // related to bad request status code // related to auth requests - EmailAlreadyExists, - UserNameAlreadyExists, - PasswordInvalid, - InvalidCredentials, - VerifyTokenInvalid, - ResetCodeInvalid, - InvalidResetToken, + emailAlreadyExists, + userNameAlreadyExists, + passwordInvalid, + invalidCredentials, + verifyTokenInvalid, + resetCodeInvalid, + invalidResetToken, // SQL Lite Exceptions @@ -35,7 +35,7 @@ enum ExceptionType { // socket exception // other - Other, + other, } class GenericException implements Exception { @@ -60,83 +60,83 @@ class ValidationError extends GenericException { Map badRequestException = { "RESOURCE_ALREADY_EXISTS": GenericException( - type: ExceptionType.EmailAlreadyExists, + type: ExceptionType.emailAlreadyExists, errorMessage: "email_already_exists", ), "USERNAME_ALREADY_EXISTS": GenericException( - type: ExceptionType.UserNameAlreadyExists, + type: ExceptionType.userNameAlreadyExists, errorMessage: "username_already_exists", ), "PASSWORD_INVALID": GenericException( - type: ExceptionType.PasswordInvalid, + type: ExceptionType.passwordInvalid, errorMessage: "invalid_password", ), "INVALID_CREDENTIALS": GenericException( - type: ExceptionType.InvalidCredentials, + type: ExceptionType.invalidCredentials, errorMessage: "invalid_credentials", ), "VERIFY_TOKEN_INVALID": GenericException( - type: ExceptionType.VerifyTokenInvalid, + type: ExceptionType.verifyTokenInvalid, errorMessage: "invalid_verify_token", ), "RESET_CODE_INVALID": GenericException( - type: ExceptionType.ResetCodeInvalid, + type: ExceptionType.resetCodeInvalid, errorMessage: "invalid_reset_code", ), "INVALID_RESET_TOKEN": GenericException( - type: ExceptionType.InvalidResetToken, + type: ExceptionType.invalidResetToken, errorMessage: "invalid_reset_token", ), "NOT_VERIFIED": GenericException( //*********add*********** - type: ExceptionType.InvalidResetToken, + type: ExceptionType.invalidResetToken, errorMessage: "User is not verified", ), "UN_ACCEPTABLE_OPERATION": GenericException( - type: ExceptionType.UnAcceptableOperation, + type: ExceptionType.unAcceptableOperation, errorMessage: "un_acceptable_operation", ), "RESOURCE_NOT_FOUND": GenericException( - type: ExceptionType.NotFound, + type: ExceptionType.notFound, errorMessage: "resource_not_found", ), "INTERNAL_SERVER_ERROR": GenericException( - type: ExceptionType.InternalServerException, + type: ExceptionType.internalServerException, errorMessage: "internal_error", ), "NOT_AUTHENTICATED": GenericException( - type: ExceptionType.NotAuthenticated, + type: ExceptionType.notAuthenticated, errorMessage: "not_authenticated", ), "NOT_AUTHORIZED": GenericException( - type: ExceptionType.NotAuthorized, + type: ExceptionType.notAuthorized, errorMessage: "you_are_not_authorized", ), }; Map statusCodesException = { 403: GenericException( - type: ExceptionType.NotAuthorized, + type: ExceptionType.notAuthorized, errorMessage: "you_are_not_authorized", ), 401: GenericException( - type: ExceptionType.NotAuthorized, + type: ExceptionType.notAuthorized, errorMessage: "you_are_not_authorized", ), 404: GenericException( - type: ExceptionType.NotFound, + type: ExceptionType.notFound, errorMessage: "page_not_found", ), 410: GenericException( - type: ExceptionType.PageGone, + type: ExceptionType.pageGone, errorMessage: "page_gone", ), 500: GenericException( - type: ExceptionType.InternalServerException, + type: ExceptionType.internalServerException, errorMessage: "server_down", ), 503: GenericException( - type: ExceptionType.ServiceUnavailableException, + type: ExceptionType.serviceUnavailableException, errorMessage: "service_unavailable", ), }; diff --git a/lib/features/chat/presentation_layer/widgets/voice_message.dart b/lib/features/chat/presentation_layer/widgets/voice_message.dart deleted file mode 100644 index 7f31eb7..0000000 --- a/lib/features/chat/presentation_layer/widgets/voice_message.dart +++ /dev/null @@ -1,200 +0,0 @@ -import 'dart:io'; -import 'package:flutter/material.dart'; -import 'package:flutter_svg/svg.dart'; -import 'package:audio_waveforms/audio_waveforms.dart'; -import 'package:get/get.dart'; -import 'package:taafee_mobile/common/extensions/widget_extension.dart'; -import 'package:taafee_mobile/common/widgets/text.dart'; -import 'package:taafee_mobile/features/chat/business%20logic%20layer/chat_controller.dart'; -import 'package:taafee_mobile/features/chat/data_layer/model/message.dart'; -import 'package:taafee_mobile/features/home/business_logic_layer/home_controller.dart'; -import '../../../../common/const/const.dart'; - -class VoiceMessage extends StatefulWidget { - VoiceMessage({ - super.key, - this.file, - required this.textFieldFocusNode, - required this.messageModel, - this.dismissibleKey = const Key('sent'), - }); - final Key dismissibleKey; - final FocusNode textFieldFocusNode; - final MessageModel messageModel; - File? file; - @override - State createState() => _VoiceMessageState(); -} - -class _VoiceMessageState extends State { - final ChatController chatController = Get.find(); - final PlayerController playerController = PlayerController(); - final HomeController homeController = Get.find(); - bool isPlaying = false; - bool isLoading = false; - bool showDefaulWaves = true; - String? voiceUrl; - List waveFormData = Constants.defaulWaveFormData; - - @override - void initState() { - setState(() { - if (widget.file != null) { - playerController.preparePlayer(path: widget.file!.path); - showDefaulWaves = false; - if (chatController.voiceFiles[widget.messageModel.content] == null) { - chatController.voiceFiles[widget.messageModel.content] = widget.file!; - } - } - }); - voiceUrl = Domain.chatFiles + widget.messageModel.content; - - playerController.onCompletion.listen((event) { - setState(() { - isPlaying = false; - }); - }); - playerController.onPlayerStateChanged.listen((event) { - if (event.isPaused || event.isStopped) { - setState(() { - isPlaying = false; - }); - } - }); - super.initState(); - } - - @override - Widget build(BuildContext context) { - return Obx(() { - return Dismissible( - confirmDismiss: (direction) async { - chatController.updateReplyModel(messageModel: widget.messageModel); - if (chatController.isReplying.value == false) { - chatController.toggleIsReplying(); - } - - FocusScope.of(context).requestFocus(widget.textFieldFocusNode); - return false; - }, - key: widget.dismissibleKey, - onDismissed: null, - child: SizedBox( - width: Get.width * 0.7, - child: Container( - decoration: const BoxDecoration( - image: DecorationImage( - image: AssetImage('assets/images/sent message.png'), - fit: BoxFit.fill)), - child: SizedBox( - width: Get.width, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Row( - children: [ - if (isLoading) - const CircleAvatar( - radius: 21.3, - backgroundColor: Colors.white, - child: CircularProgressIndicator( - color: Colors.grey, - ), - ).paddingOnly(left: 16, top: 16), - if (widget.file == null && !isLoading) - CircleAvatar( - radius: 21.3, - backgroundColor: Colors.white, - child: const Icon( - Icons.download, - color: Colors.grey, - ).onTap(() async { - setState(() { - isPlaying = false; - isLoading = true; - }); - widget.file = await chatController.getVoiceFile( - id: widget.messageModel.content); - chatController - .voiceFiles[widget.messageModel.content] = - widget.file!; - await playerController.preparePlayer( - path: widget.file!.path); - - setState(() { - isLoading = false; - showDefaulWaves = false; - }); - }), - ).paddingOnly(left: 16, top: 16), - if (isPlaying) - CircleAvatar( - radius: 21.3, - backgroundColor: Colors.white, - child: const Icon( - Icons.stop, - color: Colors.grey, - ).onTap(() async { - setState(() { - isPlaying = false; - }); - - await playerController.pausePlayer(); - }), - ).paddingOnly(left: 16, top: 16), - if (!isPlaying && widget.file != null && !isLoading) - SvgPicture.asset('assets/icons/play_voice.svg') - .paddingOnly(top: 16, left: 16) - .onTap(() async { - setState(() { - isPlaying = true; - }); - await playerController.startPlayer( - finishMode: FinishMode.pause); - }), - Visibility( - visible: showDefaulWaves, - child: AudioFileWaveforms( - waveformData: waveFormData, - size: const Size(160, 50.0), - waveformType: WaveformType.fitWidth, - playerController: playerController, - ).paddingOnly( - left: homeController.isArabic.value ? 20 : 8, - ), - ), - Visibility( - visible: !showDefaulWaves, - child: AudioFileWaveforms( - size: const Size(160, 50.0), - waveformType: WaveformType.fitWidth, - playerController: playerController, - ).paddingOnly( - left: homeController.isArabic.value ? 20 : 8, - ), - ), - ], - ).paddingOnly( - right: homeController.isArabic.value ? 36 : 0, - ), - RegularTextWidget( - widget.messageModel.createdAt.toString().substring(11, 16), - color: Colors.white, - textAlign: TextAlign.right, - fontSize: 10, - ) - .align(alignment: Alignment.bottomRight) - .paddingOnly(right: Responsive.isTablet() ? 80 : 40), - const SizedBox( - height: 16, - ), - ], - ), - ).align(alignment: Alignment.centerRight), - ).align(alignment: Alignment.centerRight), - ).paddingOnly(left: Responsive.isTablet() ? 0 : 70, right: 0), - ).align(alignment: Alignment.centerRight); - }); - } -} diff --git a/lib/features/notification/presentation_layer/screens/notification.dart b/lib/features/notification/presentation_layer/screens/notification.dart index 38c3710..87ee7a7 100644 --- a/lib/features/notification/presentation_layer/screens/notification.dart +++ b/lib/features/notification/presentation_layer/screens/notification.dart @@ -41,7 +41,7 @@ class NotificationScreen extends StatelessWidget { Column( children: [ Lottie.asset( - 'assets/animations/Folder Lottie.json', + 'assets/animations/folder.json', repeat: false, ), RegularTextWidget( diff --git a/lib/features/splash/business_logic_layer/splash_controller.dart b/lib/features/splash/business_logic_layer/splash_controller.dart index 6b49fb4..69c6c20 100644 --- a/lib/features/splash/business_logic_layer/splash_controller.dart +++ b/lib/features/splash/business_logic_layer/splash_controller.dart @@ -1,4 +1,5 @@ -import 'dart:io'; +import 'dart:developer'; +// import 'dart:io'; import 'package:get/get.dart'; import 'package:package_info_plus/package_info_plus.dart'; @@ -10,7 +11,7 @@ import 'package:taafee_mobile/features/splash/data%20layer/source/splash_source. import 'package:rx_future/rx_future.dart'; import '../../auth/data_layer/model/user.dart'; -import '../data layer/model/params.dart'; +// import '../data layer/model/params.dart'; class SplashController extends GetxController { LocalStorage storage = LocalStorage(); @@ -73,7 +74,7 @@ class SplashController extends GetxController { showErrorResult.refresh(); } - print('err is${error.toString()}'); + log('err is${error.toString()}'); onError?.call(); }, @@ -100,21 +101,22 @@ class SplashController extends GetxController { {required Future Function(bool forced) versionAlert}) async { PackageInfo packageInfo = await PackageInfo.fromPlatform(); String appVersion = packageInfo.version; + log(appVersion); return true; - if (Platform.isAndroid) { - if (appVersion != Params.currentAndroidVersion) { - return await versionAlert(Params.forceUpdateAndroid); - } else { - return true; - } - } - if (Platform.isIOS) { - if (appVersion != Params.currentIosVersion) { - return await versionAlert(Params.forceUpdateIos); - } else { - return true; - } - } - return false; + // if (Platform.isAndroid) { + // if (appVersion != Params.currentAndroidVersion) { + // return await versionAlert(Params.forceUpdateAndroid); + // } else { + // return true; + // } + // } + // if (Platform.isIOS) { + // if (appVersion != Params.currentIosVersion) { + // return await versionAlert(Params.forceUpdateIos); + // } else { + // return true; + // } + // } + // return false; } }