refactoring
This commit is contained in:
parent
f4f07fd71f
commit
29d7378e93
|
|
@ -1,24 +1,24 @@
|
||||||
enum ExceptionType {
|
enum ExceptionType {
|
||||||
ConnectionError,
|
connectionError,
|
||||||
// related to http status code exceptions
|
// related to http status code exceptions
|
||||||
NotAuthorized,
|
notAuthorized,
|
||||||
NotAuthenticated,
|
notAuthenticated,
|
||||||
NotFound,
|
notFound,
|
||||||
InternalServerException,
|
internalServerException,
|
||||||
ServiceUnavailableException,
|
serviceUnavailableException,
|
||||||
PageGone,
|
pageGone,
|
||||||
ResourceAlreadyExists,
|
resourceAlreadyExists,
|
||||||
UnAcceptableOperation,
|
unAcceptableOperation,
|
||||||
|
|
||||||
// related to bad request status code
|
// related to bad request status code
|
||||||
// related to auth requests
|
// related to auth requests
|
||||||
EmailAlreadyExists,
|
emailAlreadyExists,
|
||||||
UserNameAlreadyExists,
|
userNameAlreadyExists,
|
||||||
PasswordInvalid,
|
passwordInvalid,
|
||||||
InvalidCredentials,
|
invalidCredentials,
|
||||||
VerifyTokenInvalid,
|
verifyTokenInvalid,
|
||||||
ResetCodeInvalid,
|
resetCodeInvalid,
|
||||||
InvalidResetToken,
|
invalidResetToken,
|
||||||
|
|
||||||
// SQL Lite Exceptions
|
// SQL Lite Exceptions
|
||||||
|
|
||||||
|
|
@ -35,7 +35,7 @@ enum ExceptionType {
|
||||||
// socket exception
|
// socket exception
|
||||||
|
|
||||||
// other
|
// other
|
||||||
Other,
|
other,
|
||||||
}
|
}
|
||||||
|
|
||||||
class GenericException implements Exception {
|
class GenericException implements Exception {
|
||||||
|
|
@ -60,83 +60,83 @@ class ValidationError extends GenericException {
|
||||||
|
|
||||||
Map<String, GenericException> badRequestException = {
|
Map<String, GenericException> badRequestException = {
|
||||||
"RESOURCE_ALREADY_EXISTS": GenericException(
|
"RESOURCE_ALREADY_EXISTS": GenericException(
|
||||||
type: ExceptionType.EmailAlreadyExists,
|
type: ExceptionType.emailAlreadyExists,
|
||||||
errorMessage: "email_already_exists",
|
errorMessage: "email_already_exists",
|
||||||
),
|
),
|
||||||
"USERNAME_ALREADY_EXISTS": GenericException(
|
"USERNAME_ALREADY_EXISTS": GenericException(
|
||||||
type: ExceptionType.UserNameAlreadyExists,
|
type: ExceptionType.userNameAlreadyExists,
|
||||||
errorMessage: "username_already_exists",
|
errorMessage: "username_already_exists",
|
||||||
),
|
),
|
||||||
"PASSWORD_INVALID": GenericException(
|
"PASSWORD_INVALID": GenericException(
|
||||||
type: ExceptionType.PasswordInvalid,
|
type: ExceptionType.passwordInvalid,
|
||||||
errorMessage: "invalid_password",
|
errorMessage: "invalid_password",
|
||||||
),
|
),
|
||||||
"INVALID_CREDENTIALS": GenericException(
|
"INVALID_CREDENTIALS": GenericException(
|
||||||
type: ExceptionType.InvalidCredentials,
|
type: ExceptionType.invalidCredentials,
|
||||||
errorMessage: "invalid_credentials",
|
errorMessage: "invalid_credentials",
|
||||||
),
|
),
|
||||||
"VERIFY_TOKEN_INVALID": GenericException(
|
"VERIFY_TOKEN_INVALID": GenericException(
|
||||||
type: ExceptionType.VerifyTokenInvalid,
|
type: ExceptionType.verifyTokenInvalid,
|
||||||
errorMessage: "invalid_verify_token",
|
errorMessage: "invalid_verify_token",
|
||||||
),
|
),
|
||||||
"RESET_CODE_INVALID": GenericException(
|
"RESET_CODE_INVALID": GenericException(
|
||||||
type: ExceptionType.ResetCodeInvalid,
|
type: ExceptionType.resetCodeInvalid,
|
||||||
errorMessage: "invalid_reset_code",
|
errorMessage: "invalid_reset_code",
|
||||||
),
|
),
|
||||||
"INVALID_RESET_TOKEN": GenericException(
|
"INVALID_RESET_TOKEN": GenericException(
|
||||||
type: ExceptionType.InvalidResetToken,
|
type: ExceptionType.invalidResetToken,
|
||||||
errorMessage: "invalid_reset_token",
|
errorMessage: "invalid_reset_token",
|
||||||
),
|
),
|
||||||
"NOT_VERIFIED": GenericException(
|
"NOT_VERIFIED": GenericException(
|
||||||
//*********add***********
|
//*********add***********
|
||||||
type: ExceptionType.InvalidResetToken,
|
type: ExceptionType.invalidResetToken,
|
||||||
errorMessage: "User is not verified",
|
errorMessage: "User is not verified",
|
||||||
),
|
),
|
||||||
"UN_ACCEPTABLE_OPERATION": GenericException(
|
"UN_ACCEPTABLE_OPERATION": GenericException(
|
||||||
type: ExceptionType.UnAcceptableOperation,
|
type: ExceptionType.unAcceptableOperation,
|
||||||
errorMessage: "un_acceptable_operation",
|
errorMessage: "un_acceptable_operation",
|
||||||
),
|
),
|
||||||
"RESOURCE_NOT_FOUND": GenericException(
|
"RESOURCE_NOT_FOUND": GenericException(
|
||||||
type: ExceptionType.NotFound,
|
type: ExceptionType.notFound,
|
||||||
errorMessage: "resource_not_found",
|
errorMessage: "resource_not_found",
|
||||||
),
|
),
|
||||||
"INTERNAL_SERVER_ERROR": GenericException(
|
"INTERNAL_SERVER_ERROR": GenericException(
|
||||||
type: ExceptionType.InternalServerException,
|
type: ExceptionType.internalServerException,
|
||||||
errorMessage: "internal_error",
|
errorMessage: "internal_error",
|
||||||
),
|
),
|
||||||
"NOT_AUTHENTICATED": GenericException(
|
"NOT_AUTHENTICATED": GenericException(
|
||||||
type: ExceptionType.NotAuthenticated,
|
type: ExceptionType.notAuthenticated,
|
||||||
errorMessage: "not_authenticated",
|
errorMessage: "not_authenticated",
|
||||||
),
|
),
|
||||||
"NOT_AUTHORIZED": GenericException(
|
"NOT_AUTHORIZED": GenericException(
|
||||||
type: ExceptionType.NotAuthorized,
|
type: ExceptionType.notAuthorized,
|
||||||
errorMessage: "you_are_not_authorized",
|
errorMessage: "you_are_not_authorized",
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
Map<int, GenericException> statusCodesException = {
|
Map<int, GenericException> statusCodesException = {
|
||||||
403: GenericException(
|
403: GenericException(
|
||||||
type: ExceptionType.NotAuthorized,
|
type: ExceptionType.notAuthorized,
|
||||||
errorMessage: "you_are_not_authorized",
|
errorMessage: "you_are_not_authorized",
|
||||||
),
|
),
|
||||||
401: GenericException(
|
401: GenericException(
|
||||||
type: ExceptionType.NotAuthorized,
|
type: ExceptionType.notAuthorized,
|
||||||
errorMessage: "you_are_not_authorized",
|
errorMessage: "you_are_not_authorized",
|
||||||
),
|
),
|
||||||
404: GenericException(
|
404: GenericException(
|
||||||
type: ExceptionType.NotFound,
|
type: ExceptionType.notFound,
|
||||||
errorMessage: "page_not_found",
|
errorMessage: "page_not_found",
|
||||||
),
|
),
|
||||||
410: GenericException(
|
410: GenericException(
|
||||||
type: ExceptionType.PageGone,
|
type: ExceptionType.pageGone,
|
||||||
errorMessage: "page_gone",
|
errorMessage: "page_gone",
|
||||||
),
|
),
|
||||||
500: GenericException(
|
500: GenericException(
|
||||||
type: ExceptionType.InternalServerException,
|
type: ExceptionType.internalServerException,
|
||||||
errorMessage: "server_down",
|
errorMessage: "server_down",
|
||||||
),
|
),
|
||||||
503: GenericException(
|
503: GenericException(
|
||||||
type: ExceptionType.ServiceUnavailableException,
|
type: ExceptionType.serviceUnavailableException,
|
||||||
errorMessage: "service_unavailable",
|
errorMessage: "service_unavailable",
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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<VoiceMessage> createState() => _VoiceMessageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _VoiceMessageState extends State<VoiceMessage> {
|
|
||||||
final ChatController chatController = Get.find<ChatController>();
|
|
||||||
final PlayerController playerController = PlayerController();
|
|
||||||
final HomeController homeController = Get.find<HomeController>();
|
|
||||||
bool isPlaying = false;
|
|
||||||
bool isLoading = false;
|
|
||||||
bool showDefaulWaves = true;
|
|
||||||
String? voiceUrl;
|
|
||||||
List<double> 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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -41,7 +41,7 @@ class NotificationScreen extends StatelessWidget {
|
||||||
Column(
|
Column(
|
||||||
children: [
|
children: [
|
||||||
Lottie.asset(
|
Lottie.asset(
|
||||||
'assets/animations/Folder Lottie.json',
|
'assets/animations/folder.json',
|
||||||
repeat: false,
|
repeat: false,
|
||||||
),
|
),
|
||||||
RegularTextWidget(
|
RegularTextWidget(
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import 'dart:io';
|
import 'dart:developer';
|
||||||
|
// import 'dart:io';
|
||||||
|
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:package_info_plus/package_info_plus.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 'package:rx_future/rx_future.dart';
|
||||||
|
|
||||||
import '../../auth/data_layer/model/user.dart';
|
import '../../auth/data_layer/model/user.dart';
|
||||||
import '../data layer/model/params.dart';
|
// import '../data layer/model/params.dart';
|
||||||
|
|
||||||
class SplashController extends GetxController {
|
class SplashController extends GetxController {
|
||||||
LocalStorage storage = LocalStorage();
|
LocalStorage storage = LocalStorage();
|
||||||
|
|
@ -73,7 +74,7 @@ class SplashController extends GetxController {
|
||||||
showErrorResult.refresh();
|
showErrorResult.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
print('err is${error.toString()}');
|
log('err is${error.toString()}');
|
||||||
|
|
||||||
onError?.call();
|
onError?.call();
|
||||||
},
|
},
|
||||||
|
|
@ -100,21 +101,22 @@ class SplashController extends GetxController {
|
||||||
{required Future<bool> Function(bool forced) versionAlert}) async {
|
{required Future<bool> Function(bool forced) versionAlert}) async {
|
||||||
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
||||||
String appVersion = packageInfo.version;
|
String appVersion = packageInfo.version;
|
||||||
|
log(appVersion);
|
||||||
return true;
|
return true;
|
||||||
if (Platform.isAndroid) {
|
// if (Platform.isAndroid) {
|
||||||
if (appVersion != Params.currentAndroidVersion) {
|
// if (appVersion != Params.currentAndroidVersion) {
|
||||||
return await versionAlert(Params.forceUpdateAndroid);
|
// return await versionAlert(Params.forceUpdateAndroid);
|
||||||
} else {
|
// } else {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (Platform.isIOS) {
|
// if (Platform.isIOS) {
|
||||||
if (appVersion != Params.currentIosVersion) {
|
// if (appVersion != Params.currentIosVersion) {
|
||||||
return await versionAlert(Params.forceUpdateIos);
|
// return await versionAlert(Params.forceUpdateIos);
|
||||||
} else {
|
// } else {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return false;
|
// return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user