App update screen implemented

merge-requests/117/head
haroon amjad 3 years ago
parent b3782f6342
commit 8a393c1e73

@ -14,11 +14,12 @@ typedef FactoryConstructor<U> = U Function(dynamic);
class APIError {
int? errorCode;
int? errorType;
String? errorMessage;
APIError(this.errorCode, this.errorMessage);
APIError(this.errorCode, this.errorMessage, this.errorType);
Map<String, dynamic> toJson() => {'errorCode': errorCode, 'errorMessage': errorMessage};
Map<String, dynamic> toJson() => {'errorCode': errorCode, 'errorMessage': errorMessage, 'errorType': errorType,};
@override
String toString() {
@ -33,14 +34,14 @@ APIException _throwAPIException(Response response) {
if (response.body != null && response.body.isNotEmpty) {
var jsonError = jsonDecode(response.body);
print(jsonError);
apiError = APIError(jsonError['ErrorCode'], jsonError['ErrorMessage']);
apiError = APIError(jsonError['ErrorCode'], jsonError['ErrorMessage'], jsonError['ErrorType']);
}
return APIException(APIException.BAD_REQUEST, error: apiError);
case 400:
APIError? apiError;
if (response.body != null && response.body.isNotEmpty) {
var jsonError = jsonDecode(response.body);
apiError = APIError(jsonError['ErrorCode'], jsonError['ErrorMessage']);
apiError = APIError(jsonError['ErrorCode'], jsonError['ErrorMessage'], jsonError['ErrorType']);
}
return APIException(APIException.BAD_REQUEST, error: apiError);
case 401:
@ -90,7 +91,7 @@ class ApiClient {
return factoryConstructor(jsonData);
} else {
APIError? apiError;
apiError = APIError(jsonData['ErrorCode'], jsonData['ErrorEndUserMessage']);
apiError = APIError(jsonData['ErrorCode'], jsonData['ErrorEndUserMessage'], jsonData['ErrorType']);
throw APIException(APIException.BAD_REQUEST, error: apiError);
}
// } catch (ex) {

@ -64,7 +64,7 @@ class AppState {
String? get getMarathonProjectId => _projectID;
final PostParamsModel _postParamsInitConfig = PostParamsModel(channel: 31, versionID: 5.0, mobileType: Platform.isAndroid ? "android" : "ios");
final PostParamsModel _postParamsInitConfig = PostParamsModel(channel: 31, versionID: 3.8, mobileType: Platform.isAndroid ? "android" : "ios");
void setPostParamsInitConfig() {
isAuthenticated = false;

@ -98,33 +98,37 @@ class Utils {
static void handleException(dynamic exception, cxt, Function(String)? onErrorMessage) {
String errorMessage;
if (exception is APIException) {
if (exception.message == APIException.UNAUTHORIZED) {
return;
if (exception.error.errorType != null && exception.error.errorType == 4) {
Navigator.pushNamedAndRemoveUntil(cxt, AppRoutes.appUpdateScreen, (_) => false, arguments: exception.error?.errorMessage);
} else {
if (exception is APIException) {
if (exception.message == APIException.UNAUTHORIZED) {
return;
} else {
errorMessage = exception.error?.errorMessage ?? exception.message;
}
} else {
errorMessage = exception.error?.errorMessage ?? exception.message;
errorMessage = APIException.UNKNOWN;
}
} else {
errorMessage = APIException.UNKNOWN;
}
if (onErrorMessage != null) {
onErrorMessage(errorMessage);
} else {
if (!AppState().isAuthenticated) {
showDialog(
context: cxt,
builder: (cxt) => ConfirmDialog(
message: errorMessage,
onTap: () {
Navigator.pushNamedAndRemoveUntil(cxt, AppRoutes.login, (Route<dynamic> route) => false);
},
),
);
if (onErrorMessage != null) {
onErrorMessage(errorMessage);
} else {
if (cxt != null) {
confirmDialog(cxt, errorMessage);
if (!AppState().isAuthenticated) {
showDialog(
context: cxt,
builder: (cxt) => ConfirmDialog(
message: errorMessage,
onTap: () {
Navigator.pushNamedAndRemoveUntil(cxt, AppRoutes.login, (Route<dynamic> route) => false);
},
),
);
} else {
showToast(errorMessage);
if (cxt != null) {
confirmDialog(cxt, errorMessage);
} else {
showToast(errorMessage);
}
}
}
}

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:mohem_flutter_app/ui/app_update_screen.dart';
import 'package:mohem_flutter_app/ui/attendance/add_vacation_rule_screen.dart';
import 'package:mohem_flutter_app/ui/attendance/monthly_attendance_screen.dart';
import 'package:mohem_flutter_app/ui/attendance/vacation_rule_screen.dart';
@ -191,6 +192,7 @@ class AppRoutes {
static const String marathonWaitingScreen = "/marathonWaitingScreen";
static const String unsafeDeviceScreen = "/unsafeDeviceScreen";
static const String appUpdateScreen = "/appUpdateScreen";
static final Map<String, WidgetBuilder> routes = {
login: (BuildContext context) => LoginScreen(),
@ -302,5 +304,6 @@ class AppRoutes {
marathonWaitingScreen: (BuildContext context) => const MarathonWaitingScreen(),
unsafeDeviceScreen: (BuildContext context) => const UnsafeDeviceScreen(),
appUpdateScreen: (BuildContext context) => const AppUpdateScreen(),
};
}

@ -0,0 +1,56 @@
import 'dart:io';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:mohem_flutter_app/extensions/int_extensions.dart';
import 'package:mohem_flutter_app/extensions/string_extensions.dart';
import 'package:mohem_flutter_app/extensions/widget_extensions.dart';
import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
import 'package:mohem_flutter_app/widgets/button/default_button.dart';
import 'package:url_launcher/url_launcher.dart';
class AppUpdateScreen extends StatefulWidget {
const AppUpdateScreen({Key? key}) : super(key: key);
@override
State<AppUpdateScreen> createState() => _UnsafeDeviceScreenState();
}
class _UnsafeDeviceScreenState extends State<AppUpdateScreen> {
String? dynamicParams;
@override
Widget build(BuildContext context) {
dynamicParams ??= ModalRoute.of(context)!.settings.arguments as String;
return Scaffold(
body: SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
21.height,
Center(child: Image.asset("assets/images/logos/main_mohemm_logo.png", width: 200, height: 50)),
50.height,
"Please Update Your App".toText24(isBold: true),
48.height,
dynamicParams.toString().toText14(isCenter: true).paddingOnly(left: 20.0, right: 20.0),
21.height,
DefaultButton(LocaleKeys.ok.tr(), () async {
if (Platform.isAndroid || Platform.isIOS) {
var appId = Platform.isAndroid ? 'hmg.cloudSolutions.mohem' : '1468856602';
var url = Uri.parse(
Platform.isAndroid ? "market://details?id=$appId" : "https://apps.apple.com/app/id$appId",
);
launchUrl(
url,
mode: LaunchMode.externalApplication,
);
}
}).paddingAll(24)
],
),
),
);
}
}
Loading…
Cancel
Save