add request and url utils
parent
25e0f0905f
commit
f973820a3b
|
@ -26,6 +26,8 @@ class AddMobile extends StatelessWidget {
|
|||
child: SafeArea(
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Add contact info"),
|
||||
centerTitle: true,
|
||||
backgroundColor: primary,
|
||||
elevation: 0,
|
||||
),
|
||||
|
|
|
@ -65,7 +65,7 @@ class SOSreceived extends StatelessWidget {
|
|||
),
|
||||
Positioned(
|
||||
top: blockSizeVertical * 3,
|
||||
child: SpinKitPulse(
|
||||
child: const SpinKitPulse(
|
||||
color: primary,
|
||||
size: 120,
|
||||
),
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:unit2/utils/text_container.dart';
|
||||
import 'package:unit2/utils/urls.dart';
|
||||
|
||||
class Request {
|
||||
static final Request _instance = Request();
|
||||
static Request get instance => _instance;
|
||||
int requestTimeout = 25;
|
||||
String host = Url.instance.host();
|
||||
|
||||
Future<Response> getRequest(
|
||||
{String? path,
|
||||
Map<String, String>? headers,
|
||||
Map<String, String>? param}) async {
|
||||
Response response;
|
||||
try {
|
||||
response = await get(Uri.http(host, path!, param), headers: headers)
|
||||
.timeout(Duration(seconds: requestTimeout));
|
||||
} on TimeoutException catch (_) {
|
||||
Fluttertoast.showToast(
|
||||
msg: timeoutError,
|
||||
toastLength: Toast.LENGTH_LONG,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
backgroundColor: Colors.black,
|
||||
);
|
||||
throw (timeoutError);
|
||||
} on SocketException catch (_) {
|
||||
Fluttertoast.showToast(
|
||||
msg: timeoutError,
|
||||
toastLength: Toast.LENGTH_LONG,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
backgroundColor: Colors.black,
|
||||
);
|
||||
throw (timeoutError);
|
||||
} on FormatException catch (_) {
|
||||
throw const FormatException(formatError);
|
||||
} on HttpException catch (_) {
|
||||
throw const HttpException(httpError);
|
||||
} on Error catch (e) {
|
||||
debugPrint("get request error: $e");
|
||||
Fluttertoast.showToast(
|
||||
msg: onError,
|
||||
toastLength: Toast.LENGTH_LONG,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
backgroundColor: Colors.black,
|
||||
);
|
||||
throw (onError);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
Future<Response> postRequest(
|
||||
{String? path,
|
||||
Map<String, String>? headers,
|
||||
Map? body,
|
||||
Map<String, String>? param}) async {
|
||||
Response response;
|
||||
try {
|
||||
response = await post(Uri.http(host, path!, param), headers: headers)
|
||||
.timeout(Duration(seconds: requestTimeout));
|
||||
} on TimeoutException catch (_) {
|
||||
Fluttertoast.showToast(
|
||||
msg: timeoutError,
|
||||
toastLength: Toast.LENGTH_LONG,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
backgroundColor: Colors.black,
|
||||
);
|
||||
throw (timeoutError);
|
||||
} on SocketException catch (_) {
|
||||
Fluttertoast.showToast(
|
||||
msg: timeoutError,
|
||||
toastLength: Toast.LENGTH_LONG,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
backgroundColor: Colors.black,
|
||||
);
|
||||
throw (timeoutError);
|
||||
} on FormatException catch (_) {
|
||||
throw const FormatException(formatError);
|
||||
} on HttpException catch (_) {
|
||||
throw const HttpException(httpError);
|
||||
} on Error catch (e) {
|
||||
debugPrint("post request error: $e");
|
||||
Fluttertoast.showToast(
|
||||
msg: onError,
|
||||
toastLength: Toast.LENGTH_LONG,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
backgroundColor: Colors.black,
|
||||
);
|
||||
throw (onError);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@ const String mobileNumberRequired = "You must add atleast one mobile";
|
|||
const String numericValidator = "Please a number only";
|
||||
const String mobile1 = "Mobile number 1";
|
||||
const String mobile2 = "Mobile number 2";
|
||||
const String currentLocation = "You current location";
|
||||
const String currentLocation = "Your current location";
|
||||
const String noModule = "No Module Assign";
|
||||
const String noModuleSubTitle =
|
||||
"Please contact the admin if you want to access a module.";
|
||||
|
@ -57,13 +57,18 @@ const String tapToScanQR = "TAP TO SCAN QR CODE";
|
|||
const String incoming = "INCOMING";
|
||||
const String setQRScannerSettings = "Set QR Scanner Settings";
|
||||
const String includeOtherInputs = "Include other inputs?";
|
||||
const String includeOtherInputsSubTitle = "Inputs such as body temperature, etc.";
|
||||
const String includeOtherInputsSubTitle =
|
||||
"Inputs such as body temperature, etc.";
|
||||
const String incomingORoutgoing = "Incoming or Outgoing?";
|
||||
const String incomingORoutgoingSubTitle = "incoming for entrance outgoing for exit.";
|
||||
const String incomingORoutgoingSubTitle =
|
||||
"incoming for entrance outgoing for exit.";
|
||||
const String fieldIsRequired = "This field is required";
|
||||
const String selectLevel = "Select level";
|
||||
const String selectEstablishment = "Select Establishment";
|
||||
//
|
||||
const String timeoutError = "Internet timeout! Please Check your connection";
|
||||
const String formatError = "Invalid Error";
|
||||
const String httpError = "Error getting requested data";
|
||||
const String onError = "Something went wrong! Please try again.";
|
||||
//
|
||||
//
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
class Url{
|
||||
static final Url _instance = Url();
|
||||
static Url get instance => instance;
|
||||
|
||||
|
||||
String host(){
|
||||
return '192.168.10.219:3000';
|
||||
}
|
||||
|
||||
String authentication(){
|
||||
return '/api/account/auth/login';
|
||||
}
|
||||
}
|
|
@ -49,7 +49,7 @@ packages:
|
|||
name: barcode_scan2
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.2.1"
|
||||
version: "4.2.3"
|
||||
boolean_selector:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -169,6 +169,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "6.1.4"
|
||||
file_utils:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: file_utils
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
fixnum:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -201,7 +208,7 @@ packages:
|
|||
name: flutter_custom_clippers
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
version: "2.1.0"
|
||||
flutter_form_builder:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -272,7 +279,7 @@ packages:
|
|||
name: fluttertoast
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "8.1.1"
|
||||
version: "8.1.2"
|
||||
form_builder_validators:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -287,6 +294,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.2.0"
|
||||
globbing:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: globbing
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
go_router:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -321,7 +335,7 @@ packages:
|
|||
name: image
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.2.2"
|
||||
version: "3.3.0"
|
||||
intl:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -517,7 +531,7 @@ packages:
|
|||
name: provider
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "6.0.4"
|
||||
version: "6.0.5"
|
||||
qr:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -580,14 +594,14 @@ packages:
|
|||
name: shared_preferences_linux
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
version: "2.1.2"
|
||||
shared_preferences_macos:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_macos
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.4"
|
||||
version: "2.0.5"
|
||||
shared_preferences_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -608,7 +622,7 @@ packages:
|
|||
name: shared_preferences_windows
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
version: "2.1.2"
|
||||
signature:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -634,7 +648,7 @@ packages:
|
|||
name: sqflite
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.2.0+3"
|
||||
version: "2.2.2"
|
||||
sqflite_common:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -670,6 +684,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.0+3"
|
||||
system_info2:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: system_info2
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.4"
|
||||
term_glyph:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -718,7 +739,7 @@ packages:
|
|||
name: win32
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.1.2"
|
||||
version: "3.1.3"
|
||||
xdg_directories:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -59,6 +59,7 @@ dependencies:
|
|||
qr_flutter: ^4.0.0
|
||||
signature: ^5.3.0
|
||||
awesome_dialog: ^3.0.2
|
||||
system_info2: ^2.0.4
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Reference in New Issue