DiscoverModule/lib/ui_screen/interactionform/mockapi.dart

634 lines
22 KiB
Dart

import 'dart:convert';
import 'dart:developer';
import 'dart:io';
import 'package:dio/dio.dart';
import 'package:dio/io.dart';
import 'package:discover_module/ui_screen/interactionform/model/interaction_config_data.dart';
import 'package:http_mock_adapter/http_mock_adapter.dart';
// import 'package:pwa_ios/model/interaction_config_data.dart';
class MockApiCall {
Future<dynamic> getConfigData() async {
print("Iam_getConfig");
// final dio = Dio(BaseOptions());
final dio = Dio();
final response = await dio.get('https://passvault.konectar.io/forms');
print("response1_isssss");
// print(response.data.toString());
// log(jsonEncode(response.data));
final parsedJson = json.encode(response.data);
print(parsedJson);
return response.data;
}
Future<dynamic> postConfigData(var jsonObj) async {
// final dio = Dio(BaseOptions());
final dio = Dio();
dio.httpClientAdapter = IOHttpClientAdapter(
createHttpClient: () {
// Don't trust any certificate just because their root cert is trusted.
final HttpClient client =
HttpClient(context: SecurityContext(withTrustedRoots: false));
// You can test the intermediate / root cert here. We just ignore it.
client.badCertificateCallback =
((X509Certificate cert, String host, int port) => true);
return client;
},
);
//final dioAdapter = DioAdapter(dio: dio);
// dynamic jsonResult = jsonDecode(
// await rootBundle.loadString("assets/images/interactiondata.json"));
// Set up a mock response for GET requests to "https://example.com"
// dio.get('192.168.2.64/passvault/public/forms'
// (server) => server.reply(
// 200,
// jsonResult,
// // Delay the response by 1 second
// delay: const Duration(seconds: 1),
// ),
// );
// Send a GET request to "https://example.com" using Dio
final response = await dio
.post('http://192.168.2.64/konectar-app/public/forms', data: jsonObj);
UIDataResponse dataResponse = UIDataResponse.fromJson(response.data);
// The response should contain the mock data we registered
print("response2_iss");
print(response.data);
return dataResponse;
}
// Future<void> getConfigWidgetData() async {
// final dio = Dio(BaseOptions());
// final dioAdapter = DioAdapter(dio: dio);
// dynamic jsonResult = jsonDecode(
// await rootBundle.loadString("assets/images/interactiondata.json"));
// // Set up a mock response for GET requests to "https://example.com"
// dioAdapter.onGet(
// 'https://example.com',
// (server) => server.reply(
// 200,
// jsonResult,
// // Delay the response by 1 second
// delay: const Duration(seconds: 1),
// ),
// );
// // Send a GET request to "https://example.com" using Dio
// final response = await dio.get('https://example.com');
// // The response should contain the mock data we registered
// print(response.data); // {messa
// }
Future<void> postFormData(var jsonObj) async {
final dio = Dio(BaseOptions());
final dioAdapter = DioAdapter(dio: dio);
dioAdapter.onPost(
'https://example.com',
data: jsonObj,
(server) => server.reply(
200,
{"message": "success"},
// Delay the response by 1 second
delay: const Duration(seconds: 1),
),
);
// Send a GET request to "https://example.com" using Dio
final response = await dio.post(
'http://192.168.2.64/konectar-app/public/push_data',
data: jsonObj);
// The response should contain the mock data we registered
print(response.data); // {messa
}
Future<dynamic> postSavedData(var jsonObj) async {
// final dio = Dio(BaseOptions());
final dio = Dio();
// ignore: deprecated_member_use
(dio.httpClientAdapter as IOHttpClientAdapter).onHttpClientCreate =
(HttpClient client) {
client.badCertificateCallback =
(X509Certificate cert, String host, int port) => true;
return client;
};
final options = Options(
sendTimeout: const Duration(seconds: 15),
receiveTimeout: const Duration(seconds: 15),
);
final response = await dio.get('https://passvault.konectar.io/push_data',
options: options, data: jsonObj);
//UIDataResponse dataResponse = UIDataResponse.fromJson(response.data);
// The response should contain the mock data we registered
print("response3");
print(response.data);
return response.data;
}
Future<bool> uploadFileAndJsonData(var jsonObj) async {
// {required File empFace, required String empCode}
const url = 'http://192.168.2.64/konectar-app/public/push_data';
try {
var formData = FormData.fromMap({
"files": [
MultipartFile.fromFileSync(
"/Users/aissel/Library/Developer/CoreSimulator/Devices/1E435121-7E65-45C6-9E0B-411C8B9915F5/data/Containers/Data/Application/3CBC1CFF-79AD-49FA-A6E0-13D0AA2959D2/tmp/Flutter Questionaire.pdf",
filename: "upload.txt"),
MultipartFile.fromFileSync("./example/upload.txt",
filename: "upload.txt"),
],
"data": jsonObj
});
final response = await Dio().post(
url,
data: jsonObj,
);
if (response.statusCode == 200) {
var map = response.data as Map;
print("result $map");
print('success');
if (map['status'] == 'Successfully registered') {
return true;
} else {
return false;
}
} else if (response.statusCode != 200) {
var map = response.data as Map;
print("result $map");
//BotToast is a package for toasts available on pub.dev
// BotToast.showText(text: 'Validation Error Occurs');
return false;
}
} on DioException catch (error) {
log(error.message!);
throw 'Something Went Wrong';
} catch (_) {
log(_.toString());
throw 'Something Went Wrong';
}
return false;
}
Future<dynamic> getConfigData123() async {
// final dio = Dio(BaseOptions());
final dio = Dio();
dio.httpClientAdapter = IOHttpClientAdapter(
createHttpClient: () {
// Don't trust any certificate just because their root cert is trusted.
final HttpClient client =
HttpClient(context: SecurityContext(withTrustedRoots: false));
// You can test the intermediate / root cert here. We just ignore it.
client.badCertificateCallback =
((X509Certificate cert, String host, int port) => true);
return client;
},
);
// final response = await dio.get('https://passvault.konectar.io/forms');
print("response123456");
// print(response.data.toString());
//log('${jsonEncode()}');
return {
"success": true,
"message": "New form generated",
"data": [
{
"id": "form-pooja",
"name": "form-pooja1 demo",
"formtype": "Event",
"form-fields": [
{
"sectionName": "section0",
"multiple": false,
"sectionList": [
{
"name": "field_0_0",
"id": "field_0_0",
"depid": "",
"widget": "checkbox",
"input": "radio",
"validation": {"isRequired": true},
"inputList": [
{"id": "1", "name": "Option 1"},
{"id": "2", "name": "Option 2"},
{"id": "3", "name": "Option 3"},
{"id": "4", "name": "Option 4"},
{"id": "5", "name": "Option 5"},
{"id": "6", "name": "Option 6"},
{"id": "7", "name": "Option 7"}
]
},
{
"name": "field_0_1",
"id": "field_0_1",
"depid": "",
"widget": "dropdown",
"input": "checkbox",
"validation": {"isRequired": true},
"inputList": [
{"id": "1", "name": "Option 1"},
{"id": "2", "name": "Option 2"},
{"id": "3", "name": "Option 3"},
{"id": "4", "name": "Option 4"},
{"id": "5", "name": "Option 5"},
{"id": "6", "name": "Option 6"},
{"id": "7", "name": "Option 7"}
]
},
{
"name": "field_0_2",
"id": "field_0_2",
"depid": "",
"widget": "text",
"input": "date",
"validation": {"isRequired": true}
}
]
},
{
"sectionName": "section1",
"multiple": true,
"sectionList": [
{
"name": "field_1_0",
"id": "field_1_0",
"depid": "",
"widget": "multiselect",
"input": "number",
"validation": {"isRequired": true},
"inputList": [
{"id": "1", "name": "Option 1"},
{"id": "2", "name": "Option 2"},
{"id": "3", "name": "Option 3"},
{"id": "4", "name": "Option 4"},
{"id": "5", "name": "Option 5"},
{"id": "6", "name": "Option 6"},
{"id": "7", "name": "Option 7"}
]
},
{
"name": "field_1_1",
"id": "field_1_1",
"depid": "",
"widget": "autocomplete",
"input": "checkbox",
"validation": {"isRequired": true},
"inputList": [
{"id": "1", "name": "Option 1"},
{"id": "2", "name": "Option 2"},
{"id": "3", "name": "Option 3"},
{"id": "4", "name": "Option 4"},
{"id": "5", "name": "Option 5"},
{"id": "6", "name": "Option 6"},
{"id": "7", "name": "Option 7"}
]
},
{
"name": "field_1_2",
"id": "field_1_2",
"depid": "",
"widget": "checkbox",
"input": "dropdown",
"validation": {"isRequired": false},
"inputList": [
{"id": "1", "name": "Option 1"},
{"id": "2", "name": "Option 2"},
{"id": "3", "name": "Option 3"},
{"id": "4", "name": "Option 4"},
{"id": "5", "name": "Option 5"},
{"id": "6", "name": "Option 6"},
{"id": "7", "name": "Option 7"}
]
},
{
"name": "field_1_3",
"id": "field_1_3",
"depid": "",
"widget": "checkbox",
"input": "date",
"validation": {"isRequired": true},
"inputList": [
{"id": "1", "name": "Option 1"},
{"id": "2", "name": "Option 2"},
{"id": "3", "name": "Option 3"},
{"id": "4", "name": "Option 4"},
{"id": "5", "name": "Option 5"},
{"id": "6", "name": "Option 6"},
{"id": "7", "name": "Option 7"}
]
},
{
"name": "field_1_4",
"id": "field_1_4",
"depid": "",
"widget": "dropdown",
"input": "autocomplete",
"validation": {"isRequired": true},
"inputList": [
{"id": "1", "name": "Option 1"},
{"id": "2", "name": "Option 2"},
{"id": "3", "name": "Option 3"},
{"id": "4", "name": "Option 4"},
{"id": "5", "name": "Option 5"},
{"id": "6", "name": "Option 6"},
{"id": "7", "name": "Option 7"}
]
}
]
}
]
}
]
};
}
Future<dynamic> getConfigDataMedical() async {
// final dio = Dio(BaseOptions());
final dio = Dio();
// (dio.httpClientAdapter as IOHttpClientAdapter).onHttpClientCreate =
// (HttpClient client) {
// client.badCertificateCallback =
// (X509Certificate cert, String host, int port) => true;
// return client;
// };
dio.httpClientAdapter = IOHttpClientAdapter(
createHttpClient: () {
// Don't trust any certificate just because their root cert is trusted.
final HttpClient client =
HttpClient(context: SecurityContext(withTrustedRoots: false));
// You can test the intermediate / root cert here. We just ignore it.
client.badCertificateCallback =
((X509Certificate cert, String host, int port) => true);
return client;
},
);
// final response = await dio.get('https://passvault.konectar.io/forms');
print("response123456");
// print(response.data.toString());
//log('${jsonEncode()}');
return {
"success": true,
"message": "New form generated",
"data": [
{
"id": "form-med",
"name": "form-med demo",
"formtype": "Event",
"form-fields": [
{
"sectionName": "section0",
"multiple": false,
"sectionList": [
{
"name": "field_0_0",
"id": "field_0_0",
"depid": "",
"widget": "checkbox",
"input": "radio",
"validation": {"isRequired": true},
"inputList": [
{"id": "1", "name": "Option 1"},
{"id": "2", "name": "Option 2"},
{"id": "3", "name": "Option 3"},
{"id": "4", "name": "Option 4"},
{"id": "5", "name": "Option 5"},
{"id": "6", "name": "Option 6"},
{"id": "7", "name": "Option 7"}
]
},
{
"name": "field_0_1",
"id": "field_0_1",
"depid": "",
"widget": "dropdown",
"input": "checkbox",
"validation": {"isRequired": true},
"inputList": [
{"id": "1", "name": "Option 1"},
{"id": "2", "name": "Option 2"},
{"id": "3", "name": "Option 3"},
{"id": "4", "name": "Option 4"},
{"id": "5", "name": "Option 5"},
{"id": "6", "name": "Option 6"},
{"id": "7", "name": "Option 7"}
]
},
{
"name": "field_0_2",
"id": "field_0_2",
"depid": "",
"widget": "text",
"input": "date",
"validation": {"isRequired": true}
}
]
},
]
}
]
};
}
Future<dynamic> getConfigDataEng() async {
// final dio = Dio(BaseOptions());
final dio = Dio();
// (dio.httpClientAdapter as IOHttpClientAdapter).onHttpClientCreate =
// (HttpClient client) {
// client.badCertificateCallback =
// (X509Certificate cert, String host, int port) => true;
// return client;
// };
dio.httpClientAdapter = IOHttpClientAdapter(
createHttpClient: () {
// Don't trust any certificate just because their root cert is trusted.
final HttpClient client =
HttpClient(context: SecurityContext(withTrustedRoots: false));
// You can test the intermediate / root cert here. We just ignore it.
client.badCertificateCallback =
((X509Certificate cert, String host, int port) => true);
return client;
},
);
// final response = await dio.get('https://passvault.konectar.io/forms');
print("response123456");
// print(response.data.toString());
//log('${jsonEncode()}');
return {
"success": true,
"message": "New form generated",
"data": [
{
"id": "form-eng",
"name": "form-eng demo",
"formtype": "Event",
"form-fields": [
{
"sectionName": "section0",
"multiple": false,
"sectionList": [
{
"name": "field_0_0",
"id": "field_0_0",
"depid": "",
"widget": "checkbox",
"input": "radio",
"validation": {"isRequired": true},
"inputList": [
{"id": "1", "name": "Option 1"},
{"id": "2", "name": "Option 2"},
{"id": "3", "name": "Option 3"},
{"id": "4", "name": "Option 4"},
{"id": "5", "name": "Option 5"},
{"id": "6", "name": "Option 6"},
{"id": "7", "name": "Option 7"}
]
},
{
"name": "field_0_1",
"id": "field_0_1",
"depid": "",
"widget": "dropdown",
"input": "checkbox",
"validation": {"isRequired": true},
"inputList": [
{"id": "1", "name": "Option 1"},
{"id": "2", "name": "Option 2"},
{"id": "3", "name": "Option 3"},
{"id": "4", "name": "Option 4"},
{"id": "5", "name": "Option 5"},
{"id": "6", "name": "Option 6"},
{"id": "7", "name": "Option 7"}
]
},
{
"name": "field_0_2",
"id": "field_0_2",
"depid": "",
"widget": "text",
"input": "date",
"validation": {"isRequired": true}
}
],
},
// {
// "sectionName": "HCP",
// "multiple": true,
// "sectionList": [
// {
// "name": "name",
// "id": "field_0_2",
// "depid": "pooja",
// "widget": "text",
// "input": "text1",
// "validation": {"isRequired": true}
// },
// {
// "name": "Role",
// "id": "field_0_1",
// "depid": "",
// "widget": "dropdown",
// "input": "checkbox",
// "validation": {"isRequired": true},
// "inputList": [
// {"id": "1", "name": "Option 1"},
// {"id": "2", "name": "Option 2"},
// {"id": "3", "name": "Option 3"},
// {"id": "4", "name": "Option 4"},
// {"id": "5", "name": "Option 5"},
// {"id": "6", "name": "Option 6"},
// {"id": "7", "name": "Option 7"}
// ]
// },
// {
// "name": "Attended",
// "id": "field_0_1",
// "depid": "",
// "widget": "dropdown",
// "input": "checkbox",
// "validation": {"isRequired": true},
// "inputList": [
// {"id": "1", "name": "Option 1"},
// {"id": "2", "name": "Option 2"},
// {"id": "3", "name": "Option 3"},
// {"id": "4", "name": "Option 4"},
// {"id": "5", "name": "Option 5"},
// {"id": "6", "name": "Option 6"},
// {"id": "7", "name": "Option 7"}
// ]
// },
// {
// "name": "Honorarium",
// "id": "field_0_2",
// "depid": "",
// "widget": "text",
// "input": "date",
// "validation": {"isRequired": true}
// },
// {
// "name": "created by",
// "id": "field_0_2",
// "depid": "poojatk",
// "widget": "text",
// "input": "text1",
// "validation": {"isRequired": true}
// },
// {
// "name": "created on",
// "id": "field_0_2",
// "depid": "13/05/2024",
// "widget": "text",
// "input": "text1",
// "validation": {"isRequired": true}
// },
// // {
// // "name": "field_0_0",
// // "id": "field_0_0",
// // "depid": "",
// // "widget": "checkbox",
// // "input": "radio",
// // "validation": {"isRequired": true},
// // "inputList": [
// // {"id": "1", "name": "Option 1"},
// // {"id": "2", "name": "Option 2"},
// // {"id": "3", "name": "Option 3"},
// // {"id": "4", "name": "Option 4"},
// // {"id": "5", "name": "Option 5"},
// // {"id": "6", "name": "Option 6"},
// // {"id": "7", "name": "Option 7"}
// // ]
// // },
// // {
// // "name": "field_0_2",
// // "id": "field_0_2",
// // "depid": "",
// // "widget": "text",
// // "input": "date",
// // "validation": {"isRequired": true}
// // }
// ],
// },
]
}
]
};
}
}