add request and url utils

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
rodolfobacuinjr 2023-01-17 15:52:31 +08:00
parent 25e0f0905f
commit f973820a3b
7 changed files with 154 additions and 15 deletions

View File

@ -26,6 +26,8 @@ class AddMobile extends StatelessWidget {
child: SafeArea( child: SafeArea(
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text("Add contact info"),
centerTitle: true,
backgroundColor: primary, backgroundColor: primary,
elevation: 0, elevation: 0,
), ),

View File

@ -65,7 +65,7 @@ class SOSreceived extends StatelessWidget {
), ),
Positioned( Positioned(
top: blockSizeVertical * 3, top: blockSizeVertical * 3,
child: SpinKitPulse( child: const SpinKitPulse(
color: primary, color: primary,
size: 120, size: 120,
), ),

View File

@ -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;
}
}

View File

@ -5,7 +5,7 @@ const String mobileNumberRequired = "You must add atleast one mobile";
const String numericValidator = "Please a number only"; const String numericValidator = "Please a number only";
const String mobile1 = "Mobile number 1"; const String mobile1 = "Mobile number 1";
const String mobile2 = "Mobile number 2"; 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 noModule = "No Module Assign";
const String noModuleSubTitle = const String noModuleSubTitle =
"Please contact the admin if you want to access a module."; "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 incoming = "INCOMING";
const String setQRScannerSettings = "Set QR Scanner Settings"; const String setQRScannerSettings = "Set QR Scanner Settings";
const String includeOtherInputs = "Include other inputs?"; 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 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 fieldIsRequired = "This field is required";
const String selectLevel = "Select level"; const String selectLevel = "Select level";
const String selectEstablishment = "Select Establishment"; 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.";
// //
// //

View File

@ -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';
}
}

View File

@ -49,7 +49,7 @@ packages:
name: barcode_scan2 name: barcode_scan2
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "4.2.1" version: "4.2.3"
boolean_selector: boolean_selector:
dependency: transitive dependency: transitive
description: description:
@ -169,6 +169,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "6.1.4" version: "6.1.4"
file_utils:
dependency: transitive
description:
name: file_utils
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
fixnum: fixnum:
dependency: transitive dependency: transitive
description: description:
@ -201,7 +208,7 @@ packages:
name: flutter_custom_clippers name: flutter_custom_clippers
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.0" version: "2.1.0"
flutter_form_builder: flutter_form_builder:
dependency: "direct main" dependency: "direct main"
description: description:
@ -272,7 +279,7 @@ packages:
name: fluttertoast name: fluttertoast
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "8.1.1" version: "8.1.2"
form_builder_validators: form_builder_validators:
dependency: "direct main" dependency: "direct main"
description: description:
@ -287,6 +294,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.2.0" version: "2.2.0"
globbing:
dependency: transitive
description:
name: globbing
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
go_router: go_router:
dependency: "direct main" dependency: "direct main"
description: description:
@ -321,7 +335,7 @@ packages:
name: image name: image
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.2.2" version: "3.3.0"
intl: intl:
dependency: "direct main" dependency: "direct main"
description: description:
@ -517,7 +531,7 @@ packages:
name: provider name: provider
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "6.0.4" version: "6.0.5"
qr: qr:
dependency: transitive dependency: transitive
description: description:
@ -580,14 +594,14 @@ packages:
name: shared_preferences_linux name: shared_preferences_linux
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.1" version: "2.1.2"
shared_preferences_macos: shared_preferences_macos:
dependency: transitive dependency: transitive
description: description:
name: shared_preferences_macos name: shared_preferences_macos
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.4" version: "2.0.5"
shared_preferences_platform_interface: shared_preferences_platform_interface:
dependency: transitive dependency: transitive
description: description:
@ -608,7 +622,7 @@ packages:
name: shared_preferences_windows name: shared_preferences_windows
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.1" version: "2.1.2"
signature: signature:
dependency: "direct main" dependency: "direct main"
description: description:
@ -634,7 +648,7 @@ packages:
name: sqflite name: sqflite
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.2.0+3" version: "2.2.2"
sqflite_common: sqflite_common:
dependency: transitive dependency: transitive
description: description:
@ -670,6 +684,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.0.0+3" 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: term_glyph:
dependency: transitive dependency: transitive
description: description:
@ -718,7 +739,7 @@ packages:
name: win32 name: win32
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.1.2" version: "3.1.3"
xdg_directories: xdg_directories:
dependency: transitive dependency: transitive
description: description:

View File

@ -59,6 +59,7 @@ dependencies:
qr_flutter: ^4.0.0 qr_flutter: ^4.0.0
signature: ^5.3.0 signature: ^5.3.0
awesome_dialog: ^3.0.2 awesome_dialog: ^3.0.2
system_info2: ^2.0.4
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: