// import 'package:konectar_events/ui_screen/interactionform/NewtworkConnectivity.dart'; // import 'package:konectar_events/ui_screen/interactionform/mockapi.dart'; // import 'package:konectar_events/ui_screen/interactionform/model/interaction_config_data.dart'; // import 'package:konectar_events/ui_screen/interactionform/model/interaction_data.dart'; // import 'package:konectar_events/ui_screen/interactionform/util.dart'; import 'package:konectar_events/contacts_module/ui_screen/interactionform/NewtworkConnectivity.dart'; import 'package:konectar_events/contacts_module/ui_screen/interactionform/mockapi.dart'; import 'package:konectar_events/contacts_module/ui_screen/interactionform/model/interaction_config_data.dart'; import 'package:konectar_events/contacts_module/ui_screen/interactionform/model/interaction_data.dart'; import 'package:konectar_events/contacts_module/ui_screen/interactionform/util.dart'; import 'package:flutter/foundation.dart'; import 'package:hive_flutter/hive_flutter.dart'; class ConfigDataProvider extends ChangeNotifier { Future initConfigUIData() async { List interactionConfigData = []; // interactionConfigData = await fetchInteactionConfigData(); //interactionConfigData = fetchInteactionUIConfigData(jsonResult); NetworkConnectivity networkConnectivity = NetworkConnectivity(); bool isOnline = await networkConnectivity.isInternetAvailable(); print("Checkonline: $isOnline"); if (isOnline) { interactionConfigData = await fetchLocalInteactionConfigData(); print("interactionConfigData_is $interactionConfigData"); var box = Hive.box('InteractionConfigDataBox'); if (!box.isOpen) { box = await Hive.openBox( 'InteractionConfigDataBox'); } if (box.isEmpty) { for (InteractionConfigData data in interactionConfigData) { box.put(await getNextAutoIncrementValue(), data); } } else { box.clear(); print("IamELse"); for (InteractionConfigData data in interactionConfigData) { box.put(await getNextAutoIncrementValue(), data); } } } notifyListeners(); } Future> fetchLocalInteactionConfigData() async { // dynamic jsonResult = jsonDecode( // await rootBundle.loadString("assets/images/interactiondata.json")); dynamic jsonResult = await MockApiCall().getConfigData(); List interactionConfigData = []; ResponseData responseData = ResponseDataFromJson(jsonResult); print('Response_data_is: $responseData'); print('Response_data_dta_is: ${responseData.data}'); for (InteractionResultData obj in responseData.data) { interactionConfigData .add(InteractionConfigData(widgets: obj, id: obj.id, name: obj.name)); } print("interactionConfigData_issss: ${interactionConfigData.length}"); return interactionConfigData; } //pooja Future initConfigUIData123() async { List interactionConfigData = []; // interactionConfigData = await fetchInteactionConfigData(); //interactionConfigData = fetchInteactionUIConfigData(jsonResult); NetworkConnectivity networkConnectivity = NetworkConnectivity(); bool isOnline = await networkConnectivity.isInternetAvailable(); if (isOnline) { interactionConfigData = await fetchLocalInteactionConfigData123(); var box = Hive.box('InteractionConfigDataBox'); if (!box.isOpen) { box = await Hive.openBox( 'InteractionConfigDataBox'); } if (box.isEmpty) { for (InteractionConfigData data in interactionConfigData) { box.put(await getNextAutoIncrementValue(), data); } } else { box.clear(); print("IamELse"); for (InteractionConfigData data in interactionConfigData) { box.put(await getNextAutoIncrementValue(), data); } } } notifyListeners(); } Future> fetchLocalInteactionConfigData123() async { // dynamic jsonResult = jsonDecode( // await rootBundle.loadString("assets/images/interactiondata.json")); dynamic jsonResult = await MockApiCall().getConfigData123(); List interactionConfigData = []; ResponseData responseData = ResponseDataFromJson(jsonResult); print('Response_data_is: $responseData'); print('Response_data_dta_is: ${responseData.data}'); for (InteractionResultData obj in responseData.data) { interactionConfigData .add(InteractionConfigData(widgets: obj, id: obj.id, name: obj.name)); } print("interactionConfigData_issss: ${interactionConfigData.length}"); return interactionConfigData; } Future initConfigUIDataMedical() async { List interactionConfigData = []; // interactionConfigData = await fetchInteactionConfigData(); //interactionConfigData = fetchInteactionUIConfigData(jsonResult); NetworkConnectivity networkConnectivity = NetworkConnectivity(); bool isOnline = await networkConnectivity.isInternetAvailable(); if (isOnline) { // if (await InternetConnectionChecker().hasConnection) { interactionConfigData = await fetchLocalInteactionConfigDataMedical(); var box = Hive.box('InteractionConfigDataBox'); if (!box.isOpen) { box = await Hive.openBox( 'InteractionConfigDataBox'); } if (box.isEmpty) { for (InteractionConfigData data in interactionConfigData) { box.put(await getNextAutoIncrementValue(), data); } } else { box.clear(); print("IamELse"); for (InteractionConfigData data in interactionConfigData) { box.put(await getNextAutoIncrementValue(), data); } } } notifyListeners(); } Future> fetchLocalInteactionConfigDataMedical() async { // dynamic jsonResult = jsonDecode( // await rootBundle.loadString("assets/images/interactiondata.json")); dynamic jsonResult = await MockApiCall().getConfigDataMedical(); List interactionConfigData = []; ResponseData responseData = ResponseDataFromJson(jsonResult); print('Response_data_is: $responseData'); print('Response_data_dta_is: ${responseData.data}'); for (InteractionResultData obj in responseData.data) { interactionConfigData .add(InteractionConfigData(widgets: obj, id: obj.id, name: obj.name)); } print("interactionConfigData_issss: ${interactionConfigData.length}"); return interactionConfigData; } Future initConfigUIDataEng() async { List interactionConfigData = []; // interactionConfigData = await fetchInteactionConfigData(); //interactionConfigData = fetchInteactionUIConfigData(jsonResult); // if (await InternetConnectionChecker().hasConnection) { NetworkConnectivity networkConnectivity = NetworkConnectivity(); bool isOnline = await networkConnectivity.isInternetAvailable(); if (isOnline) { interactionConfigData = await fetchLocalInteactionConfigDataEng(); var box = Hive.box('InteractionConfigDataBox'); if (!box.isOpen) { box = await Hive.openBox( 'InteractionConfigDataBox'); } if (box.isEmpty) { for (InteractionConfigData data in interactionConfigData) { box.put(await getNextAutoIncrementValue(), data); } } else { box.clear(); print("IamELse"); for (InteractionConfigData data in interactionConfigData) { box.put(await getNextAutoIncrementValue(), data); } } } notifyListeners(); } Future> fetchLocalInteactionConfigDataEng() async { // dynamic jsonResult = jsonDecode( // await rootBundle.loadString("assets/images/interactiondata.json")); dynamic jsonResult = await MockApiCall().getConfigDataEng(); List interactionConfigData = []; ResponseData responseData = ResponseDataFromJson(jsonResult); print('Response_data_is: $responseData'); print('Response_data_dta_is: ${responseData.data}'); for (InteractionResultData obj in responseData.data) { interactionConfigData .add(InteractionConfigData(widgets: obj, id: obj.id, name: obj.name)); } print("interactionConfigData_issss: ${interactionConfigData.length}"); return interactionConfigData; } }