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:flutter/services.dart'; import 'package:http_mock_adapter/http_mock_adapter.dart'; // import 'package:pwa_ios/model/interaction_config_data.dart'; class MockApiCall { Future getConfigData() async { print("Iam_getConfig"); // 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; // }; //final response = await dio.get('https://passvault.konectar.io/forms'); // dynamic response = // jsonDecode(await rootBundle.loadString("assets/interaction.json")); // print("response1_isssss"); // // print(response.data.toString()); // // log(jsonEncode(response.data)); // final parsedJson = json.encode(response.data); // print(parsedJson); //return response.data; return { "success": true, "message": "New form generated", "data": [ { "id": "Form1", "name": "Interaction Form", "form-fields": [ { "sectionName": "Discussion Topic", "multiple": true, "sectionList": [ { "name": "Product", "id": "discproduct_41", "depid": "", "param": "product", "widget": "dropdown", "input": "dropdown", "inputList": [ {"id": "41", "name": "Product1"}, {"id": "42", "name": "Product2"} ], "validation": {"isRequired": true} }, { "name": "Discussion Type", "id": "disctype_51", "depid": "", "widget": "autocomplete", "input": "autocomplete", "inputList": [ {"id": "51", "name": "Face to Face"}, {"id": "52", "name": "Lecture"}, {"id": "53", "name": "Mailing"}, {"id": "54", "name": "Other"}, {"id": "55", "name": "Phone"} ], "validation": {"isRequired": true} }, { "name": "Discussion Topic", "id": "disctopic_61", "depid": "", "widget": "multiselect", "input": "multiselect", "inputList": [ {"id": "61", "name": "Face to Face"}, {"id": "62", "name": "Lecture"}, {"id": "63", "name": "Mailing"}, {"id": "64", "name": "Other"}, {"id": "65", "name": "Phone"} ], "validation": {"isRequired": true} } ] }, { "sectionName": "Attendees", "multiple": true, "sectionList": [ { "name": "HCP Name", "id": "attendeeshcpname_3", "depid": "", "widget": "text", "input": "text", "validation": {"isRequired": true} }, { "name": "Speciality", "id": "attendeeshcpspeciality_4", "depid": "", "widget": "text", "input": "text", "validation": {"isRequired": true} }, { "name": "Title", "id": "attendeestitle_5", "depid": "", "widget": "text", "input": "text", "validation": {"isRequired": true} } ] }, { "sectionName": "Other", "multiple": false, "sectionList": [ { "name": "Address1", "id": "otheraddress1_12", "depid": "", "widget": "text", "input": "primary", "validation": {"isRequired": true} }, { "name": "Address2", "id": "otheraddress2_13", "depid": "", "widget": "text", "input": "Hubli", "validation": {"isRequired": true} }, { "name": "Postal code", "id": "otherpostal_14", "depid": "", "widget": "text", "input": "number", "validation": {"isRequired": true} }, { "name": "Country", "id": "othercountry_15", "depid": "", "widget": "dropdown", "inputList": [ {"name": "India", "id": "1"}, {"name": "USA", "id": "2"}, {"name": "Nepal", "id": "3"} ], "validation": {"isRequired": true} }, { "name": "State", "id": "otherstate_16", "depid": "othercountry_15", "widget": "dropdown", "inputList": [ {"name": "Karnataka", "id": "1", "pid": "1"}, {"name": "Maharashtra", "id": "2", "pid": "1"}, {"name": "Andhra Pradesh", "id": "3", "pid": "1"}, {"name": "Karnataka", "id": "4", "pid": "1"} ], "validation": {"isRequired": true} }, { "name": "City", "widget": "dropdown", "id": "othercity_17", "depid": "otherstate_16", "inputList": [ {"name": "Hubli", "id": "1", "pid": "1"}, {"name": "Bangalore", "id": "2", "pid": "1"}, {"name": "Belgavi", "id": "3", "pid": "1"} ], "validation": {"isRequired": true} } ] }, { "sectionName": "Other Attendees", "multiple": false, "sectionList": [ { "name": "Attendee Name", "id": "otherattendeename_18", "depid": "", "widget": "text", "input": "text", "validation": {"isRequired": true} }, { "name": "Speciality", "id": "otherattendeespeciality_19", "depid": "", "widget": "text", "input": "text", "validation": {"isRequired": true} }, { "name": "Comments", "id": "otherattendeecom_20", "depid": "", "widget": "text", "input": "text", "validation": {"isRequired": true} } ] }, ] } ] }; } Future 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 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 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 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 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 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 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 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} // // } // ], // }, ] } ] }; } }