import 'package:flutter/foundation.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:pwa_ios/model/interaction_config_data.dart'; import 'package:pwa_ios/model/interaction_data.dart'; import 'package:pwa_ios/utils/mockapi.dart'; import 'package:pwa_ios/utils/util.dart'; import 'package:internet_connection_checker/internet_connection_checker.dart'; class ConfigDataProvider extends ChangeNotifier { Future initConfigUIData() async { List interactionConfigData = []; // interactionConfigData = await fetchInteactionConfigData(); //interactionConfigData = fetchInteactionUIConfigData(jsonResult); if (await InternetConnectionChecker().hasConnection) { interactionConfigData = await fetchLocalInteactionConfigData(); 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(); 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(); // dynamic jsonResultc2 = jsonDecode( // await rootBundle.loadString("assets/images/interactiondatac2.json")); // // for (var value in jsonResult) { // InteractionDataSet interactionDataSet2 = // InteractionDataSet.fromJson(jsonResultc2); // dynamic jsonResult2 = jsonDecode( // await rootBundle.loadString("assets/images/interactionform.json")); // dynamic jsonResult2c2 = jsonDecode( // await rootBundle.loadString("assets/images/newconfigdata.json")); List interactionConfigData = []; // for (var value in jsonResult) { // InteractionResultData interactionConfig = // InteractionResultData.fromJson(jsonResult2); ResponseData responseData = ResponseDataFromJson(jsonResult); for (InteractionResultData obj in responseData.data) { // InteractionResultData interactionConfigc2 = // InteractionResultData.fromJson(obj); interactionConfigData.add( // InteractionConfigData( // dataSet: interactionDataSet, // widgets: interactionConfig, // id: "IN01", // name: "InteractionForm1")); // inte ractionConfigData.add( InteractionConfigData(widgets: obj, id: obj.id, name: obj.name)); } return interactionConfigData; } // List fetchInteactionUIConfigData(UIDataResponse data) { // //final data = json.decode(jsonResult); // InteractionDataSet interactionDataSet = // InteractionDataSet(data: data.formAttr); // InteractionResultData interactionConfig = // InteractionResultData(result: data.formFields, id: data.id , name: ''); // List interactionConfigData = []; // interactionConfigData.add(InteractionConfigData( // dataSet: interactionDataSet, // widgets: interactionConfig, // id: "IN01", // name: "InteractionForm1")); // return interactionConfigData; // } }